Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07d82af
Recompile runtime.
gavofyork Jun 22, 2018
d467109
Introduce and enforce block time
gavofyork Jun 22, 2018
f714307
Introduce early session ending.
gavofyork Jun 22, 2018
19fe55f
Report most of staking module
gavofyork Jun 23, 2018
b8f2689
rewards, proper early exit and slashing
gavofyork Jun 23, 2018
5ac27b5
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 24, 2018
2ac1ecd
Fix build & session logic, introduce tests
gavofyork Jun 24, 2018
bd41bbc
Fixed staking tests.
gavofyork Jun 24, 2018
9016bc6
Initial test for reward
gavofyork Jun 25, 2018
7a11706
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 25, 2018
f679c22
Fix test
gavofyork Jun 25, 2018
4fb942f
Tests for slashing
gavofyork Jun 25, 2018
4b19d28
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 25, 2018
1ac443b
Update/fix preset configs
gavofyork Jun 25, 2018
31284c3
Fix some tests.
gavofyork Jun 25, 2018
bc9ad04
Fix some staking tests
gavofyork Jun 25, 2018
bd1b4a4
Minor fix
gavofyork Jun 25, 2018
cdfa86b
minor cleanups
gavofyork Jun 25, 2018
3ce3ca7
Nominating.
gavofyork Jun 25, 2018
c2f95ca
Slash/reward nominators
gavofyork Jun 25, 2018
447538c
Tests for nominating + slash/reward
gavofyork Jun 25, 2018
8cd7914
Merge branch 'master' into gav-staking-rewards
gavofyork Jun 26, 2018
353f51c
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 26, 2018
fe75f9a
Fix build
gavofyork Jun 26, 2018
75e160f
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 26, 2018
5b92dc1
Rename timestamp::Value -> Moment
gavofyork Jun 27, 2018
924ca4b
Merge remote-tracking branch 'origin/master' into gav-staking-rewards
gavofyork Jun 27, 2018
a3e8fe2
Merge branch 'gav-staking-rewards' into gav-delegation
gavofyork Jun 27, 2018
217ecc1
Avoid double-nominating/staking
gavofyork Jun 28, 2018
71f2a9e
Fix comment
gavofyork Jun 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests for slashing
  • Loading branch information
gavofyork committed Jun 25, 2018
commit 4fb942ff35067f5e55daac7b34d5c8f6d02006e8
1 change: 1 addition & 0 deletions substrate/runtime/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,5 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64

pub type System = system::Module<Test>;
pub type Session = session::Module<Test>;
pub type Timestamp = timestamp::Module<Test>;
pub type Staking = Module<Test>;
35 changes: 32 additions & 3 deletions substrate/runtime/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use super::*;
use runtime_io::with_externalities;
use mock::{Session, Staking, System, Test, new_test_ext};
use mock::{Session, Staking, System, Timestamp, Test, new_test_ext};

#[test]
fn reward_should_work() {
Expand All @@ -42,20 +42,49 @@ fn rewards_should_work() {
assert_eq!(Staking::voting_balance(&10), 1);

System::set_block_number(3);
Timestamp::set_timestamp(15); // on time.
Session::check_rotate_session();
assert_eq!(Staking::current_era(), 0);
assert_eq!(Session::current_index(), 1);
assert_eq!(Staking::voting_balance(&10), 11);
System::set_block_number(6);
Timestamp::set_timestamp(31); // a little late
Session::check_rotate_session();
assert_eq!(Staking::current_era(), 0);
assert_eq!(Session::current_index(), 2);
assert_eq!(Staking::voting_balance(&10), 21);
assert_eq!(Staking::voting_balance(&10), 20); // less reward
System::set_block_number(9);
Timestamp::set_timestamp(50); // very late
Session::check_rotate_session();
assert_eq!(Staking::current_era(), 1);
assert_eq!(Session::current_index(), 3);
assert_eq!(Staking::voting_balance(&10), 31);
assert_eq!(Staking::voting_balance(&10), 27); // much less reward
});
}

#[test]
fn slashing_should_work() {
with_externalities(&mut new_test_ext(0, 3, 3, 0, true), || {
assert_eq!(Staking::era_length(), 9);
assert_eq!(Staking::sessions_per_era(), 3);
assert_eq!(Staking::last_era_length_change(), 0);
assert_eq!(Staking::current_era(), 0);
assert_eq!(Session::current_index(), 0);
assert_eq!(Staking::voting_balance(&10), 1);

System::set_block_number(3);
Timestamp::set_timestamp(15); // on time.
Session::check_rotate_session();
assert_eq!(Staking::current_era(), 0);
assert_eq!(Session::current_index(), 1);
assert_eq!(Staking::voting_balance(&10), 11);

System::set_block_number(4);
Timestamp::set_timestamp(100); // way too late - early exit.
Session::check_rotate_session();
assert_eq!(Staking::current_era(), 1);
assert_eq!(Session::current_index(), 2);
assert_eq!(Staking::voting_balance(&10), 1);
});
}

Expand Down