Skip to content

Commit

Permalink
Native-staking* and vault tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed May 10, 2024
1 parent 19b17c2 commit c4c34f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 19 deletions.
37 changes: 21 additions & 16 deletions contracts/provider/native-staking-proxy/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,7 @@ fn unstaking() {
);

// Advance time until the unbonding period is over
app.update_block(|block| {
block.height += 1234;
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
});
process_staking_unbondings(&app);

// Check that the contract now has the funds
assert_eq!(
Expand All @@ -296,6 +293,7 @@ fn unstaking() {
);
}


#[test]
fn burning() {
let owner = "vault_admin";
Expand Down Expand Up @@ -338,11 +336,9 @@ fn burning() {
coin(0, OSMO)
);


// Advance time until the unbonding period is over
app.update_block(|block| {
block.height += 1234;
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
});
process_staking_unbondings(&app);

// Check that the contract now has the funds
assert_eq!(
Expand Down Expand Up @@ -424,10 +420,7 @@ fn burning_multiple_delegations() {
);

// Advance time until the unbonding period is over
app.update_block(|block| {
block.height += 1234;
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
});
process_staking_unbondings(&app);

// Check that the contract now has the funds
assert_eq!(
Expand Down Expand Up @@ -482,10 +475,7 @@ fn releasing_unbonded() {
assert!(delegation.is_none());

// Advance time until the unbonding period is over
app.update_block(|block| {
block.height += 12345;
block.time = block.time.plus_seconds(UNBONDING_PERIOD + 1);
});
process_staking_unbondings(&app);

// Release the unbonded funds
staking_proxy.release_unbonded().call(user).unwrap();
Expand Down Expand Up @@ -551,3 +541,18 @@ fn withdrawing_rewards() {
.unwrap();
assert_eq!(original_vault_funds, vault_funds);
}

fn process_staking_unbondings(app: &App<MtApp>) {
// Advance unbonding period
app.app_mut().update_block(|block| {
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
block.height += UNBONDING_PERIOD / 5;
});
// This is deprecated as unneeded, but tests fail if it isn't here. What's up???
app.app_mut()
.sudo(cw_multi_test::SudoMsg::Staking(
cw_multi_test::StakingSudo::ProcessQueue {},
))
.unwrap();
}

10 changes: 10 additions & 0 deletions contracts/provider/native-staking/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ fn releasing_proxy_stake() {
.unstake(validator.to_string(), coin(100, OSMO))
.call(user)
.unwrap();
// Important: we need to wait the unbonding period until this is released
app.update_block(advance_unbonding_period);
staking_proxy.release_unbonded().call(user).unwrap();

// Check that the vault has the funds again
Expand All @@ -351,3 +353,11 @@ fn releasing_proxy_stake() {
let claims = vault.account_claims(user.to_owned(), None, None).unwrap();
assert_eq!(claims.claims, []);
}

pub fn advance_unbonding_period(block: &mut cosmwasm_std::BlockInfo) {
// Default unbonding time in cw_multi_test is 60, from looking at the code...
// Wish I could find this somewhere in this setup somewhere.
const UNBONDING_TIME: u64 = 60;
block.time = block.time.plus_seconds(5 * UNBONDING_TIME);
block.height += UNBONDING_TIME;
}
13 changes: 10 additions & 3 deletions contracts/provider/vault/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,16 @@ fn proxy_for_user<'a>(
}

fn process_staking_unbondings(app: &App<MtApp>) {
let mut block_info = app.block_info();
block_info.time = block_info.time.plus_seconds(61);
app.set_block(block_info);
app.app_mut().update_block(|block| {
block.time = block.time.plus_seconds(61);
block.height += 13;
});
// This is deprecated as unneeded, but tests fail if it isn't here. What's up???
app.app_mut()
.sudo(cw_multi_test::SudoMsg::Staking(
cw_multi_test::StakingSudo::ProcessQueue {},
))
.unwrap();
}

#[track_caller]
Expand Down

0 comments on commit c4c34f6

Please sign in to comment.