Skip to content

Commit

Permalink
feat: 📝 implement cometstub crate (work-in-progress)
Browse files Browse the repository at this point in the history
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
cratelyn committed Jan 12, 2024
1 parent 5adb302 commit ef1d9dd
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ members = [
"crates/bin/pclientd",
"crates/bin/pcli",
"crates/wasm",
"crates/test/cometstub",
"crates/test/tct-property-test",
"crates/misc/measure",
"crates/misc/tct-visualize",
Expand Down
29 changes: 29 additions & 0 deletions crates/test/cometstub/Cargo.toml
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"
89 changes: 89 additions & 0 deletions crates/test/cometstub/src/lib.rs
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
}
}

0 comments on commit ef1d9dd

Please sign in to comment.