mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 03:41:02 +00:00
Self-Vote for Staking (among others.) (#2078)
* initial doc for the staking module * Remove md style links. * Remove todos. * Add rust code types * Rename and fix review notes. * Add new md file * Final touches. * Migrate compleatly to rustdoc * Update link * Fix heading * Final touches wrt the new template. * Remove empty prereq. * Fix more reviews * Some final nits. * Fix some side issues. * Fix another set of reviews * Fix + stabilize leftover reivews. * Remove unused test parameters * Fix typo. * Merge redundant loops * Adds phantom self-vote * Fix broken tests. * Refactor some names to match the reference. * Remove redundant inner loops from election round. * Introduce phragmen post-processing. * Some fixes and todos. * Fix some tests with new phragmen params * Fix test * Bump spec * Fix wasm build * Fix tests and phragmen fallback. Avoid double-controlling * Fix and rebuild wasm * Whitespaces, whitespaces everywhere. * Rebuild * Disable post-processing. * Identify by stash, not controller account. * Couple of fixes * Fix first test * Fix invulnerability_should_work * Fix a couple more tests * Fix more tests * Fix more tests * Fix more tests * Fix some tests * Fix update-ledger. * Fix update-ledger. * Fix another test * Fix another test * Fix rest of staking tests * Remove printlns * Rebuild wasm * Fix & tests for auth/val syncing * Fix up threading for tests * Remove superfluous asserts
This commit is contained in:
@@ -84,12 +84,12 @@ pub struct ExtBuilder {
|
||||
session_length: u64,
|
||||
sessions_per_era: u64,
|
||||
current_era: u64,
|
||||
monied: bool,
|
||||
reward: u64,
|
||||
validator_pool: bool,
|
||||
nominate: bool,
|
||||
validator_count: u32,
|
||||
minimum_validator_count: u32,
|
||||
fare: bool,
|
||||
}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
@@ -99,12 +99,12 @@ impl Default for ExtBuilder {
|
||||
session_length: 1,
|
||||
sessions_per_era: 1,
|
||||
current_era: 0,
|
||||
monied: true,
|
||||
reward: 10,
|
||||
validator_pool: false,
|
||||
nominate: true,
|
||||
validator_count: 2,
|
||||
minimum_validator_count: 0,
|
||||
fare: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,16 +126,7 @@ impl ExtBuilder {
|
||||
self.current_era = current_era;
|
||||
self
|
||||
}
|
||||
pub fn _monied(mut self, monied: bool) -> Self {
|
||||
self.monied = monied;
|
||||
self
|
||||
}
|
||||
pub fn reward(mut self, reward: u64) -> Self {
|
||||
self.reward = reward;
|
||||
self
|
||||
}
|
||||
pub fn validator_pool(mut self, validator_pool: bool) -> Self {
|
||||
// NOTE: this should only be set to true with monied = false.
|
||||
pub fn validator_pool(mut self, validator_pool: bool) -> Self {
|
||||
self.validator_pool = validator_pool;
|
||||
self
|
||||
}
|
||||
@@ -152,6 +143,10 @@ impl ExtBuilder {
|
||||
self.minimum_validator_count = count;
|
||||
self
|
||||
}
|
||||
pub fn fare(mut self, is_fare: bool) -> Self {
|
||||
self.fare = is_fare;
|
||||
self
|
||||
}
|
||||
pub fn build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let (mut t, mut c) = system::GenesisConfig::<Test>::default().build_storage().unwrap();
|
||||
let balance_factor = if self.existential_deposit > 0 {
|
||||
@@ -170,34 +165,22 @@ impl ExtBuilder {
|
||||
keys: vec![],
|
||||
}.assimilate_storage(&mut t, &mut c);
|
||||
let _ = balances::GenesisConfig::<Test>{
|
||||
balances: if self.monied {
|
||||
if self.reward > 0 {
|
||||
vec![
|
||||
(1, 10 * balance_factor),
|
||||
(2, 20 * balance_factor),
|
||||
(3, 300 * balance_factor),
|
||||
(4, 400 * balance_factor),
|
||||
(10, balance_factor),
|
||||
(11, balance_factor * 1000),
|
||||
(20, balance_factor),
|
||||
(21, balance_factor * 2000),
|
||||
(100, 2000 * balance_factor),
|
||||
(101, 2000 * balance_factor),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
(1, 10 * balance_factor), (2, 20 * balance_factor),
|
||||
(3, 300 * balance_factor), (4, 400 * balance_factor)
|
||||
]
|
||||
}
|
||||
} else {
|
||||
vec![
|
||||
(10, balance_factor), (11, balance_factor * 10),
|
||||
(20, balance_factor), (21, balance_factor * 20),
|
||||
(30, balance_factor), (31, balance_factor * 30),
|
||||
(40, balance_factor), (41, balance_factor * 40)
|
||||
]
|
||||
},
|
||||
balances: vec![
|
||||
(1, 10 * balance_factor),
|
||||
(2, 20 * balance_factor),
|
||||
(3, 300 * balance_factor),
|
||||
(4, 400 * balance_factor),
|
||||
(10, balance_factor),
|
||||
(11, balance_factor * 1000),
|
||||
(20, balance_factor),
|
||||
(21, balance_factor * 2000),
|
||||
(30, balance_factor),
|
||||
(31, balance_factor * 2000),
|
||||
(40, balance_factor),
|
||||
(41, balance_factor * 2000),
|
||||
(100, 2000 * balance_factor),
|
||||
(101, 2000 * balance_factor),
|
||||
],
|
||||
transaction_base_fee: 0,
|
||||
transaction_byte_fee: 0,
|
||||
existential_deposit: self.existential_deposit,
|
||||
@@ -211,27 +194,26 @@ impl ExtBuilder {
|
||||
stakers: if self.validator_pool {
|
||||
vec![
|
||||
(11, 10, balance_factor * 1000, StakerStatus::<AccountIdType>::Validator),
|
||||
(21, 20, balance_factor * 2000, StakerStatus::<AccountIdType>::Validator),
|
||||
(31, 30, balance_factor * 3000, if self.validator_pool { StakerStatus::<AccountIdType>::Validator } else { StakerStatus::<AccountIdType>::Idle }),
|
||||
(41, 40, balance_factor * 4000, if self.validator_pool { StakerStatus::<AccountIdType>::Validator } else { StakerStatus::<AccountIdType>::Idle }),
|
||||
(21, 20, balance_factor * if self.fare { 1000 } else { 2000 }, StakerStatus::<AccountIdType>::Validator),
|
||||
(31, 30, balance_factor * 1000, if self.validator_pool { StakerStatus::<AccountIdType>::Validator } else { StakerStatus::<AccountIdType>::Idle }),
|
||||
(41, 40, balance_factor * 1000, if self.validator_pool { StakerStatus::<AccountIdType>::Validator } else { StakerStatus::<AccountIdType>::Idle }),
|
||||
// nominator
|
||||
(101, 100, balance_factor * 500, if self.nominate { StakerStatus::<AccountIdType>::Nominator(vec![10, 20]) } else { StakerStatus::<AccountIdType>::Nominator(vec![]) })
|
||||
(101, 100, balance_factor * 500, if self.nominate { StakerStatus::<AccountIdType>::Nominator(vec![11, 21]) } else { StakerStatus::<AccountIdType>::Nominator(vec![]) })
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
(11, 10, balance_factor * 1000, StakerStatus::<AccountIdType>::Validator),
|
||||
(21, 20, balance_factor * 2000, StakerStatus::<AccountIdType>::Validator),
|
||||
(21, 20, balance_factor * if self.fare { 1000 } else { 2000 }, StakerStatus::<AccountIdType>::Validator),
|
||||
// nominator
|
||||
(101, 100, balance_factor * 500, if self.nominate { StakerStatus::<AccountIdType>::Nominator(vec![10, 20]) } else { StakerStatus::<AccountIdType>::Nominator(vec![]) })
|
||||
(101, 100, balance_factor * 500, if self.nominate { StakerStatus::<AccountIdType>::Nominator(vec![11, 21]) } else { StakerStatus::<AccountIdType>::Nominator(vec![]) })
|
||||
]
|
||||
},
|
||||
validator_count: self.validator_count,
|
||||
minimum_validator_count: self.minimum_validator_count,
|
||||
bonding_duration: self.sessions_per_era * self.session_length * 3,
|
||||
session_reward: Perbill::from_millionths((1000000 * self.reward / balance_factor) as u32),
|
||||
offline_slash: if self.monied { Perbill::from_percent(40) } else { Perbill::zero() },
|
||||
offline_slash: Perbill::from_percent(5),
|
||||
current_session_reward: self.reward,
|
||||
current_offline_slash: 20,
|
||||
offline_slash_grace: 0,
|
||||
invulnerables: vec![],
|
||||
}.assimilate_storage(&mut t, &mut c);
|
||||
|
||||
Reference in New Issue
Block a user