From bb8e034e68f13fdb780567c8c1fab77f0b413aad Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 13 Nov 2023 00:43:35 -0500 Subject: [PATCH] Test historic start times in tendermint-machine Closes https://github.com/serai-dex/serai/issues/342. Under ideal network conditions, this is fine. While I won't claim ideal network conditions will occur IRL, b0fcdd3367e4e0a808c59cff887ea2524e88a957 has the Tributary rebroadcast messages and should brute-force its way into a functioning system. --- coordinator/tributary/tendermint/tests/ext.rs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/coordinator/tributary/tendermint/tests/ext.rs b/coordinator/tributary/tendermint/tests/ext.rs index 928efbbc8..295d9a840 100644 --- a/coordinator/tributary/tendermint/tests/ext.rs +++ b/coordinator/tributary/tendermint/tests/ext.rs @@ -81,7 +81,7 @@ impl Weights for TestWeights { 4 } fn weight(&self, id: TestValidatorId) -> u64 { - [1; 4][usize::try_from(id).unwrap()] + [1; 4][usize::from(id)] } fn proposer(&self, number: BlockNumber, round: RoundNumber) -> TestValidatorId { @@ -137,9 +137,8 @@ impl Network for TestNetwork { } } - async fn slash(&mut self, _: TestValidatorId, _: SlashEvent) { - dbg!("Slash"); - todo!() + async fn slash(&mut self, id: TestValidatorId, event: SlashEvent) { + println!("Slash for {id} due to {event:?}"); } async fn validate(&mut self, block: &TestBlock) -> Result<(), BlockError> { @@ -151,7 +150,7 @@ impl Network for TestNetwork { block: TestBlock, commit: Commit, ) -> Option { - dbg!("Adding ", &block); + println!("Adding {:?}", &block); assert!(block.valid.is_ok()); assert!(self.verify_commit(block.id(), &commit)); Some(TestBlock { id: (u32::from_le_bytes(block.id) + 1).to_le_bytes(), valid: Ok(()) }) @@ -161,6 +160,7 @@ impl Network for TestNetwork { impl TestNetwork { async fn new( validators: usize, + start_time: u64, ) -> Arc, SyncedBlockSender, SyncedBlockResultReceiver)>>> { let arc = Arc::new(RwLock::new(vec![])); @@ -172,7 +172,7 @@ impl TestNetwork { TendermintMachine::new( TestNetwork(i, arc.clone()), BlockNumber(1), - SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(), + start_time, TestBlock { id: 1u32.to_le_bytes(), valid: Ok(()) }, ) .await; @@ -185,7 +185,13 @@ impl TestNetwork { } #[tokio::test] -async fn test() { - TestNetwork::new(4).await; +async fn test_machine() { + TestNetwork::new(4, SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()).await; + sleep(Duration::from_secs(30)).await; +} + +#[tokio::test] +async fn test_machine_with_historic_start_time() { + TestNetwork::new(4, SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() - 60).await; sleep(Duration::from_secs(30)).await; }