Skip to content

Commit

Permalink
Mock IBC Test: Handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
zbuc committed Aug 15, 2024
1 parent 56cb002 commit 092a386
Show file tree
Hide file tree
Showing 43 changed files with 1,561 additions and 130 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ const EPOCH_DURATION: u64 = 8;
async fn app_can_define_and_delegate_to_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_deposit_into_community_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -28,7 +29,7 @@ mod common;
async fn app_can_deposit_into_community_pool() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define our application state, and start the test node.
let mut test_node = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_disable_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::ValidatorDataReadExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::VerificationKey,
penumbra_app::{
genesis::{AppState, Content},
Expand Down Expand Up @@ -49,7 +50,7 @@ const PROPOSAL_VOTING_BLOCKS: u64 = 3;
async fn app_can_propose_community_pool_spends() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Define a helper to get the current community pool balance.
let pool_balance = || async { storage.latest_snapshot().community_pool_balance().await };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -27,7 +28,7 @@ mod common;
async fn app_can_spend_notes_and_detect_outputs() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let mut test_node = {
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{AppState, Content},
server::consensus::Consensus,
Expand Down Expand Up @@ -37,7 +38,7 @@ const COUNT: usize = SWEEP_COUNT + 1;
async fn app_can_sweep_a_collection_of_small_notes() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber_with_env_filter("info".into());
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Instantiate a mock tendermint proxy, which we will connect to the test node.
let proxy = penumbra_mock_tendermint_proxy::TestNodeProxy::new::<Consensus>();
Expand Down
3 changes: 2 additions & 1 deletion crates/core/app/tests/app_can_undelegate_from_a_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_fmd::Precision,
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -37,7 +38,7 @@ const UNBONDING_DELAY: u64 = 4;
async fn app_can_undelegate_from_a_validator() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Helper function to get the latest block height.
let get_latest_height = || async {
Expand Down
5 changes: 4 additions & 1 deletion crates/core/app/tests/app_check_dex_vcb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use std::{ops::Deref, sync::Arc};
/// This bug was fixed in #4643.
async fn dex_vcb_tracks_multiswap() -> anyhow::Result<()> {
let mut rng = rand_chacha::ChaChaRng::seed_from_u64(1776);
let storage = TempStorage::new().await?.apply_default_genesis().await?;
let storage = TempStorage::new_with_penumbra_prefixes()
.await?
.apply_default_genesis()
.await?;
let mut state = Arc::new(StateDelta::new(storage.latest_snapshot()));

// Create the first swap:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand All @@ -23,7 +24,7 @@ mod common;
async fn app_rejects_validator_definitions_with_invalid_auth_sigs() -> anyhow::Result<()> {
// Install a test logger, and acquire some temporary storage.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/app/tests/app_reproduce_testnet_75_vcb_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ use {
self::common::BuilderExt,
anyhow::anyhow,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
},
penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID},
penumbra_auction::StateReadExt as _,
penumbra_auction::{
auction::{
dutch::{ActionDutchAuctionEnd, ActionDutchAuctionSchedule, DutchAuctionDescription},
AuctionNft,
},
component::AuctionStoreRead,
StateReadExt as _,
},
penumbra_keys::test_keys,
penumbra_mock_client::MockClient,
Expand Down Expand Up @@ -65,7 +66,7 @@ async fn app_can_reproduce_tesnet_75_vcb_close() -> anyhow::Result<()> {

common::set_tracing_subscriber_with_env_filter(filter)
};
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;
let app_state = AppState::Content(
genesis::Content::default().with_chain_id(TestNode::<()>::CHAIN_ID.to_string()),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down Expand Up @@ -60,7 +61,7 @@ async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Res
let height = 4;
for i in 1..=height {
node.block()
.with_signatures(Default::default())
.without_signatures()
.execute()
.tap(|_| trace!(%i, "executing block with no signatures"))
.instrument(error_span!("executing block with no signatures", %i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use {
self::common::{BuilderExt, ValidatorDataReadExt},
anyhow::Context,
cnidarium::TempStorage,
common::TempStorageExt as _,
penumbra_app::{
genesis::{self, AppState},
server::consensus::Consensus,
Expand All @@ -18,7 +19,7 @@ mod common;
async fn app_tracks_uptime_for_genesis_validator_missing_blocks() -> anyhow::Result<()> {
// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Start the test node.
let mut node = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use {
self::common::{BuilderExt, TestNodeExt, ValidatorDataReadExt},
cnidarium::TempStorage,
common::TempStorageExt as _,
decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey},
penumbra_app::{
genesis::{self, AppState},
Expand Down Expand Up @@ -32,7 +33,7 @@ async fn app_tracks_uptime_for_validators_only_once_active() -> anyhow::Result<(

// Install a test logger, acquire some temporary storage, and start the test node.
let guard = common::set_tracing_subscriber();
let storage = TempStorage::new().await?;
let storage = TempStorage::new_with_penumbra_prefixes().await?;

// Configure an AppState with slightly shorter epochs than usual.
let app_state = AppState::Content(
Expand Down
136 changes: 136 additions & 0 deletions crates/core/app/tests/common/ibc_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
use {
anyhow::{anyhow, Result},
ibc_types::{
core::client::Height,
lightclients::tendermint::{
consensus_state::ConsensusState, header::Header as TendermintHeader,
},
},
};

mod relayer;
#[allow(unused_imports)]
pub use relayer::MockRelayer;

mod node;
pub use node::TestNodeWithIBC;

// TODO: this needs to move somewhere else
#[allow(dead_code)]
pub fn create_tendermint_header(
pk: &ed25519_consensus::VerificationKey,
prev_counterparty_consensus_state: Option<(Height, ConsensusState)>,
penumbra_proto::util::tendermint_proxy::v1::GetBlockByHeightResponse{block_id: _, block}: penumbra_proto::util::tendermint_proxy::v1::GetBlockByHeightResponse,
) -> Result<TendermintHeader> {
let block = block.ok_or(anyhow!("no block"))?;
let header = block.header.ok_or(anyhow!("no header"))?;

// the tendermint SignedHeader is non_exhaustive so we
// can't use struct syntax to instantiate it and have to do
// some annoying manual construction of the pb type instead.
let h: tendermint::block::Header = header.clone().try_into().expect("bad header");
use tendermint_proto::v0_37::types::SignedHeader as RawSignedHeader;
let rsh: RawSignedHeader = RawSignedHeader {
header: Some(tendermint_proto::v0_37::types::Header {
version: Some(tendermint_proto::v0_37::version::Consensus {
block: header.version.as_ref().expect("version").block,
app: header.version.expect("version").app,
}),
chain_id: header.chain_id,
height: header.height.into(),
time: Some(tendermint_proto::google::protobuf::Timestamp {
seconds: header.time.as_ref().expect("time").seconds,
nanos: header.time.expect("time").nanos,
}),
last_block_id: header.last_block_id.clone().map(|a| {
tendermint_proto::v0_37::types::BlockId {
hash: a.hash,
part_set_header: a.part_set_header.map(|b| {
tendermint_proto::v0_37::types::PartSetHeader {
total: b.total,
hash: b.hash,
}
}),
}
}),
last_commit_hash: header.last_commit_hash.into(),
data_hash: header.data_hash.into(),
validators_hash: header.validators_hash.into(),
next_validators_hash: header.next_validators_hash.into(),
consensus_hash: header.consensus_hash.into(),
app_hash: header.app_hash.into(),
last_results_hash: header.last_results_hash.into(),
evidence_hash: header.evidence_hash.into(),
proposer_address: header.proposer_address.into(),
}),
commit: Some(tendermint_proto::v0_37::types::Commit {
// The commit is for the current height
height: header.height.into(),
round: 0.into(),
block_id: Some(tendermint_proto::v0_37::types::BlockId {
hash: h.hash().into(),
part_set_header: Some(tendermint_proto::v0_37::types::PartSetHeader {
total: 0,
hash: vec![],
}),
}),
signatures: block
.last_commit
.map(|lc| {
lc.signatures
.iter()
.map(|a| tendermint_proto::v0_37::types::CommitSig {
block_id_flag: a.block_id_flag,
validator_address: a.validator_address.clone(),
timestamp: Some(tendermint_proto::google::protobuf::Timestamp {
seconds: a.timestamp.as_ref().expect("time").seconds,
nanos: a.timestamp.clone().expect("time").nanos,
}),
signature: a.signature.clone(),
})
.collect()
})
.unwrap(),
}),
};

let signed_header = rsh.clone().try_into()?;

// now get a SignedHeader
let pub_key = tendermint::PublicKey::from_raw_ed25519(pk.as_bytes()).expect("pub key present");
let proposer_address = tendermint::account::Id::new(
<sha2::Sha256 as sha2::Digest>::digest(pk).as_slice()[0..20]
.try_into()
.expect(""),
);
let validator_set = tendermint::validator::Set::new(
vec![tendermint::validator::Info {
address: proposer_address.try_into()?,
pub_key,
power: 1i64.try_into()?,
name: Some("test validator".to_string()),
proposer_priority: 1i64.try_into()?,
}],
// Same validator as proposer?
Some(tendermint::validator::Info {
address: proposer_address.try_into()?,
pub_key,
power: 1i64.try_into()?,
name: Some("test validator".to_string()),
proposer_priority: 1i64.try_into()?,
}),
);

// now we can make the Header
Ok(TendermintHeader {
signed_header,
validator_set: validator_set.clone(),
trusted_validator_set: validator_set.clone(),
trusted_height: prev_counterparty_consensus_state
.map(|cs| cs.0)
.unwrap_or_else(|| ibc_types::core::client::Height {
revision_number: 0,
revision_height: 1,
}),
})
}
Loading

0 comments on commit 092a386

Please sign in to comment.