Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow all states to be override in instantiation #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ pub fn instantiate(
percentage: Decimal::percent(msg.admin_voting_threshold_percentage as u64),
},
)?;
WITHDRAWN_STAKING_REWARDS.save(deps.storage, &0)?;
WITHDRAWN_UNLOCKED.save(deps.storage, &0)?;
WITHDRAWN_LOCKED.save(deps.storage, &0)?;
let withdrawn_rewards = msg.withdrawn_staking_rewards.unwrap_or(0);
WITHDRAWN_STAKING_REWARDS.save(deps.storage, &withdrawn_rewards)?;
let withdrawn_unlocked = msg.withdrawn_unlocked.unwrap_or(0);
WITHDRAWN_UNLOCKED.save(deps.storage, &withdrawn_unlocked)?;
let withdrawn_locked = msg.withdrawn_locked.unwrap_or(0);
WITHDRAWN_LOCKED.save(deps.storage, &withdrawn_locked)?;
Ok(Response::default())
}

Expand Down Expand Up @@ -850,6 +853,9 @@ mod tests {
},
max_voting_period: Duration::Time(3600),
admin_voting_threshold_percentage: 75,
withdrawn_staking_rewards: None,
withdrawn_locked: None,
withdrawn_unlocked: None,
};
instantiate(deps, mock_env(), info, instantiate_msg)
}
Expand All @@ -874,6 +880,9 @@ mod tests {
},
max_voting_period: Duration::Time(3600),
admin_voting_threshold_percentage: 75,
withdrawn_staking_rewards: None,
withdrawn_locked: None,
withdrawn_unlocked: None,
};
let err =
instantiate(deps.as_mut(), mock_env(), info.clone(), instantiate_msg).unwrap_err();
Expand All @@ -892,6 +901,9 @@ mod tests {
},
max_voting_period: Duration::Time(3600),
admin_voting_threshold_percentage: 75,
withdrawn_staking_rewards: None,
withdrawn_locked: None,
withdrawn_unlocked: None,
};
let err =
instantiate(deps.as_mut(), mock_env(), info.clone(), instantiate_msg).unwrap_err();
Expand All @@ -910,6 +922,9 @@ mod tests {
},
max_voting_period: Duration::Time(3600),
admin_voting_threshold_percentage: 75,
withdrawn_staking_rewards: None,
withdrawn_locked: None,
withdrawn_unlocked: None,
};
let err =
instantiate(deps.as_mut(), mock_env(), info.clone(), instantiate_msg).unwrap_err();
Expand Down
5 changes: 5 additions & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ pub struct InstantiateMsg {
pub tranche: Tranche,
pub max_voting_period: Duration,
pub admin_voting_threshold_percentage: u8,

// override cumulative state (for inheriting a contract or testing)
pub withdrawn_staking_rewards: Option<u128>,
pub withdrawn_unlocked: Option<u128>,
pub withdrawn_locked: Option<u128>,
}

#[cw_serde]
Expand Down