From d7650ad83552b73e114345197facbe7c1d865522 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 11 Jan 2021 15:22:57 +0800 Subject: [PATCH] Update Relay Authorities Protocol (#440) * update: relay authorities protocol * test: `authority_term_should_work` * update: test --- frame/bridge/relay-authorities/src/lib.rs | 6 +----- frame/bridge/relay-authorities/src/test.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frame/bridge/relay-authorities/src/lib.rs b/frame/bridge/relay-authorities/src/lib.rs index 3371c15dc0..96dfe4323c 100644 --- a/frame/bridge/relay-authorities/src/lib.rs +++ b/frame/bridge/relay-authorities/src/lib.rs @@ -492,9 +492,6 @@ decl_module! { let (message, mut signatures) = if let Some(signatures) = >::get() { signatures } else { - // Should never enter this condition - // TODO: error log - return Ok(()); }; @@ -547,7 +544,6 @@ decl_module! { } >::kill(); - >::mutate(|term| *term += 1); >::kill(); >::kill(); { @@ -676,7 +672,6 @@ where pub fn wait_target_chain_authorities_change() { >::kill(); >::mutate(|authorities_state| authorities_state.1 = 0.into()); - >::mutate(|authority_term| *authority_term += 1); for account_id in >::take() { >::remove_lock(T::LockId::get(), &account_id); @@ -771,6 +766,7 @@ where fn finish_authorities_change() { >::kill(); + >::mutate(|authority_term| *authority_term += 1); } } diff --git a/frame/bridge/relay-authorities/src/test.rs b/frame/bridge/relay-authorities/src/test.rs index b67784af93..4d3356e3f1 100644 --- a/frame/bridge/relay-authorities/src/test.rs +++ b/frame/bridge/relay-authorities/src/test.rs @@ -159,6 +159,22 @@ fn kill_candidates_should_work() { }); } +#[test] +fn authority_term_should_work() { + new_test_ext().execute_with(|| { + let max_candidates = >::get(); + + for i in 1..=max_candidates { + assert_eq!(RelayAuthorities::authority_term(), i as Term - 1); + assert_ok!(request_authority(i as _)); + assert_ok!(RelayAuthorities::add_authority(Origin::root(), i as _)); + + RelayAuthorities::finish_authorities_change(); + assert_eq!(RelayAuthorities::authority_term(), i as Term); + } + }); +} + #[test] fn encode_message_should_work() { // --- substrate ---