Skip to content

Commit

Permalink
Enable and extend jail / unjail test
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Oct 11, 2023
1 parent 5ccc519 commit 017c227
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,27 +652,52 @@ mod tests {
}

#[test]
#[ignore]
fn validator_jail_unjail() {
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(10u128);
contract.quick_bond(deps.as_mut(), "val1", 5);
knobs.bond_status.update_cap(100u128);
contract.quick_bond(deps.as_mut(), "val1", 10);
contract.quick_bond(deps.as_mut(), "val2", 20);
contract
.hit_epoch(deps.as_mut())
.assert_bond(&[("val1", (5u128, &denom))])
.assert_bond(&[("val1", (10u128, &denom)), ("val2", (20u128, &denom))])
.assert_rewards(&[]);

// val1 is being jailed
contract.jail(deps.as_mut(), "val1");
contract.hit_epoch(deps.as_mut()).assert_rewards(&[]);

contract
.hit_epoch(deps.as_mut())
.assert_bond(&[]) // No bond msgs after jailing
.assert_unbond(&[]) // No unbond msgs after jailing
.assert_rewards(&["val1", "val2"]); // But rewards can still be gathered

// Check that the bonded amounts of val1 have been slashed for being offline (10%)
// Val2 is unaffected.
let bonded = contract.bonded.load(deps.as_ref().storage).unwrap();
assert_eq!(
bonded,
[
("val1".to_string(), Uint128::new(9)),
("val2".to_string(), Uint128::new(20))
]
);

// FIXME: Subsequent rewards msgs could be removed while validator is jailed / inactive
contract
.hit_epoch(deps.as_mut())
.assert_rewards(&["val1", "val2"]); // But rewards can still be gathered

contract.unjail(deps.as_mut(), "val1");
contract.hit_epoch(deps.as_mut());
contract.hit_epoch(deps.as_mut()).assert_rewards(&["val1"]);
contract
.hit_epoch(deps.as_mut())
.assert_bond(&[]) // No bond msgs after unjailing
.assert_unbond(&[]) // No unbond msgs after unjailing
.assert_rewards(&["val1", "val2"]);
}

#[test]
Expand Down Expand Up @@ -799,8 +824,8 @@ mod tests {
delegated: coin(0, "DOES NOT MATTER"),
});
let slash_ratio = MockSlashRatio::new(SlashRatioResponse {
slash_fraction_downtime: "0".to_string(),
slash_fraction_double_sign: "0".to_string(),
slash_fraction_downtime: "0.1".to_string(),
slash_fraction_double_sign: "0.2".to_string(),
});

let handler = {
Expand Down

0 comments on commit 017c227

Please sign in to comment.