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:
Gav Wood
2019-03-02 14:31:48 +01:00
committed by GitHub
parent ff331e7fdc
commit 828cd9580a
24 changed files with 1871 additions and 910 deletions
+52 -33
View File
@@ -66,6 +66,18 @@ mod tests {
AccountId::from(Keyring::Charlie.to_raw_public())
}
fn dave() -> AccountId {
AccountId::from(Keyring::Dave.to_raw_public())
}
fn eve() -> AccountId {
AccountId::from(Keyring::Eve.to_raw_public())
}
fn ferdie() -> AccountId {
AccountId::from(Keyring::Ferdie.to_raw_public())
}
fn sign(xt: CheckedExtrinsic) -> UncheckedExtrinsic {
match xt.signed {
Some((signed, index)) => {
@@ -258,12 +270,16 @@ mod tests {
..Default::default()
}),
indices: Some(IndicesConfig {
ids: vec![alice(), charlie()],
ids: vec![alice(), bob(), charlie(), dave(), eve(), ferdie()],
}),
balances: Some(BalancesConfig {
balances: vec![
(alice(), 111),
(bob(), 100),
(charlie(), 100_000_000),
(dave(), 100),
(eve(), 100),
(ferdie(), 100),
],
existential_deposit: 0,
transfer_fee: 0,
@@ -273,11 +289,16 @@ mod tests {
session: Some(SessionConfig {
session_length: 2,
validators: vec![Keyring::One.to_raw_public().into(), Keyring::Two.to_raw_public().into(), three],
keys: vec![
(alice(), keyring::ed25519::Keyring::Alice.to_raw_public().into()),
(bob(), keyring::ed25519::Keyring::Bob.to_raw_public().into()),
(charlie(), keyring::ed25519::Keyring::Charlie.to_raw_public().into())
]
}),
staking: Some(StakingConfig {
sessions_per_era: 2,
current_era: 0,
intentions: vec![alice(), bob(), Keyring::Charlie.to_raw_public().into()],
stakers: vec![(dave(), alice(), 111), (eve(), bob(), 100), (ferdie(), charlie(), 100)],
validator_count: 3,
minimum_validator_count: 0,
bonding_duration: 0,
@@ -286,7 +307,7 @@ mod tests {
current_offline_slash: 0,
current_session_reward: 0,
offline_slash_grace: 0,
invulnerables: vec![alice(), bob(), Keyring::Charlie.to_raw_public().into()],
invulnerables: vec![alice(), bob(), charlie()],
}),
democracy: Some(Default::default()),
council_seats: Some(Default::default()),
@@ -297,9 +318,9 @@ mod tests {
sudo: Some(Default::default()),
grandpa: Some(GrandpaConfig {
authorities: vec![ // set these so no GRANDPA events fire when session changes
(Keyring::Alice.to_raw_public().into(), 1),
(Keyring::Bob.to_raw_public().into(), 1),
(Keyring::Charlie.to_raw_public().into(), 1),
(keyring::ed25519::Keyring::Alice.to_raw_public().into(), 1),
(keyring::ed25519::Keyring::Bob.to_raw_public().into(), 1),
(keyring::ed25519::Keyring::Charlie.to_raw_public().into(), 1),
],
}),
fees: Some(FeesConfig {
@@ -353,7 +374,7 @@ mod tests {
).0.unwrap();
}
let correct_header = match Executor::new(None).call::<_, NeverNativeValue, fn() -> _>(
let header = match Executor::new(None).call::<_, NeverNativeValue, fn() -> _>(
env,
"BlockBuilder_finalise_block",
&[0u8;0],
@@ -364,9 +385,8 @@ mod tests {
NativeOrEncoded::Encoded(h) => Header::decode(&mut &h[..]).unwrap(),
};
let hash = correct_header.blake2_256();
(Block { header: correct_header, extrinsics }.encode(), hash.into())
let hash = header.blake2_256();
(Block { header, extrinsics }.encode(), hash.into())
}
fn changes_trie_block() -> (Vec<u8>, Hash) {
@@ -471,24 +491,15 @@ mod tests {
).0.unwrap();
runtime_io::with_externalities(&mut t, || {
assert_eq!(Balances::total_balance(&alice()), 41);
assert_eq!(Balances::total_balance(&bob()), 69);
// block1 transfers from alice 69 to bob.
// -1 is the default fee
assert_eq!(Balances::total_balance(&alice()), 111 - 69 - 1);
assert_eq!(Balances::total_balance(&bob()), 100 + 69);
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
event: Event::system(system::Event::ExtrinsicSuccess)
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::indices(indices::RawEvent::NewAccountIndex(bob(), 2))
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::balances(balances::RawEvent::NewAccount(
bob().into(),
69
))
},
EventRecord {
phase: Phase::ApplyExtrinsic(1),
event: Event::balances(balances::RawEvent::Transfer(
@@ -530,8 +541,11 @@ mod tests {
).0.unwrap();
runtime_io::with_externalities(&mut t, || {
assert_eq!(Balances::total_balance(&alice()), 30);
assert_eq!(Balances::total_balance(&bob()), 78);
// bob sends 5, alice sends 15 | bob += 10, alice -= 10
// 111 - 69 - 1 - 10 - 1 = 30
assert_eq!(Balances::total_balance(&alice()), 111 - 69 - 1 - 10 - 1);
// 100 + 69 + 10 - 1 = 178
assert_eq!(Balances::total_balance(&bob()), 100 + 69 + 10 - 1);
assert_eq!(System::events(), vec![
EventRecord {
phase: Phase::ApplyExtrinsic(0),
@@ -571,10 +585,10 @@ mod tests {
phase: Phase::Finalization,
event: Event::session(session::RawEvent::NewSession(1))
},
EventRecord {
phase: Phase::Finalization,
event: Event::staking(staking::RawEvent::Reward(0))
},
// EventRecord {
// phase: Phase::Finalization,
// event: Event::staking(staking::RawEvent::Reward(0))
// },
EventRecord {
phase: Phase::Finalization,
event: Event::grandpa(::grandpa::RawEvent::NewAuthorities(vec![
@@ -616,15 +630,20 @@ mod tests {
WasmExecutor::new().call(&mut t, 8, COMPACT_CODE, "Core_execute_block", &block1.0).unwrap();
runtime_io::with_externalities(&mut t, || {
assert_eq!(Balances::total_balance(&alice()), 41);
assert_eq!(Balances::total_balance(&bob()), 69);
// block1 transfers from alice 69 to bob.
// -1 is the default fee
assert_eq!(Balances::total_balance(&alice()), 111 - 69 - 1);
assert_eq!(Balances::total_balance(&bob()), 100 + 69);
});
WasmExecutor::new().call(&mut t, 8, COMPACT_CODE, "Core_execute_block", &block2.0).unwrap();
runtime_io::with_externalities(&mut t, || {
assert_eq!(Balances::total_balance(&alice()), 30);
assert_eq!(Balances::total_balance(&bob()), 78);
// bob sends 5, alice sends 15 | bob += 10, alice -= 10
// 111 - 69 - 1 - 10 - 1 = 30
assert_eq!(Balances::total_balance(&alice()), 111 - 69 - 1 - 10 - 1);
// 100 + 69 + 10 - 1 = 178
assert_eq!(Balances::total_balance(&bob()), 100 + 69 + 10 - 1);
});
}