Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBC integration test #4119

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
wip 2
tzemanovic committed Dec 23, 2024

Verified

This commit was signed with the committer’s verified signature.
binbin-li Binbin Li
commit 35c95efb8118dd4748883fbfad88eb570e87d2c1
1,306 changes: 1,121 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -118,9 +118,12 @@ fs_extra = "1.2.0"
futures = "0.3"
git2 = { version = "0.18.1", default-features = false }
# branch yuji/derive-arbitrary
ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", features = ["serde"] }
ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" }
ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", default-features = false }
# ibc = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", features = ["serde"] }
# ibc-derive = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd" }
# ibc-testkit = { git = "https://github.com/heliaxdev/cosmos-ibc-rs", rev = "38bd2a32f35117d4d9165a3c68c64ccd87ad56dd", default-features = false }
ibc = { path = "../ibc-rs/ibc", features = ["serde"] }
ibc-derive = { path = "../ibc-rs/ibc-derive" }
ibc-testkit = { path = "../ibc-rs/ibc-testkit", default-features = false }
ics23 = "0.12.0"
index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] }
indexmap = { git = "https://github.com/heliaxdev/indexmap", tag = "2.2.4-heliax-1", features = ["borsh-schema", "serde"] }
@@ -189,6 +192,7 @@ tendermint-config = "0.38.0"
tendermint-light-client = "0.38.0"
tendermint-proto = "0.38.0"
tendermint-rpc = {version = "0.38.0", default-features = false}
tendermint-testgen = "0.38.0"
test-log = {version = "0.2.14", default-features = false, features = ["trace"]}
tiny-bip39 = {git = "https://github.com/anoma/tiny-bip39.git", rev = "bf0f6d8713589b83af7a917366ec31f5275c0e57"}
tiny-hderive = {git = "https://github.com/heliaxdev/tiny-hderive.git", rev = "173ae03abed0cd25d88a5a13efac00af96b75b87"}
6 changes: 6 additions & 0 deletions crates/core/src/key/mod.rs
Original file line number Diff line number Diff line change
@@ -368,6 +368,12 @@ impl<PK: PublicKey> From<&PK> for PublicKeyHash {
}
}

impl From<PublicKeyHash> for [u8; address::HASH_LEN] {
fn from(PublicKeyHash(value): PublicKeyHash) -> Self {
value
}
}

/// Derive Tendermint raw hash from the public key
pub trait PublicKeyTmRawHash {
/// Derive Tendermint raw hash from the public key
5 changes: 3 additions & 2 deletions crates/ibc/src/context/client.rs
Original file line number Diff line number Diff line change
@@ -219,9 +219,10 @@ impl TryFrom<Vec<u8>> for AnyConsensusState {
type Error = ClientError;

fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
dbg!(&bytes);
Any::decode(&bytes[..])
.map_err(|e| ClientError::Other {
description: e.to_string(),
.map_err(|e: prost::DecodeError| ClientError::Other {
description: format!("decode AnyConsensusState {e}"),
})?
.try_into()
}
8 changes: 4 additions & 4 deletions crates/ibc/src/context/common.rs
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ pub trait IbcCommonContext: IbcStorageContext {
match self.storage().read_bytes(&key)? {
Some(value) => Any::decode(&value[..])
.map_err(|e| ClientError::Other {
description: e.to_string(),
description: format!("client_state {e}"),
})?
.try_into()
.map_err(ContextError::from),
@@ -77,7 +77,7 @@ pub trait IbcCommonContext: IbcStorageContext {
match self.storage().read_bytes(&key)? {
Some(value) => Any::decode(&value[..])
.map_err(|e| ClientError::Other {
description: e.to_string(),
description: format!("consensus_state {e}"),
})?
.try_into()
.map_err(ContextError::from),
@@ -120,7 +120,7 @@ pub trait IbcCommonContext: IbcStorageContext {
) -> Result<AnyConsensusState> {
Any::decode(&consensus_state[..])
.map_err(|e| ClientError::Other {
description: e.to_string(),
description: format!("decode_consensus_state_value {e}"),
})?
.try_into()
.map_err(ContextError::from)
@@ -138,7 +138,7 @@ pub trait IbcCommonContext: IbcStorageContext {
let key = Key::parse(key).expect("the key should be parsable");
let height = storage::consensus_height(&key).map_err(|e| {
ClientError::Other {
description: e.to_string(),
description: format!("consensus state heights: {e}"),
}
})?;
heights.push(height);
5 changes: 3 additions & 2 deletions crates/ibc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -737,14 +737,14 @@ where
// needed in actual txs to addresses whose VPs should be triggered
let verifiers = Rc::new(RefCell::new(BTreeSet::<Address>::new()));

let message = decode_message::<Transfer>(tx_data)?;
let message = decode_message::<Transfer>(tx_data).unwrap();
match message {
IbcMessage::Transfer(msg) => {
let token_transfer_ctx = TokenTransferContext::new(
self.ctx.inner.clone(),
verifiers.clone(),
);
self.insert_verifiers()?;
self.insert_verifiers().unwrap();
send_transfer_validate(
&self.ctx,
&token_transfer_ctx,
@@ -763,6 +763,7 @@ where
.map_err(Error::NftTransfer)
}
IbcMessage::Envelope(envelope) => {
dbg!(&envelope);
validate(&self.ctx, &self.router, *envelope)
.map_err(|e| Error::Context(Box::new(e)))
}
8 changes: 4 additions & 4 deletions crates/ibc/src/vp/mod.rs
Original file line number Diff line number Diff line change
@@ -163,16 +163,16 @@ where
.ok_or(VpError::NoTxData)?;

// Pseudo execution and compare them
self.validate_state(&tx_data, keys_changed)?;
self.validate_state(&tx_data, keys_changed).unwrap();

// Validate the state according to the given IBC message
self.validate_with_msg(&tx_data)?;
self.validate_with_msg(&tx_data).unwrap();

// Validate the denom store if a denom key has been changed
self.validate_trace(keys_changed)?;
self.validate_trace(keys_changed).unwrap();

// Check the limits
self.check_limits(keys_changed)?;
self.check_limits(keys_changed).unwrap();

Ok(())
}
345 changes: 291 additions & 54 deletions crates/node/src/shell/testing/node.rs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -74,11 +74,14 @@ expectrl.workspace = true
eyre.workspace = true
flate2.workspace = true
fs_extra.workspace = true
# hermes = { git = "https://github.com/heliaxdev/hermes", package = "ibc-relayer-cli", branch = "namada-0.45" }
hermes = { path = "../../../hermes/crates/relayer-cli", package = "ibc-relayer-cli" }
once_cell.workspace = true
proptest-state-machine.workspace = true
rand.workspace = true
tar.workspace = true
tendermint-light-client.workspace = true
tendermint-testgen.workspace = true
test-log.workspace = true
toml.workspace = true

2 changes: 1 addition & 1 deletion crates/tests/src/integration.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod helpers;
mod ibc;
mod ledger_tests;
mod masp;
mod setup;
mod ibc;