Skip to content

Commit

Permalink
increase time before querying total staked, and fixed height in execu…
Browse files Browse the repository at this point in the history
…te fn
  • Loading branch information
NoahSaso committed Jun 24, 2024
1 parent cf8e5dc commit 88e2965
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions contracts/voting/dao-voting-cosmos-staked/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,13 @@ pub fn execute_update_total_staked(
amount: Uint128,
height: Option<u64>,
) -> Result<Response, ContractError> {
STAKED_TOTAL.save(deps.storage, &amount, env.block.height)?;
let height = height.unwrap_or(env.block.height);
STAKED_TOTAL.save(deps.storage, &amount, height)?;

Ok(Response::new()
.add_attribute("action", "update_total_staked")
.add_attribute("amount", amount)
.add_attribute("height", height.unwrap_or(env.block.height).to_string()))
.add_attribute("height", height.to_string()))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ fn test_staked_voting_power_and_update() {
msgs: vec![CosmosMsg::Stargate {
type_url: "/cosmos.authz.v1beta1.MsgGrant".to_string(),
value: MsgGrant {
granter: dao.contract_addr.to_string(),
grantee: bot.address().to_string(),
granter: dao.contract_addr.clone(),
grantee: bot.address(),
grant: Some(Grant {
authorization: Some(
ContractExecutionAuthorization {
Expand Down Expand Up @@ -119,9 +119,6 @@ fn test_staked_voting_power_and_update() {
staker,
)
.unwrap();

app.increase_time(10);

proposal_single
.execute(
&dao_proposal_single::msg::ExecuteMsg::Execute { proposal_id: 1 },
Expand Down Expand Up @@ -152,6 +149,9 @@ fn test_staked_voting_power_and_update() {
)
.unwrap();

// Move chain forward so we can update total staked on a new block
app.increase_time(100);

// Query total power
let total_power = vp_contract.query_tp(None).unwrap();
assert_eq!(total_power.power, Uint128::new(100));
Expand Down

0 comments on commit 88e2965

Please sign in to comment.