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 11, 2024
1 parent 5adb302 commit 2f6b9e6
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
10 changes: 10 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
27 changes: 27 additions & 0 deletions crates/test/cometstub/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[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"
67 changes: 67 additions & 0 deletions crates/test/cometstub/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
use tendermint::{
abci::types::CommitInfo,
block::{Header, Round, Height},
Hash, Time,
};
use {
ibc_proto::{
google::protobuf::Any, ibc::core::client::v1::MsgCreateClient as RawMsgCreateClient,
},
ibc_types::{core::client::msgs::MsgCreateClient, DomainType},
tendermint::abci::request::BeginBlock,
};

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 }, //: Version,
chain_id: todo!(), //: chain::Id,
height: Height::default(), //: block::Height,
time: Time::unix_epoch(), //: Time,
last_block_id: None, //: Option<block::Id>,
last_commit_hash: None, //: Option<Hash>,
data_hash: None, //: Option<Hash>,
validators_hash: todo!(), //: Hash,
next_validators_hash: todo!(), //: Hash,
consensus_hash: todo!(), //: Hash,
app_hash: todo!(), //: AppHash,
last_results_hash: None, //: Option<Hash>,
evidence_hash: None, //: Option<Hash>,
proposer_address: todo!(), //: account::Id,
}
}

#[cfg(test)]
mod tests {
use {
super::*,
ibc_types::{core::client::msgs::MsgCreateClient, DomainType},
};

#[test]
fn begin_block_works() {
let msg = begin_block();
unimplemented!("generate a begin block message")
}
}

// TODO(katie): this sketch is loosely based upon test_create_and_update_light_client. i am not
// convinced this is the right direction quite yet. i see very little interaction with headers
// themselves, it feels vaguely like we should be generating abci messages instead?
//
// Any is another puzzle. how to make those?
//
// tendermint_proxy contains the logic to marshal a tendermint::Block into its
// protobuf representation. consider moving that, see the todo comment there.

0 comments on commit 2f6b9e6

Please sign in to comment.