From 21f1fba74f66052564764d93c119a712d27d0aa3 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sat, 20 Jun 2020 15:15:55 +0200 Subject: [PATCH] more unit tests --- scheduler/src/tests.rs | 54 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/scheduler/src/tests.rs b/scheduler/src/tests.rs index 5e5cb726..e0a2ec40 100644 --- a/scheduler/src/tests.rs +++ b/scheduler/src/tests.rs @@ -262,7 +262,7 @@ fn push_one_day_works() { run_to_block(1); let _ = Timestamp::dispatch( as ProvideInherent>::Call:: set(genesis_time + TEN_MIN), Origin::NONE); - + assert_ok!(EncointerScheduler::push_by_one_day(Origin::signed( MASTER ))); @@ -483,3 +483,55 @@ fn resync_after_next_phase_works_during_assigning() { }); } +#[test] +fn resync_after_next_phase_works_during_attesting() { + ExtBuilder::default().equal_phase_duration(ONE_DAY).build().execute_with(|| { + let genesis_time: u64 = 0; + + System::set_block_number(0); + + let _ = Timestamp::dispatch( as ProvideInherent>::Call:: + set(genesis_time), Origin::NONE); + + assert_eq!(EncointerScheduler::current_ceremony_index(), 1); + assert_eq!( + EncointerScheduler::current_phase(), + CeremonyPhaseType::REGISTERING + ); + assert_eq!(EncointerScheduler::next_phase_timestamp(), + (genesis_time - genesis_time.rem(ONE_DAY)) + 1 * ONE_DAY); + + run_to_block(1); + let _ = Timestamp::dispatch( as ProvideInherent>::Call:: + set(genesis_time + 1*ONE_DAY+ TEN_MIN), Origin::NONE); + + run_to_block(2); + let _ = Timestamp::dispatch( as ProvideInherent>::Call:: + set(genesis_time + 2*ONE_DAY+ TEN_MIN), Origin::NONE); + + assert_eq!( + EncointerScheduler::current_phase(), + CeremonyPhaseType::ATTESTING + ); + + // now use next_phase manually + assert_ok!(EncointerScheduler::next_phase(Origin::signed( + MASTER + ))); + assert_ok!(EncointerScheduler::next_phase(Origin::signed( + MASTER + ))); + assert_ok!(EncointerScheduler::next_phase(Origin::signed( + MASTER + ))); + + assert_eq!(EncointerScheduler::current_ceremony_index(), 2); + assert_eq!( + EncointerScheduler::current_phase(), + CeremonyPhaseType::ATTESTING + ); + assert_eq!(EncointerScheduler::next_phase_timestamp(), + (genesis_time - genesis_time.rem(ONE_DAY)) + 3 * ONE_DAY); + + }); +}