Skip to content

Commit

Permalink
fix tests between gaia and namada
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Jul 9, 2024
1 parent 6899c72 commit 337f4dc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
2 changes: 1 addition & 1 deletion tools/integration-test/src/tests/client_expiration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl BinaryChainTest for ChannelExpirationTest {
},
// From simapp version v7.1.0 if `ConnOpenInit` is sent while the client
// is expired, an error will be returned.
Err(e) => match chains.node_a.chain_driver().value().chain_type {
Err(e) => match chains.node_b.chain_driver().value().chain_type {
ChainType::Namada => {
// See https://github.com/cosmos/ibc-rs/blob/v0.53.0/ibc-core/ics02-client/types/src/error.rs#L22
assert!(e.to_string().contains("client is not active. Status=`Expired`"))
Expand Down
39 changes: 28 additions & 11 deletions tools/integration-test/src/tests/tendermint/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::time::Instant;
use ibc_relayer::chain::tracking::TrackedMsgs;
use ibc_relayer::config::types::max_msg_num::MaxMsgNum;
use ibc_relayer::config::ChainConfig;
use ibc_test_framework::chain::chain_type::ChainType;
use ibc_test_framework::chain::config;
use ibc_test_framework::prelude::*;
use ibc_test_framework::relayer::transfer::build_transfer_message;
Expand Down Expand Up @@ -104,16 +105,28 @@ impl BinaryChannelTest for SequentialCommitTest {
TOTAL_MESSAGES, duration
);

// Time taken for submitting sequential batches should be around number of transactions * block time

assert!(
duration
> Duration::from_millis((BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) - 1000)
);
assert!(
duration
< Duration::from_millis((BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) + 1000)
);
let (min_duration, max_duration) = match chains.node_a.chain_driver().value().chain_type
{
ChainType::Namada => (
Duration::from_millis((BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) - 1000),
Duration::from_millis(
(BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) * 2 + 1000,
),
),
_ => {
// Time taken for submitting sequential batches should be around number of transactions * block time
(
Duration::from_millis(
(BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) - 1000,
),
Duration::from_millis(
(BLOCK_TIME_MILLIS * TOTAL_TRANSACTIONS as u64) + 1000,
),
)
}
};
assert!(duration > min_duration);
assert!(duration < max_duration);
}

{
Expand Down Expand Up @@ -150,7 +163,11 @@ impl BinaryChannelTest for SequentialCommitTest {
TOTAL_MESSAGES, duration
);

assert!(duration < Duration::from_millis(BLOCK_TIME_MILLIS * 3));
let max_duration = match chains.node_b.chain_driver().value().chain_type {
ChainType::Namada => Duration::from_millis(BLOCK_TIME_MILLIS * 2 * 2),
_ => Duration::from_millis(BLOCK_TIME_MILLIS * 2),
};
assert!(duration < max_duration);
}

Ok(())
Expand Down
40 changes: 31 additions & 9 deletions tools/test-framework/src/ibc/denom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub enum Denom {
Base {
display_name: String,
raw_address: String,
token_denom: u8,
},
Ibc {
path: String,
Expand Down Expand Up @@ -94,25 +95,34 @@ fn derive_cosmos_ibc_denom<ChainA, ChainB>(
}

match denom.value() {
Denom::Base { raw_address, .. } => {
Denom::Base {
raw_address,
token_denom,
..
} => {
let hashed = derive_denom(port_id.value(), channel_id.value(), raw_address)?;

Ok(MonoTagged::new(Denom::Ibc {
path: format!("{port_id}/{channel_id}"),
denom: Box::new((*denom.value()).clone()),
hashed,
token_denom: 0,
token_denom: *token_denom,
}))
}
Denom::Ibc { path, denom, .. } => {
Denom::Ibc {
path,
denom,
token_denom,
..
} => {
let new_path = format!("{port_id}/{channel_id}/{path}");
let hashed = derive_denom_with_path(&format!("{new_path}/{denom}"))?;

Ok(MonoTagged::new(Denom::Ibc {
path: new_path,
denom: denom.clone(),
hashed,
token_denom: 0,
token_denom: *token_denom,
}))
}
}
Expand All @@ -124,18 +134,27 @@ fn derive_namada_ibc_denom<ChainA, ChainB>(
denom: &TaggedDenomRef<ChainA>,
) -> Result<TaggedDenom<ChainB>, Error> {
match denom.value() {
Denom::Base { raw_address, .. } => {
Denom::Base {
raw_address,
token_denom,
..
} => {
let path = format!("{port_id}/{channel_id}");
let ibc_token_addr = namada_ibc::trace::ibc_token(format!("{path}/{raw_address}"));

Ok(MonoTagged::new(Denom::Ibc {
path,
denom: Box::new((*denom.value()).clone()),
hashed: ibc_token_addr.to_string(),
token_denom: 6,
token_denom: *token_denom,
}))
}
Denom::Ibc { path, denom, .. } => {
Denom::Ibc {
path,
denom,
token_denom,
..
} => {
let new_path = format!("{port_id}/{channel_id}/{path}");
let ibc_token_addr =
namada_ibc::trace::ibc_token(format!("{new_path}/{}", denom.hash_only()));
Expand All @@ -144,7 +163,7 @@ fn derive_namada_ibc_denom<ChainA, ChainB>(
path: new_path,
denom: denom.clone(),
hashed: ibc_token_addr.to_string(),
token_denom: 6,
token_denom: *token_denom,
}))
}
}
Expand All @@ -155,6 +174,7 @@ impl Denom {
Denom::Base {
display_name: display_name.to_owned(),
raw_address: raw_address.to_owned(),
token_denom: if display_name == "nam" { 6 } else { 0 },
}
}

Expand Down Expand Up @@ -210,12 +230,14 @@ impl PartialEq for Denom {
Self::Base {
display_name: d1,
raw_address: a1,
token_denom: td1,
},
Self::Base {
display_name: d2,
raw_address: a2,
token_denom: td2,
},
) => (d1 == d2) && (a1 == a2),
) => (d1 == d2) && (a1 == a2) && (td1 == td2),
(
Self::Ibc {
path: p1,
Expand Down

0 comments on commit 337f4dc

Please sign in to comment.