Skip to content

Commit

Permalink
tests(app): ⌛ shorten epoch length in staking test (#4048)
Browse files Browse the repository at this point in the history
### 🚠 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:
<https://github.com/penumbra-zone/penumbra/blob/8be8e8266b312c2a9eb1b1522a937e8df12f3a4f/crates/core/component/sct/src/params.rs#L41>

* `TestNode<C>::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
```
  • Loading branch information
cratelyn authored Mar 19, 2024
1 parent 7ab4bcc commit 1ec7aba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions crates/core/app/tests/mock_consensus_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand All @@ -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")?;
Expand Down
2 changes: 1 addition & 1 deletion crates/test/mock-consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 1ec7aba

Please sign in to comment.