diff --git a/tests/coordinator/src/lib.rs b/tests/coordinator/src/lib.rs index 0baa84a3..c364128c 100644 --- a/tests/coordinator/src/lib.rs +++ b/tests/coordinator/src/lib.rs @@ -350,7 +350,7 @@ impl Processor { /// Receive a message from the coordinator as a processor. pub async fn recv_message(&mut self) -> CoordinatorMessage { - // Set a timeout of 30 minutes to allow effectively any protocol to occur without a fear of + // Set a timeout of 20 minutes to allow effectively any protocol to occur without a fear of // an arbitrary timeout cutting it short tokio::time::timeout(Duration::from_secs(20 * 60), self.msgs.recv()).await.unwrap().unwrap() } diff --git a/tests/coordinator/src/tests/batch.rs b/tests/coordinator/src/tests/batch.rs index 9cbd4b29..bfe4e36e 100644 --- a/tests/coordinator/src/tests/batch.rs +++ b/tests/coordinator/src/tests/batch.rs @@ -262,7 +262,7 @@ pub async fn batch( async fn batch_test() { new_test( |mut processors: Vec| async move { - // pop the last participant since genesis keygen has only 4 participant. + // pop the last participant since genesis keygen has only 4 participants processors.pop().unwrap(); assert_eq!(processors.len(), COORDINATORS); diff --git a/tests/coordinator/src/tests/key_gen.rs b/tests/coordinator/src/tests/key_gen.rs index de65ee4a..0bb7043c 100644 --- a/tests/coordinator/src/tests/key_gen.rs +++ b/tests/coordinator/src/tests/key_gen.rs @@ -32,16 +32,27 @@ pub async fn key_gen( let id = KeyGenId { session: set.session, attempt: 0 }; for (i, processor) in processors.iter_mut().enumerate() { - let mut found = false; - while !found { + loop { let msg = processor.recv_message().await; match &msg { CoordinatorMessage::KeyGen(messages::key_gen::CoordinatorMessage::GenerateKey { + id: this_id, params, - .. + shares, }) => { + assert_eq!(id, *this_id); + assert_eq!( + *params, + ThresholdParams::new( + u16::try_from(((coordinators * 2) / 3) + 1).unwrap(), + u16::try_from(coordinators).unwrap(), + participant_is[i], + ) + .unwrap() + ); + assert_eq!(*shares, 1); participant_is.push(params.i()); - found = true; + break; } CoordinatorMessage::Substrate( messages::substrate::CoordinatorMessage::ConfirmKeyPair { .. }, @@ -50,20 +61,6 @@ pub async fn key_gen( } _ => panic!("unexpected message: {msg:?}"), } - - assert_eq!( - msg, - CoordinatorMessage::KeyGen(messages::key_gen::CoordinatorMessage::GenerateKey { - id, - params: ThresholdParams::new( - u16::try_from(((coordinators * 2) / 3) + 1).unwrap(), - u16::try_from(coordinators).unwrap(), - participant_is[i], - ) - .unwrap(), - shares: 1, - }) - ); } processor @@ -193,14 +190,14 @@ pub async fn key_gen( .unwrap() .as_secs() .abs_diff(context.serai_time) < - (60 * 60 * 3) // 3hrs + (60 * 60 * 3) // 3 hours, which should exceed the length of any test we run ); assert_eq!(context.network_latest_finalized_block.0, [0; 32]); assert_eq!(set.session, session); 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 { @@ -233,7 +230,7 @@ pub async fn key_gen( async fn key_gen_test() { new_test( |mut processors: Vec| async move { - // pop the last participant since genesis keygen has only 4 participant. + // pop the last participant since genesis keygen has only 4 participants processors.pop().unwrap(); assert_eq!(processors.len(), COORDINATORS); diff --git a/tests/coordinator/src/tests/mod.rs b/tests/coordinator/src/tests/mod.rs index d7ba21c2..ef67b0ac 100644 --- a/tests/coordinator/src/tests/mod.rs +++ b/tests/coordinator/src/tests/mod.rs @@ -47,7 +47,9 @@ pub(crate) async fn new_test(test_body: impl TestBody, fast_epoch: bool) { let mut coordinators = vec![]; let mut test = DockerTest::new().with_network(dockertest::Network::Isolated); let mut coordinator_compositions = vec![]; - for i in 0 .. 5 { + // Spawn one extra coordinator which isn't in-set + #[allow(clippy::range_plus_one)] + for i in 0 .. (COORDINATORS + 1) { let name = match i { 0 => "Alice", 1 => "Bob",