-
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.
feat: 📝 implement cometstub crate (work-in-progress)
this commit introduces a new library, in `crates/test/`. this library contains a mock implementation of cometbft, for use in cargo integration tests. * this does NOT add the `penumbra-cometstub` crate to the list of crates included in the rust documentation in `deployments/scripts/rust-docs`. the `penumbra-tct-property-test` crate was also not included in that list at the time of writing. /!\ ------------------------------------------------------- /!\ /!\ NOTE: this is a rolling work-in-progress. /!\ /!\ this branch will be force-pushed frequently until it is /!\ /!\ ready for review. proceed accordingly! /!\ /!\ ------------------------------------------------------- /!\
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "penumbra-cometstub" | ||
version = "0.64.1" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
default = ["component", "std"] | ||
component = [ | ||
# "cnidarium", | ||
# "cnidarium-component", | ||
# "penumbra-proto/cnidarium", | ||
# "penumbra-chain/component", | ||
] | ||
std = ["ibc-types/std"] | ||
|
||
[dependencies] | ||
# Workspace dependencies | ||
|
||
# Penumbra dependencies | ||
ibc-proto = { version = "0.40.0", default-features = false } | ||
ibc-types = { version = "0.11.0", default-features = false } | ||
|
||
# Crates.io deps | ||
anyhow = "1" | ||
tendermint = "0.34.0" | ||
# tendermint-proto = "0.34.0" | ||
tendermint-light-client-verifier = "0.34.0" |
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,89 @@ | ||
use tendermint::{ | ||
abci::{request::BeginBlock, types::CommitInfo}, | ||
account, | ||
block::{Header, Height, Round}, | ||
chain, | ||
validator::Set, | ||
AppHash, Hash, Time, | ||
}; | ||
use tendermint_light_client_verifier::{ | ||
options::Options, | ||
types::{TrustedBlockState, UntrustedBlockState}, | ||
Verdict, Verifier, | ||
}; | ||
|
||
pub fn begin_block() -> BeginBlock { | ||
BeginBlock { | ||
hash: Hash::None, | ||
header: header(), | ||
last_commit_info: CommitInfo { | ||
round: Round::default(), | ||
votes: vec![], | ||
}, | ||
byzantine_validators: vec![], | ||
} | ||
} | ||
|
||
fn header() -> Header { | ||
use tendermint::block::header::Version; | ||
Header { | ||
version: Version { block: 0, app: 0 }, | ||
chain_id: chain::Id::try_from("test").unwrap(), | ||
height: Height::default(), | ||
time: Time::unix_epoch(), | ||
last_block_id: None, | ||
last_commit_hash: None, | ||
data_hash: None, | ||
validators_hash: validators().hash(), | ||
next_validators_hash: validators().hash(), | ||
consensus_hash: Hash::None, | ||
app_hash: app_hash(), | ||
last_results_hash: None, | ||
evidence_hash: None, | ||
proposer_address: account::Id::new([ | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
]), | ||
} | ||
} | ||
|
||
fn validators() -> Set { | ||
Set::new(vec![], None) | ||
} | ||
|
||
fn app_hash() -> AppHash { | ||
AppHash::try_from(vec![1, 2, 3]).unwrap() | ||
// AppHash::try_from is infallible, see: https://github.com/informalsystems/tendermint-rs/issues/1243 | ||
} | ||
|
||
pub struct TestVerifier; | ||
impl Verifier for TestVerifier { | ||
fn verify_update_header( | ||
&self, | ||
_untrusted: UntrustedBlockState<'_>, | ||
_trusted: TrustedBlockState<'_>, | ||
_options: &Options, | ||
_now: Time, | ||
) -> Verdict { | ||
todo!("<BarkBark as Verifier>::verify_update_header") | ||
} | ||
fn verify_misbehaviour_header( | ||
&self, | ||
_untrusted: UntrustedBlockState<'_>, | ||
_trusted: TrustedBlockState<'_>, | ||
_options: &Options, | ||
_now: Time, | ||
) -> Verdict { | ||
todo!("<BarkBark as Verifier>::verify_misbehaviour_header") | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
// use tendermint_light_client_verifier:: | ||
|
||
#[test] | ||
fn begin_block_works() { | ||
let _ = super::begin_block(); | ||
// next, parse this block via a light client | ||
} | ||
} |