From 5ad993b5226d11bd0ed3989175340fbf390d7e8a Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 27 Feb 2024 14:18:43 -0500 Subject: [PATCH] =?UTF-8?q?mock-consensus:=20=F0=9F=8C=B1=20single=20genes?= =?UTF-8?q?is=20validator=20(work-in-progress)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + crates/core/app/tests/common/mod.rs | 8 +++++++ crates/test/mock-consensus/Cargo.toml | 1 + crates/test/mock-consensus/src/builder.rs | 24 ++++++++++++++----- .../mock-consensus/src/builder/init_chain.rs | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 298d2177c5..051b3006da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5273,6 +5273,7 @@ version = "0.68.0" dependencies = [ "anyhow", "bytes", + "penumbra-proto", "serde_json", "tap", "tendermint", diff --git a/crates/core/app/tests/common/mod.rs b/crates/core/app/tests/common/mod.rs index f400c349fb..38ae57c1d9 100644 --- a/crates/core/app/tests/common/mod.rs +++ b/crates/core/app/tests/common/mod.rs @@ -94,6 +94,14 @@ impl BuilderExt for penumbra_mock_consensus::builder::Builder { // - read out list of abci/comet validators from the builder, // - define a penumbra validator for each one // - inject that into the penumbra app state + let app_state: AppState = { + let mut content = match app_state { + AppState::Content(content) => content, + AppState::Checkpoint(_) => anyhow::bail!("checkpoint app state isn't supported"), + }; + content.stake_content.validators = self.validators.clone(); + AppState::Content(content) + }; // - serialize to json and then call `with_app_state_bytes` let app_state = serde_json::to_vec(&app_state)?; Ok(self.app_state(app_state)) diff --git a/crates/test/mock-consensus/Cargo.toml b/crates/test/mock-consensus/Cargo.toml index 5bbdd37521..932aeb991f 100644 --- a/crates/test/mock-consensus/Cargo.toml +++ b/crates/test/mock-consensus/Cargo.toml @@ -10,6 +10,7 @@ license.workspace = true [dependencies] anyhow = { workspace = true } bytes = { workspace = true } +penumbra-proto = { workspace = true } serde_json = { workspace = true } tap = { workspace = true } tendermint = { workspace = true } diff --git a/crates/test/mock-consensus/src/builder.rs b/crates/test/mock-consensus/src/builder.rs index 7d90e11c1f..337d86b2ee 100644 --- a/crates/test/mock-consensus/src/builder.rs +++ b/crates/test/mock-consensus/src/builder.rs @@ -5,12 +5,13 @@ /// Most importantly, defines [`Builder::init_chain()`]. mod init_chain; -use {crate::TestNode, bytes::Bytes}; +use {crate::TestNode, bytes::Bytes, penumbra_proto::penumbra::core::component::stake::v1 as pb}; /// A buider, used to prepare and instantiate a new [`TestNode`]. #[derive(Default)] pub struct Builder { - app_state: Option, + pub app_state: Option, + pub validators: Vec, } impl TestNode<()> { @@ -21,12 +22,23 @@ impl TestNode<()> { } impl Builder { - // TODO: add other convenience methods for validator config? - /// Creates a single validator with a randomly generated key. pub fn single_validator(self) -> Self { - // this does not do anything yet - self + let validator = pb::Validator { + identity_key: Option::default(), + consensus_key: Vec::default(), + name: String::default(), + website: String::default(), + description: String::default(), + enabled: true, + funding_streams: Vec::default(), + sequence_number: 0, + governance_key: Option::default(), + }; + Self { + validators: vec![validator], + ..self + } } /// Sets the `app_state_bytes` to send the ABCI application upon chain initialization. diff --git a/crates/test/mock-consensus/src/builder/init_chain.rs b/crates/test/mock-consensus/src/builder/init_chain.rs index b60a7793fd..93bbc23e97 100644 --- a/crates/test/mock-consensus/src/builder/init_chain.rs +++ b/crates/test/mock-consensus/src/builder/init_chain.rs @@ -32,6 +32,7 @@ impl Builder { let Self { app_state: Some(app_state), + validators: _, } = self else { bail!("builder was not fully initialized")