Skip to content

Commit

Permalink
mock-consensus: 🌱 single genesis validator (work-in-progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
cratelyn committed Feb 27, 2024
1 parent 628a9b6 commit 5ad993b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions crates/core/app/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions crates/test/mock-consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
24 changes: 18 additions & 6 deletions crates/test/mock-consensus/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bytes>,
pub app_state: Option<Bytes>,
pub validators: Vec<pb::Validator>,
}

impl TestNode<()> {
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crates/test/mock-consensus/src/builder/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Builder {

let Self {
app_state: Some(app_state),
validators: _,
} = self
else {
bail!("builder was not fully initialized")
Expand Down

0 comments on commit 5ad993b

Please sign in to comment.