From af797f893fcbf6f6a4f3639b8aa60e144cd616e4 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 19 Mar 2024 10:31:08 -0400 Subject: [PATCH] tests(app): shorten epoch length in staking test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 🚠 overview in #4001 we added a test for the staking component (_see also #3995, and #3588_). this shortens the epoch length, so that this test runs in less time, and importantly, so that debugging test failures does not entail sifting through many log lines. ### ➕ changes * manually construct an `AppState` so that we use a shorter epoch. this test involves waiting for multiple epochs to pass, which takes many seconds with the default length of 719, see: * `TestNode::fast_forward` now accepts a u64, mirroring the type used in the sct parameters. ### 🏃 runtime on `main`... ``` Starting 1 test across 1 binary PASS [ 12.646s] penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator ------------ Summary [ 12.647s] 1 test run: 1 passed, 0 skipped ``` after these changes... ``` Starting 1 test across 1 binary PASS [ 0.420s] penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator ------------ Summary [ 0.420s] 1 test run: 1 passed, 0 skipped ``` ### 🥙 log volume on `main`... ``` ; RUST_LOG='info' cargo nextest run -p penumbra-app --test mock_consensus_staking --no-capture | wc -l Finished test [unoptimized + debuginfo] target(s) in 0.16s Starting 1 test across 1 binary START penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator PASS [ 12.185s] penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator ------------ Summary [ 12.185s] 1 test run: 1 passed, 0 skipped 46082 ``` ``` ; RUST_LOG='info' cargo nextest run -p penumbra-app --test mock_consensus_staking --no-capture | wc -l Finished test [unoptimized + debuginfo] target(s) in 0.15s Starting 1 test across 1 binary START penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator PASS [ 0.416s] penumbra-app::mock_consensus_staking mock_consensus_can_define_and_delegate_to_a_validator ------------ Summary [ 0.416s] 1 test run: 1 passed, 0 skipped 450 ``` --- .../core/app/tests/mock_consensus_staking.rs | 18 +++++++++++++----- crates/test/mock-consensus/src/lib.rs | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/core/app/tests/mock_consensus_staking.rs b/crates/core/app/tests/mock_consensus_staking.rs index c40f384c55..8a4a2a803c 100644 --- a/crates/core/app/tests/mock_consensus_staking.rs +++ b/crates/core/app/tests/mock_consensus_staking.rs @@ -20,16 +20,27 @@ use { mod common; +const EPOCH_DURATION: u64 = 8; + #[tokio::test] async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> { // Install a test logger, acquire some temporary storage, and start the test node. let guard = common::set_tracing_subscriber(); let storage = TempStorage::new().await?; + // Configure an AppState with slightly shorter epochs than usual. + let app_state = AppState::Content(penumbra_genesis::Content { + sct_content: penumbra_sct::genesis::Content { + sct_params: penumbra_sct::params::SctParameters { + epoch_duration: EPOCH_DURATION, + }, + }, + ..Default::default() + }); + // Start the test node. let mut node = { let consensus = Consensus::new(storage.as_ref().clone()); - let app_state = AppState::default(); TestNode::builder() .single_validator() .with_penumbra_auto_app_state(app_state)? @@ -43,12 +54,9 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu .await? .tap(|c| info!(client.notes = %c.notes.len(), "mock client synced to test storage")); - // TODO(kate): get this number by querying the chain parameters. - const EPOCH_LENGTH: usize = 1000; - // Fast forward to the next epoch. let snapshot_start = storage.latest_snapshot(); - node.fast_forward(EPOCH_LENGTH) + node.fast_forward(EPOCH_DURATION) .instrument(error_span!("fast forwarding test node to next epoch")) .await .context("fast forwarding {EPOCH_LENGTH} blocks")?; diff --git a/crates/test/mock-consensus/src/lib.rs b/crates/test/mock-consensus/src/lib.rs index d28781899e..13ae230924 100644 --- a/crates/test/mock-consensus/src/lib.rs +++ b/crates/test/mock-consensus/src/lib.rs @@ -78,7 +78,7 @@ where skip(self), fields(fast_forward.blocks = %blocks) )] - pub async fn fast_forward(&mut self, blocks: usize) -> anyhow::Result<()> { + pub async fn fast_forward(&mut self, blocks: u64) -> anyhow::Result<()> { use { tap::Tap, tracing::{info, trace, trace_span, Instrument},