diff --git a/substrate/client/tests/common/validator_sets.rs b/substrate/client/tests/common/validator_sets.rs index e5ec464c4..b7257a1ce 100644 --- a/substrate/client/tests/common/validator_sets.rs +++ b/substrate/client/tests/common/validator_sets.rs @@ -73,7 +73,7 @@ pub async fn allocate_stake( nonce: u32, ) -> [u8; 32] { // get the call - let tx = serai.sign(&pair, SeraiValidatorSets::allocate(network, amount), nonce, 0); + let tx = serai.sign(pair, SeraiValidatorSets::allocate(network, amount), nonce, 0); publish_tx(serai, &tx).await } @@ -86,6 +86,6 @@ pub async fn deallocate_stake( nonce: u32, ) -> [u8; 32] { // get the call - let tx = serai.sign(&pair, SeraiValidatorSets::deallocate(network, amount), nonce, 0); + let tx = serai.sign(pair, SeraiValidatorSets::deallocate(network, amount), nonce, 0); publish_tx(serai, &tx).await } diff --git a/substrate/client/tests/validator_sets.rs b/substrate/client/tests/validator_sets.rs index 5a2b12861..4b0e55304 100644 --- a/substrate/client/tests/validator_sets.rs +++ b/substrate/client/tests/validator_sets.rs @@ -178,7 +178,7 @@ async fn validator_set_rotation() { // we start the chain with 4 default participants that has a single key share each participants.sort(); - verify_session_and_active_validators(&serai, network, 0, &participants).await; + verify_session_and_active_validators(&serai, network, 0, participants).await; // add 1 participant & verify let hash = @@ -190,7 +190,7 @@ async fn validator_set_rotation() { &serai, network, get_active_session(&serai, network, hash).await, - &participants, + participants, ) .await; @@ -201,7 +201,7 @@ async fn validator_set_rotation() { participants.swap_remove(participants.iter().position(|k| *k == pair2.public()).unwrap()); let active_session = get_active_session(&serai, network, hash).await; participants.sort(); - verify_session_and_active_validators(&serai, network, active_session, &participants).await; + verify_session_and_active_validators(&serai, network, active_session, participants).await; // check pending deallocations let pending = serai diff --git a/substrate/validator-sets/pallet/src/lib.rs b/substrate/validator-sets/pallet/src/lib.rs index 3d73b6515..76c07e1cb 100644 --- a/substrate/validator-sets/pallet/src/lib.rs +++ b/substrate/validator-sets/pallet/src/lib.rs @@ -652,7 +652,7 @@ pub mod pallet { // If not Serai, check the prior session had its keys cleared, which happens once its // retired return (network == NetworkId::Serai) || - (Keys::::contains_key(ValidatorSet { + (!Keys::::contains_key(ValidatorSet { network, session: Session(current_session.0 - 1), })); diff --git a/tests/coordinator/src/tests/key_gen.rs b/tests/coordinator/src/tests/key_gen.rs index 34806aea5..de65ee4a6 100644 --- a/tests/coordinator/src/tests/key_gen.rs +++ b/tests/coordinator/src/tests/key_gen.rs @@ -200,7 +200,7 @@ pub async fn key_gen( assert_eq!(key_pair.0 .0, substrate_key); assert_eq!(&key_pair.1, &network_key); } - _ => panic!("coordinator didn't respond with ConfirmKeyPair msg: {:?} ", msg), + _ => panic!("coordinator didn't respond with ConfirmKeyPair msg: {msg:?}"), } message = Some(msg); } else { diff --git a/tests/coordinator/src/tests/mod.rs b/tests/coordinator/src/tests/mod.rs index b50af127c..95b8f682d 100644 --- a/tests/coordinator/src/tests/mod.rs +++ b/tests/coordinator/src/tests/mod.rs @@ -23,8 +23,6 @@ mod sign; pub use sign::sign; mod rotation; -#[allow(unused_imports)] -pub use rotation::rotate; pub(crate) const COORDINATORS: usize = 4; pub(crate) const THRESHOLD: usize = ((COORDINATORS * 2) / 3) + 1; diff --git a/tests/coordinator/src/tests/rotation.rs b/tests/coordinator/src/tests/rotation.rs index d5e5aafcf..8249e5ad9 100644 --- a/tests/coordinator/src/tests/rotation.rs +++ b/tests/coordinator/src/tests/rotation.rs @@ -1,7 +1,6 @@ use tokio::time::{sleep, Duration}; -use zeroize::Zeroizing; -use ciphersuite::{Ciphersuite, Ristretto, Secp256k1}; +use ciphersuite::Secp256k1; use serai_client::{ primitives::{insecure_pair_from_name, NetworkId}, @@ -64,7 +63,7 @@ async fn allocate_stake( ) -> [u8; 32] { // get the call let tx = - serai.sign(&pair, validator_sets::SeraiValidatorSets::allocate(network, amount), nonce, 0); + serai.sign(pair, validator_sets::SeraiValidatorSets::allocate(network, amount), nonce, 0); publish_tx(serai, &tx).await } @@ -78,7 +77,7 @@ async fn deallocate_stake( ) -> [u8; 32] { // get the call let tx = - serai.sign(&pair, validator_sets::SeraiValidatorSets::deallocate(network, amount), nonce, 0); + serai.sign(pair, validator_sets::SeraiValidatorSets::deallocate(network, amount), nonce, 0); publish_tx(serai, &tx).await } @@ -95,8 +94,6 @@ async fn wait_till_next_epoch(serai: &Serai, current_epoch: u32) -> Session { .await .unwrap() .unwrap(); - - println!("current session: {} ", session.0); } session } @@ -114,8 +111,7 @@ async fn new_set_events( let mut current_session = get_session(serai, current_block.hash(), network).await; while current_session == session { - let mut events = - serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap(); + let events = serai.as_of(current_block.hash()).validator_sets().new_set_events().await.unwrap(); if !events.is_empty() { return events; } @@ -127,51 +123,6 @@ async fn new_set_events( panic!("can't find the new set events for session: {} ", session.0); } -pub async fn rotate( - processors: &mut Vec, - excluded: Processor, - _: &[u8], - _: &Zeroizing<::F>, -) { - // accounts - let pair1 = insecure_pair_from_name("Alice"); - let pair5 = insecure_pair_from_name("Eve"); - - let network = NetworkId::Bitcoin; - let amount = Amount(1_000_000 * 10_u64.pow(8)); - let serai = processors[0].serai().await; - - // add the last participant into validator set for btc network - let block = allocate_stake(&serai, network, amount, &pair5, 0).await; - - // wait until next session to see the effect on coordinator - let current_epoch = get_session(&serai, block, NetworkId::Serai).await; - let session = wait_till_next_epoch(&serai, current_epoch.0).await; - - // verfiy that coordinator received new_set - let events = new_set_events(&serai, session, network).await; - assert!(events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } })); - - // do the keygen - processors.push(excluded); - let _ = key_gen::(processors, session).await; - - // pop 1 participant - let block = deallocate_stake(&serai, network, amount, &pair1, 0).await; - - // wait for this epoch to end - let current_epoch = get_session(&serai, block, NetworkId::Serai).await; - let session = wait_till_next_epoch(&serai, current_epoch.0).await; - - // verfiy that coordinator received new_set - let events = new_set_events(&serai, session, network).await; - assert!(events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } })); - - // do the keygen - processors.remove(0); - let _ = key_gen::(processors, session).await; -} - #[tokio::test] async fn set_rotation_test() { new_test( @@ -180,10 +131,30 @@ async fn set_rotation_test() { let excluded = processors.pop().unwrap(); assert_eq!(processors.len(), COORDINATORS); - let (processor_is, substrate_key, _) = - key_gen::(&mut processors, Session(0)).await; + // genesis keygen + let _ = key_gen::(&mut processors, Session(0)).await; + + let pair5 = insecure_pair_from_name("Eve"); + let network = NetworkId::Bitcoin; + let amount = Amount(1_000_000 * 10_u64.pow(8)); + let serai = processors[0].serai().await; + + // add the last participant into validator set for btc network + let block = allocate_stake(&serai, network, amount, &pair5, 0).await; + + // wait until next session to see the effect on coordinator + let current_epoch = get_session(&serai, block, NetworkId::Serai).await; + let session = wait_till_next_epoch(&serai, current_epoch.0).await; + + // verfiy that coordinator received new_set + let events = new_set_events(&serai, session, network).await; + assert!( + events.contains(&ValidatorSetsEvent::NewSet { set: ValidatorSet { session, network } }) + ); - rotate(&mut processors, excluded, &processor_is, &substrate_key).await; + // add the last participant & do the keygen + processors.push(excluded); + let _ = key_gen::(&mut processors, session).await; }, true, )