From 85823bd19570b36319c56fbbe6940d8b0791df2c Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 26 Mar 2024 11:42:56 -0400 Subject: [PATCH] =?UTF-8?q?tests(app):=20=F0=9F=8C=AF=20reorganize,=20rena?= =?UTF-8?q?me=20mock=20consensus=20integration=20tests=20(#4103)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > it's probably about time to rename the app/tests/mock_consensus\w*.rs tests, and the test cases contained therein. at this point they're becoming the app test suite, so phrasing them as though they're exercising the mock engine is a little backwards this follows up on this note, from the discord's #testing channel. --- ...can_define_and_delegate_to_a_validator.rs} | 6 +- ...app_can_spend_notes_and_detect_outputs.rs} | 84 +----------------- crates/core/app/tests/init_chain.rs | 85 +++++++++++++++++++ 3 files changed, 89 insertions(+), 86 deletions(-) rename crates/core/app/tests/{mock_consensus_staking.rs => app_can_define_and_delegate_to_a_validator.rs} (99%) rename crates/core/app/tests/{mock_consensus.rs => app_can_spend_notes_and_detect_outputs.rs} (54%) create mode 100644 crates/core/app/tests/init_chain.rs diff --git a/crates/core/app/tests/mock_consensus_staking.rs b/crates/core/app/tests/app_can_define_and_delegate_to_a_validator.rs similarity index 99% rename from crates/core/app/tests/mock_consensus_staking.rs rename to crates/core/app/tests/app_can_define_and_delegate_to_a_validator.rs index 3aa6cda6cb..606bd684d5 100644 --- a/crates/core/app/tests/mock_consensus_staking.rs +++ b/crates/core/app/tests/app_can_define_and_delegate_to_a_validator.rs @@ -26,7 +26,7 @@ use { const EPOCH_DURATION: u64 = 8; #[tokio::test] -async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> { +async fn app_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?; @@ -121,11 +121,9 @@ async fn mock_consensus_can_define_and_delegate_to_a_validator() -> anyhow::Resu let new_validator_consensus = new_validator_consensus_sk.verification_key(); // Insert the validator's consensus keypair into the keyring so it can be used to sign blocks. - /* node.keyring_mut() // Keyring should just be a BTreeMap rather than creating a new API - .insert(validator_consensus.clone(), validator_consensus_sk); - */ + .insert(new_validator_consensus, new_validator_consensus_sk); // Now define the validator's configuration data. let new_validator = Validator { diff --git a/crates/core/app/tests/mock_consensus.rs b/crates/core/app/tests/app_can_spend_notes_and_detect_outputs.rs similarity index 54% rename from crates/core/app/tests/mock_consensus.rs rename to crates/core/app/tests/app_can_spend_notes_and_detect_outputs.rs index f5cd9e5a1d..580145a74f 100644 --- a/crates/core/app/tests/mock_consensus.rs +++ b/crates/core/app/tests/app_can_spend_notes_and_detect_outputs.rs @@ -1,8 +1,3 @@ -//! App integration tests using mock consensus. -// -// Note: these should eventually replace the existing test cases. mock consensus tests are placed -// here while the engine is still in development. See #3588. - mod common; use { @@ -12,9 +7,8 @@ use { penumbra_mock_client::MockClient, penumbra_mock_consensus::TestNode, penumbra_proto::DomainType, - penumbra_sct::component::{clock::EpochRead, tree::SctRead as _}, + penumbra_sct::component::tree::SctRead as _, penumbra_shielded_pool::{OutputPlan, SpendPlan}, - penumbra_stake::component::validator_handler::ValidatorDataRead as _, penumbra_transaction::{ memo::MemoPlaintext, plan::MemoPlan, TransactionParameters, TransactionPlan, }, @@ -23,82 +17,8 @@ use { tracing::info, }; -/// Exercises that a test node can be instantiated using the consensus service. -#[tokio::test] -async fn mock_consensus_can_send_an_init_chain_request() -> 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?; - let _ = common::start_test_node(&storage).await?; - - // Free our temporary storage. - drop(storage); - drop(guard); - - Ok(()) -} - -/// Exercises that the mock consensus engine can provide a single genesis validator. -#[tokio::test] -async fn mock_consensus_can_define_a_genesis_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?; - let _test_node = common::start_test_node(&storage).await?; - - let snapshot = storage.latest_snapshot(); - let validators = snapshot - .validator_definitions() - .tap(|_| info!("getting validator definitions")) - .await?; - match validators.as_slice() { - [v] => { - let identity_key = v.identity_key; - let status = snapshot - .get_validator_state(&identity_key) - .await? - .ok_or_else(|| anyhow!("could not find validator status"))?; - assert_eq!( - status, - penumbra_stake::validator::State::Active, - "validator should be active" - ); - } - unexpected => panic!("there should be one validator, got: {unexpected:?}"), - } - - // Free our temporary storage. - drop(storage); - drop(guard); - - Ok(()) -} - -/// Exercises that a series of empty blocks, with no validator set present, can be successfully -/// executed by the consensus service. -#[tokio::test] -async fn mock_consensus_can_send_a_sequence_of_empty_blocks() -> 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?; - let mut test_node = common::start_test_node(&storage).await?; - - 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); - drop(guard); - - Ok(()) -} - #[tokio::test] -async fn mock_consensus_can_spend_notes_and_detect_outputs() -> anyhow::Result<()> { +async fn app_can_spend_notes_and_detect_outputs() -> 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?; diff --git a/crates/core/app/tests/init_chain.rs b/crates/core/app/tests/init_chain.rs new file mode 100644 index 0000000000..b983f3c420 --- /dev/null +++ b/crates/core/app/tests/init_chain.rs @@ -0,0 +1,85 @@ +//! App integration tests using mock consensus. +// +// Note: these should eventually replace the existing test cases. mock consensus tests are placed +// here while the engine is still in development. See #3588. + +mod common; + +use { + anyhow::anyhow, cnidarium::TempStorage, penumbra_sct::component::clock::EpochRead, + penumbra_stake::component::validator_handler::ValidatorDataRead as _, tap::Tap, tracing::info, +}; + +/// Exercises that a test node can be instantiated using the consensus service. +#[tokio::test] +async fn mock_consensus_can_send_an_init_chain_request() -> 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?; + let _ = common::start_test_node(&storage).await?; + + // Free our temporary storage. + drop(storage); + drop(guard); + + Ok(()) +} + +/// Exercises that the mock consensus engine can provide a single genesis validator. +#[tokio::test] +async fn mock_consensus_can_define_a_genesis_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?; + let _test_node = common::start_test_node(&storage).await?; + + let snapshot = storage.latest_snapshot(); + let validators = snapshot + .validator_definitions() + .tap(|_| info!("getting validator definitions")) + .await?; + match validators.as_slice() { + [v] => { + let identity_key = v.identity_key; + let status = snapshot + .get_validator_state(&identity_key) + .await? + .ok_or_else(|| anyhow!("could not find validator status"))?; + assert_eq!( + status, + penumbra_stake::validator::State::Active, + "validator should be active" + ); + } + unexpected => panic!("there should be one validator, got: {unexpected:?}"), + } + + // Free our temporary storage. + drop(storage); + drop(guard); + + Ok(()) +} + +/// Exercises that a series of empty blocks, with no validator set present, can be successfully +/// executed by the consensus service. +#[tokio::test] +async fn mock_consensus_can_send_a_sequence_of_empty_blocks() -> 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?; + let mut test_node = common::start_test_node(&storage).await?; + + 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); + drop(guard); + + Ok(()) +}