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

virtual-staking: jailing / tombstoning tests #142

Merged
merged 15 commits into from
Oct 12, 2023
Prev Previous commit
Next Next commit
Add jailed while bonding test
  • Loading branch information
maurolacy committed Oct 11, 2023
commit e74bff9b09b02d6e9f103f19ff653aa81c27dfc6
46 changes: 46 additions & 0 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,52 @@ mod tests {
.assert_rewards(&["val1", "val2"]);
}

#[test]
fn validator_jail_pending_bond() {
let (mut deps, knobs) = mock_dependencies();

let contract = VirtualStakingContract::new();
contract.quick_inst(deps.as_mut());
let denom = contract.config.load(&deps.storage).unwrap().denom;

knobs.bond_status.update_cap(100u128);
contract.quick_bond(deps.as_mut(), "val1", 10);
contract
.hit_epoch(deps.as_mut())
.assert_bond(&[("val1", (10u128, &denom))])
.assert_rewards(&[]);

// Val1 is bonding some more
contract.quick_bond(deps.as_mut(), "val1", 20);

// And it's is being jailed at the same time
contract.jail(deps.as_mut(), "val1");

contract
.hit_epoch(deps.as_mut())
.assert_bond(&[("val1", (20u128, &denom))]) // Slashing is not affecting pending bonds
.assert_unbond(&[]) // No unbond msgs after jailing
.assert_rewards(&["val1"]); // Rewards are still being gathered

// Check that the non-slashed amounts of val1 have been bonded
// FIXME: Remove / filter zero amounts
let bonded = contract.bonded.load(deps.as_ref().storage).unwrap();
assert_eq!(bonded, [("val1".to_string(), Uint128::new(29)),]);

contract.hit_epoch(deps.as_mut()).assert_rewards(&["val1"]);

// Unjail over bonded has no effect
contract.unjail(deps.as_mut(), "val1");
contract
.hit_epoch(deps.as_mut())
.assert_bond(&[]) // No bond msgs after unjailing
.assert_unbond(&[]) // No unbond msgs after unjailing
.assert_rewards(&["val1"]);

let bonded = contract.bonded.load(deps.as_ref().storage).unwrap();
assert_eq!(bonded, [("val1".to_string(), Uint128::new(29)),]);
}

#[test]
fn validator_jail_pending_unbond() {
let (mut deps, knobs) = mock_dependencies();
Expand Down
Loading