mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 05:51:02 +00:00
Stash/controller model for staking (#1782)
* First steps to stash/controller separation * More drafting * More drafting * Finish draft. * Optimisation * Remove accidental commit * Make it build. * Fix linked map for traits. * Fix Option<_> variant. * Improve naming a tad * Rebuild runtime * Builds! * First test. * Bump RT version * Minor fix * Update Mock * adds the correct reward testcase (+staking eras which was already ok) * fixes the basic staking testcase to work properly (along with a small fix in the module) * New logic to avoid controller transferring stash. * Fix some build issues. * adding some comments to tests * Fix impls. * adds a few more lines to explain the test case * More fixes. * gets the basic test up and running again * Fix rest of build * Rebuild wasm * Fix docs. * fix staking test with new chnages * updating some tests, pending questions * More working tests * adds double staking test * Docs * remove invalid slashing test * Payee stuff. * Fix build * Docs * Fix test * Fix a couple of tests * Layout plan for finishing tests before Pragmen * Add some working tests * re-build staking and reward tests * Add more tests * fix offline grace test * Nominator should have payee checked for cleanup * adds more nomination tets * adds validator prefs tests * Fix and clean up some TODOs * Fix a couple of issues * Fix tests * noting warnings from tests * final fix of local tests * Fix slot_stake bug * Half baked test * Add logic to limit `unstake_threshold` set in storage * Make sure to check before writing! Almost forgot this one * Move a couple of comments * fix last broken slot_stake test * Ignore broken test
This commit is contained in:
@@ -72,61 +72,103 @@ impl Trait for Test {
|
||||
type Event = ();
|
||||
}
|
||||
|
||||
pub fn new_test_ext(
|
||||
ext_deposit: u64,
|
||||
pub struct ExtBuilder {
|
||||
existential_deposit: u64,
|
||||
session_length: u64,
|
||||
sessions_per_era: u64,
|
||||
current_era: u64,
|
||||
monied: bool,
|
||||
reward: u64
|
||||
) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
|
||||
let balance_factor = if ext_deposit > 0 {
|
||||
256
|
||||
} else {
|
||||
1
|
||||
};
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length,
|
||||
validators: vec![10, 20],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(balances::GenesisConfig::<Test>{
|
||||
balances: if monied {
|
||||
if reward > 0 {
|
||||
vec![(1, 10 * balance_factor), (2, 20 * balance_factor), (3, 30 * balance_factor), (4, 40 * balance_factor), (10, balance_factor), (20, balance_factor)]
|
||||
} else {
|
||||
vec![(1, 10 * balance_factor), (2, 20 * balance_factor), (3, 30 * balance_factor), (4, 40 * balance_factor)]
|
||||
}
|
||||
reward: u64,
|
||||
}
|
||||
|
||||
impl Default for ExtBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
existential_deposit: 0,
|
||||
session_length: 3,
|
||||
sessions_per_era: 3,
|
||||
current_era: 0,
|
||||
monied: true,
|
||||
reward: 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBuilder {
|
||||
pub fn existential_deposit(mut self, existential_deposit: u64) -> Self {
|
||||
self.existential_deposit = existential_deposit;
|
||||
self
|
||||
}
|
||||
pub fn session_length(mut self, session_length: u64) -> Self {
|
||||
self.session_length = session_length;
|
||||
self
|
||||
}
|
||||
pub fn sessions_per_era(mut self, sessions_per_era: u64) -> Self {
|
||||
self.sessions_per_era = sessions_per_era;
|
||||
self
|
||||
}
|
||||
pub fn _current_era(mut self, current_era: u64) -> Self {
|
||||
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 build(self) -> runtime_io::TestExternalities<Blake2Hasher> {
|
||||
let mut t = system::GenesisConfig::<Test>::default().build_storage().unwrap().0;
|
||||
let balance_factor = if self.existential_deposit > 0 {
|
||||
256
|
||||
} else {
|
||||
vec![(10, balance_factor), (20, balance_factor)]
|
||||
},
|
||||
existential_deposit: ext_deposit,
|
||||
transfer_fee: 0,
|
||||
creation_fee: 0,
|
||||
vesting: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
sessions_per_era,
|
||||
current_era,
|
||||
intentions: vec![10, 20],
|
||||
validator_count: 2,
|
||||
minimum_validator_count: 0,
|
||||
bonding_duration: sessions_per_era * session_length * 3,
|
||||
session_reward: Perbill::from_millionths((1000000 * reward / balance_factor) as u32),
|
||||
offline_slash: if monied { Perbill::from_percent(40) } else { Perbill::zero() },
|
||||
current_session_reward: reward,
|
||||
current_offline_slash: 20,
|
||||
offline_slash_grace: 0,
|
||||
invulnerables: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
period: 5,
|
||||
}.build_storage().unwrap().0);
|
||||
runtime_io::TestExternalities::new(t)
|
||||
1
|
||||
};
|
||||
t.extend(consensus::GenesisConfig::<Test>{
|
||||
code: vec![],
|
||||
authorities: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(session::GenesisConfig::<Test>{
|
||||
session_length: self.session_length,
|
||||
validators: vec![10, 20],
|
||||
keys: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(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)]
|
||||
} 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 * 1000), (20, balance_factor), (21, balance_factor * 2000)]
|
||||
},
|
||||
existential_deposit: self.existential_deposit,
|
||||
transfer_fee: 0,
|
||||
creation_fee: 0,
|
||||
vesting: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(GenesisConfig::<Test>{
|
||||
sessions_per_era: self.sessions_per_era,
|
||||
current_era: self.current_era,
|
||||
stakers: vec![(11, 10, balance_factor * 1000), (21, 20, balance_factor * 2000)],
|
||||
validator_count: 2,
|
||||
minimum_validator_count: 0,
|
||||
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() },
|
||||
current_session_reward: self.reward,
|
||||
current_offline_slash: 20,
|
||||
offline_slash_grace: 0,
|
||||
invulnerables: vec![],
|
||||
}.build_storage().unwrap().0);
|
||||
t.extend(timestamp::GenesisConfig::<Test>{
|
||||
period: 5,
|
||||
}.build_storage().unwrap().0);
|
||||
t.into()
|
||||
}
|
||||
}
|
||||
|
||||
pub type System = system::Module<Test>;
|
||||
|
||||
Reference in New Issue
Block a user