Skip to content

Commit c4c34f6

Browse files
committedMay 10, 2024
Native-staking* and vault tests pass
1 parent 19b17c2 commit c4c34f6

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed
 

‎contracts/provider/native-staking-proxy/src/multitest.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ fn unstaking() {
281281
);
282282

283283
// Advance time until the unbonding period is over
284-
app.update_block(|block| {
285-
block.height += 1234;
286-
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
287-
});
284+
process_staking_unbondings(&app);
288285

289286
// Check that the contract now has the funds
290287
assert_eq!(
@@ -296,6 +293,7 @@ fn unstaking() {
296293
);
297294
}
298295

296+
299297
#[test]
300298
fn burning() {
301299
let owner = "vault_admin";
@@ -338,11 +336,9 @@ fn burning() {
338336
coin(0, OSMO)
339337
);
340338

339+
341340
// Advance time until the unbonding period is over
342-
app.update_block(|block| {
343-
block.height += 1234;
344-
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
345-
});
341+
process_staking_unbondings(&app);
346342

347343
// Check that the contract now has the funds
348344
assert_eq!(
@@ -424,10 +420,7 @@ fn burning_multiple_delegations() {
424420
);
425421

426422
// Advance time until the unbonding period is over
427-
app.update_block(|block| {
428-
block.height += 1234;
429-
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
430-
});
423+
process_staking_unbondings(&app);
431424

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

484477
// Advance time until the unbonding period is over
485-
app.update_block(|block| {
486-
block.height += 12345;
487-
block.time = block.time.plus_seconds(UNBONDING_PERIOD + 1);
488-
});
478+
process_staking_unbondings(&app);
489479

490480
// Release the unbonded funds
491481
staking_proxy.release_unbonded().call(user).unwrap();
@@ -551,3 +541,18 @@ fn withdrawing_rewards() {
551541
.unwrap();
552542
assert_eq!(original_vault_funds, vault_funds);
553543
}
544+
545+
fn process_staking_unbondings(app: &App<MtApp>) {
546+
// Advance unbonding period
547+
app.app_mut().update_block(|block| {
548+
block.time = block.time.plus_seconds(UNBONDING_PERIOD);
549+
block.height += UNBONDING_PERIOD / 5;
550+
});
551+
// This is deprecated as unneeded, but tests fail if it isn't here. What's up???
552+
app.app_mut()
553+
.sudo(cw_multi_test::SudoMsg::Staking(
554+
cw_multi_test::StakingSudo::ProcessQueue {},
555+
))
556+
.unwrap();
557+
}
558+

‎contracts/provider/native-staking/src/multitest.rs

+10
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ fn releasing_proxy_stake() {
340340
.unstake(validator.to_string(), coin(100, OSMO))
341341
.call(user)
342342
.unwrap();
343+
// Important: we need to wait the unbonding period until this is released
344+
app.update_block(advance_unbonding_period);
343345
staking_proxy.release_unbonded().call(user).unwrap();
344346

345347
// Check that the vault has the funds again
@@ -351,3 +353,11 @@ fn releasing_proxy_stake() {
351353
let claims = vault.account_claims(user.to_owned(), None, None).unwrap();
352354
assert_eq!(claims.claims, []);
353355
}
356+
357+
pub fn advance_unbonding_period(block: &mut cosmwasm_std::BlockInfo) {
358+
// Default unbonding time in cw_multi_test is 60, from looking at the code...
359+
// Wish I could find this somewhere in this setup somewhere.
360+
const UNBONDING_TIME: u64 = 60;
361+
block.time = block.time.plus_seconds(5 * UNBONDING_TIME);
362+
block.height += UNBONDING_TIME;
363+
}

‎contracts/provider/vault/src/multitest.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,16 @@ fn proxy_for_user<'a>(
273273
}
274274

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

281288
#[track_caller]

0 commit comments

Comments
 (0)