-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests(app): 🔗 send InitChain request to test node
Co-Authored-By: Henry de Valence <[email protected]>
- Loading branch information
1 parent
cf57d1e
commit c85e3ea
Showing
13 changed files
with
238 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// TODO: see #3792. | ||
|
||
use crate::TestNode; | ||
|
||
struct _Builder<'e, C> { | ||
engine: &'e mut TestNode<C>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! [`Builder`] interfaces, for creating new [`TestNode`]s. | ||
/// [`Builder`] interfaces for chain initialization. | ||
/// | ||
/// Most importantly, defines [`Builder::init_chain()`]. | ||
mod init_chain; | ||
|
||
use crate::TestNode; | ||
|
||
/// A buider, used to prepare and instantiate a new [`TestNode`]. | ||
pub struct Builder; | ||
|
||
impl TestNode<()> { | ||
/// Returns a new [`Builder`]. | ||
pub fn builder() -> Builder { | ||
Builder | ||
} | ||
} | ||
|
||
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 | ||
} | ||
|
||
pub fn app_state(self, _: ()) -> Self { | ||
// this does not do anything yet | ||
self | ||
} | ||
|
||
pub fn app_state_bytes(self, _: Vec<u8>) -> Self { | ||
// this does not do anything yet | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use { | ||
super::*, | ||
anyhow::{anyhow, bail}, | ||
std::time, | ||
tap::TapFallible, | ||
tendermint::{ | ||
block, | ||
consensus::{ | ||
self, | ||
params::{AbciParams, ValidatorParams, VersionParams}, | ||
}, | ||
evidence, | ||
v0_37::abci::{ConsensusRequest, ConsensusResponse}, | ||
}, | ||
tower::{BoxError, Service, ServiceExt}, | ||
tracing::{debug, error}, | ||
}; | ||
|
||
impl Builder { | ||
/// Consumes this builder, using the provided consensus service. | ||
pub async fn init_chain<C>(self, mut consensus: C) -> Result<TestNode<C>, anyhow::Error> | ||
where | ||
C: Service<ConsensusRequest, Response = ConsensusResponse, Error = BoxError> | ||
+ Send | ||
+ Clone | ||
+ 'static, | ||
C::Future: Send + 'static, | ||
C::Error: Sized, | ||
{ | ||
use tendermint::v0_37::abci::response; | ||
|
||
let request = Self::init_chain_request(); | ||
let service = consensus | ||
.ready() | ||
.await | ||
.tap_err(|error| error!(?error, "failed waiting for consensus service")) | ||
.map_err(|_| anyhow!("failed waiting for consensus service"))?; | ||
|
||
let response::InitChain { app_hash, .. } = match service | ||
.call(request) | ||
.await | ||
.tap_ok(|resp| debug!(?resp, "received response from consensus service")) | ||
.tap_err(|error| error!(?error, "consensus service returned error")) | ||
.map_err(|_| anyhow!("consensus service returned error"))? | ||
{ | ||
ConsensusResponse::InitChain(resp) => resp, | ||
response => { | ||
error!(?response, "unexpected InitChain response"); | ||
bail!("unexpected InitChain response"); | ||
} | ||
}; | ||
|
||
Ok(TestNode { | ||
consensus, | ||
last_app_hash: app_hash.as_bytes().to_owned(), | ||
}) | ||
} | ||
|
||
fn init_chain_request() -> ConsensusRequest { | ||
use tendermint::v0_37::abci::request::InitChain; | ||
let consensus_params = Self::consensus_params(); | ||
let app_state_bytes = bytes::Bytes::new(); | ||
ConsensusRequest::InitChain(InitChain { | ||
time: tendermint::Time::now(), | ||
chain_id: "test".to_string(), // XXX const here? | ||
consensus_params, | ||
validators: vec![], | ||
app_state_bytes, | ||
initial_height: 1_u32.into(), | ||
}) | ||
} | ||
|
||
fn consensus_params() -> consensus::Params { | ||
consensus::Params { | ||
block: block::Size { | ||
max_bytes: 1, | ||
max_gas: 1, | ||
time_iota_ms: 1, | ||
}, | ||
evidence: evidence::Params { | ||
max_age_num_blocks: 1, | ||
max_age_duration: evidence::Duration(time::Duration::from_secs(1)), | ||
max_bytes: 1, | ||
}, | ||
validator: ValidatorParams { | ||
pub_key_types: vec![], | ||
}, | ||
version: Some(VersionParams { app: 1 }), | ||
abci: AbciParams { | ||
vote_extensions_enable_height: None, | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,19 @@ | ||
pub struct TestNode<S> { | ||
#[allow(dead_code)] | ||
abci_server: S, | ||
_last_app_hash: Vec<u8>, | ||
//! `penumbra-mock-consensus` is a library for testing consensus-driven applications. | ||
// | ||
// see penumbra-zone/penumbra#3588. | ||
|
||
mod block; | ||
mod builder; | ||
|
||
// TODO(kate): this is a temporary allowance while we set the test node up. | ||
#[allow(dead_code)] | ||
pub struct TestNode<C> { | ||
consensus: C, | ||
last_app_hash: Vec<u8>, | ||
} | ||
|
||
pub mod block { | ||
use crate::TestNode; | ||
|
||
struct _Builder<'e, C> { | ||
engine: &'e mut TestNode<C>, | ||
} | ||
} | ||
|
||
pub struct Builder; | ||
|
||
impl<A> TestNode<A> { | ||
pub fn builder() -> Builder { | ||
Builder | ||
} | ||
} | ||
|
||
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 { | ||
impl<C> TestNode<C> { | ||
pub fn next_block() -> tendermint::Block { | ||
todo!(); | ||
} | ||
|
||
pub fn app_state(self, _: ()) -> Self { | ||
todo!() | ||
} | ||
|
||
pub fn app_state_bytes(self, _: Vec<u8>) -> Self { | ||
todo!() | ||
} | ||
|
||
pub async fn init_chain<S>(self, abci_server: S) -> TestNode<S> { | ||
TestNode { | ||
abci_server, | ||
_last_app_hash: vec![], | ||
} | ||
} | ||
} |