diff --git a/crates/core/app/tests/mock_consensus.rs b/crates/core/app/tests/mock_consensus.rs index 5a2c3490b2..f5cd9e5a1d 100644 --- a/crates/core/app/tests/mock_consensus.rs +++ b/crates/core/app/tests/mock_consensus.rs @@ -20,7 +20,7 @@ use { }, rand_core::OsRng, tap::Tap, - tracing::{error_span, info, Instrument}, + tracing::info, }; /// Exercises that a test node can be instantiated using the consensus service. @@ -83,29 +83,12 @@ async fn mock_consensus_can_send_a_sequence_of_empty_blocks() -> anyhow::Result< let storage = TempStorage::new().await?; let mut test_node = common::start_test_node(&storage).await?; - // Check that we begin at height 0, before any blocks have been generated. - assert_eq!( - storage.latest_snapshot().get_block_height().await?, - 0, - "height should begin at 0" - ); - - for expected in 1..=8 { - // Generate an empty block. - test_node - .block() - .with_data(vec![]) - .execute() - .instrument(error_span!("executing block", %expected)) - .await?; - - // Check that the latest snapshot has the expected block height. - let height = storage.latest_snapshot().get_block_height().await?; - assert_eq!( - height, expected, - "height should continue to incrementally grow" - ); - } + let height = || async { storage.latest_snapshot().get_block_height().await }; + + // Fast forward eight blocks, and show that the height is 8 after doing so. + assert_eq!(height().await?, 0, "height should begin at 0"); + test_node.fast_forward(8).await?; + assert_eq!(height().await?, 8_u64, "height should grow"); // Free our temporary storage. drop(storage); diff --git a/crates/test/mock-consensus/src/lib.rs b/crates/test/mock-consensus/src/lib.rs index 9ef65dcb2f..1160e566e8 100644 --- a/crates/test/mock-consensus/src/lib.rs +++ b/crates/test/mock-consensus/src/lib.rs @@ -40,3 +40,42 @@ impl TestNode { format!("{:02X?}", self.last_app_hash) } } + +impl TestNode +where + C: tower::Service< + tendermint::v0_37::abci::ConsensusRequest, + Response = tendermint::v0_37::abci::ConsensusResponse, + Error = tower::BoxError, + > + Send + + Clone + + 'static, + C::Future: Send + 'static, + C::Error: Sized, +{ + /// Fast forwards a number of blocks. + #[tracing::instrument( + skip(self), + fields( + height = %self.height, + fast_forward.blocks = %blocks, + ) + )] + pub async fn fast_forward(&mut self, blocks: usize) -> anyhow::Result<()> { + use { + tap::Tap, + tracing::{info, trace}, + }; + + for i in 0..blocks { + self.block() + .with_data(vec![]) + .execute() + .tap(|_| trace!(%i, "executing empty block")) + .await + .tap(|_| trace!(%i, "finished executing empty block"))?; + } + + Ok(()).tap(|_| info!("finished fast forward")) + } +}