Newer
Older
with_externalities(&mut ExtBuilder::default()
.nominate(false)
.minimum_validator_count(1)
.validator_count(20)
.build(),
|| {
let _ = Staking::chill(Origin::signed(10));
let _ = Staking::chill(Origin::signed(20));
let _ = Staking::chill(Origin::signed(30));
let prefix = 200;
bond_validator(prefix + 2, 1);
bond_validator(prefix + 4, 100);
bond_validator(prefix + 6, 1000000);
bond_validator(prefix + 8, 100000000001000);
bond_validator(prefix + 10, 100000000002000);
bond_validator(prefix + 12, 100000000003000);
bond_validator(prefix + 14, 400000000000000);
bond_validator(prefix + 16, 400000000001000);
bond_validator(prefix + 18, 18000000000000000);
bond_validator(prefix + 20, 20000000000000000);
bond_validator(prefix + 22, 500000000000100000);
bond_validator(prefix + 24, 500000000000200000);
bond_nominator(50, 990000000000000000, vec![
prefix + 3,
prefix + 5,
prefix + 7,
prefix + 9,
prefix + 11,
prefix + 13,
prefix + 15,
prefix + 17,
prefix + 19,
prefix + 21,
prefix + 23,
#[test]
fn phragmen_large_scale_test_2() {
with_externalities(&mut ExtBuilder::default()
.nominate(false)
.minimum_validator_count(1)
.validator_count(2)
.build(),
|| {
let _ = Staking::chill(Origin::signed(10));
let _ = Staking::chill(Origin::signed(20));
let nom_budget: u64 = 1_000_000_000_000_000_000;
let c_budget: u64 = 4_000_000;
bond_validator(2, c_budget as u64);
bond_validator(4, c_budget as u64);
bond_nominator(50, nom_budget, vec![3, 5]);
// Each exposure => total == own + sum(others)
check_exposure_all();
assert_total_expo(3, nom_budget / 2 + c_budget);
assert_total_expo(5, nom_budget / 2 + c_budget);
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
#[test]
fn reward_validator_slashing_validator_doesnt_overflow() {
with_externalities(&mut ExtBuilder::default()
.build(),
|| {
let stake = u32::max_value() as u64 * 2;
let reward_slash = u32::max_value() as u64 * 2;
// Assert multiplication overflows in balance arithmetic.
assert!(stake.checked_mul(reward_slash).is_none());
// Set staker
let _ = Balances::make_free_balance_be(&11, stake);
<Stakers<Test>>::insert(&11, Exposure { total: stake, own: stake, others: vec![] });
// Check reward
Staking::reward_validator(&11, reward_slash);
assert_eq!(Balances::total_balance(&11), stake * 2);
// Set staker
let _ = Balances::make_free_balance_be(&11, stake);
let _ = Balances::make_free_balance_be(&2, stake);
<Stakers<Test>>::insert(&11, Exposure { total: stake, own: 1, others: vec![
IndividualExposure { who: 2, value: stake - 1 }
]});
// Check slashing
Staking::slash_validator(&11, reward_slash);
assert_eq!(Balances::total_balance(&11), stake - 1);
assert_eq!(Balances::total_balance(&2), 1);
})
}