Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Jun 21, 2024
1 parent fb19c25 commit 210f34b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 88 deletions.
55 changes: 3 additions & 52 deletions crates/sdk/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use namada_governance::utils::{
use namada_ibc::storage::{
ibc_trace_key, ibc_trace_key_prefix, is_ibc_trace_key,
};
use namada_ibc::trace::is_ibc_denom;
use namada_parameters::{storage as params_storage, EpochDuration};
use namada_proof_of_stake::parameters::PosParams;
use namada_proof_of_stake::types::{
Expand Down Expand Up @@ -1167,25 +1166,9 @@ pub async fn validate_amount<N: Namada>(
InputAmount::Unvalidated(amt) => amt.canonical(),
InputAmount::Validated(amt) => return Ok(amt),
};
let base_token =
if let Address::Internal(InternalAddress::IbcToken(ibc_token_hash)) =
token
{
extract_base_token(context, ibc_token_hash.clone(), None).await
} else {
Some(token.clone())
};
let denom = if let Some(token) = base_token {
convert_response::<N::Client, Option<Denomination>>(
RPC.vp()
.token()
.denomination(context.client(), &token)
.await,
)?
} else {
None
};
let denom = match denom {
let denom = match convert_response::<N::Client, Option<Denomination>>(
RPC.vp().token().denomination(context.client(), token).await,
)? {
Some(denom) => Ok(denom),
None => {
if force {
Expand Down Expand Up @@ -1371,38 +1354,6 @@ pub async fn query_ibc_tokens<N: Namada>(
Ok(tokens)
}

/// Obtain the base token of the given IBC token hash
pub async fn extract_base_token<N: Namada>(
context: &N,
ibc_token_hash: IbcTokenHash,
owner: Option<&Address>,
) -> Option<Address> {
// First obtain the IBC denomination
let ibc_denom = query_ibc_denom(
context,
Address::Internal(InternalAddress::IbcToken(ibc_token_hash))
.to_string(),
owner,
)
.await;
// Then try to extract the base token
if let Some((_trace_path, base_token)) = is_ibc_denom(ibc_denom) {
match Address::decode(&base_token) {
// If the base token successfully decoded into an Address
Ok(base_token) => Some(base_token),
// Otherwise find the Address associated with the base token's alias
Err(_) => context
.wallet()
.await
.find_address(&base_token)
.map(|x| x.into_owned()),
}
} else {
// Otherwise the base token Address is unknown to this client
None
}
}

/// Look up the IBC denomination from a IbcToken.
pub async fn query_ibc_denom<N: Namada>(
context: &N,
Expand Down
41 changes: 5 additions & 36 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ fn run_ledger_ibc() -> Result<()> {
token,
50000,
BERTHA_KEY,
true,
)?;
check_balances_after_non_ibc(&port_id_b, &channel_id_b, &test_b)?;

Expand Down Expand Up @@ -234,7 +233,6 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand All @@ -250,9 +248,8 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
BERTHA,
ALBERT,
token,
50000,
50_000_000_000,
BERTHA_KEY,
true,
)?;
check_balances_after_non_ibc(&port_id_b, &channel_id_b, &test_b)?;

Expand All @@ -268,11 +265,10 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
BERTHA,
receiver.to_string(),
ibc_denom,
50000.0,
50_000_000_000.0,
BERTHA_KEY,
&port_id_b,
&channel_id_b,
true,
None,
None,
false,
Expand All @@ -289,7 +285,6 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
BTC,
100,
ALBERT_KEY,
false,
)?;
shielded_sync(&test_a, AA_VIEWING_KEY)?;
// Shieded transfer from Chain A to Chain B
Expand All @@ -302,7 +297,6 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand All @@ -320,7 +314,6 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand All @@ -343,7 +336,6 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
Some(Duration::new(10, 0)),
None,
false,
Expand Down Expand Up @@ -409,7 +401,6 @@ fn ibc_namada_gaia() -> Result<()> {
ALBERT_KEY,
&port_id_namada,
&channel_id_namada,
false,
None,
None,
false,
Expand Down Expand Up @@ -465,7 +456,6 @@ fn ibc_namada_gaia() -> Result<()> {
ALBERT_KEY,
&port_id_namada,
&channel_id_namada,
true,
None,
None,
false,
Expand Down Expand Up @@ -499,7 +489,6 @@ fn ibc_namada_gaia() -> Result<()> {
&ibc_denom,
50,
ALBERT_KEY,
true,
)?;
check_balance(&test, AA_VIEWING_KEY, &ibc_denom, 50)?;
check_balance(&test, AB_VIEWING_KEY, &ibc_denom, 50)?;
Expand All @@ -514,7 +503,6 @@ fn ibc_namada_gaia() -> Result<()> {
BERTHA_KEY,
&port_id_namada,
&channel_id_namada,
true,
None,
None,
false,
Expand Down Expand Up @@ -572,7 +560,6 @@ fn pgf_over_ibc_with_hermes() -> Result<()> {
NAM,
100,
ALBERT_KEY,
false,
)?;

// Proposal on Chain A
Expand Down Expand Up @@ -676,7 +663,6 @@ fn proposal_ibc_token_inflation() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand Down Expand Up @@ -744,7 +730,6 @@ fn ibc_rate_limit() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand All @@ -760,7 +745,6 @@ fn ibc_rate_limit() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
// expect an error of the throughput limit
Some(
Expand All @@ -787,7 +771,6 @@ fn ibc_rate_limit() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
None,
None,
false,
Expand All @@ -812,7 +795,6 @@ fn ibc_rate_limit() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
false,
Some(Duration::new(20, 0)),
None,
false,
Expand Down Expand Up @@ -1579,7 +1561,6 @@ fn transfer_token(
ALBERT_KEY,
port_id_a,
channel_id_a,
false,
None,
None,
false,
Expand Down Expand Up @@ -1657,7 +1638,6 @@ fn try_invalid_transfers(
ALBERT_KEY,
&"port".parse().unwrap(),
channel_id_a,
false,
None,
// the IBC denom can't be parsed when using an invalid port
Some(&format!("Invalid IBC denom: {nam_addr}")),
Expand All @@ -1674,7 +1654,6 @@ fn try_invalid_transfers(
ALBERT_KEY,
port_id_a,
&"channel-42".parse().unwrap(),
false,
None,
Some("IBC token transfer error: context error: `ICS04 Channel error"),
false,
Expand All @@ -1692,12 +1671,11 @@ fn transfer_on_chain(
token: impl AsRef<str>,
amount: u64,
signer: impl AsRef<str>,
force: bool,
) -> Result<()> {
std::env::set_var(ENV_VAR_CHAIN_ID, test.net.chain_id.to_string());
let rpc = get_actor_rpc(test, Who::Validator(0));
let amount = amount.to_string();
let mut tx_args = vec![
let tx_args = vec![
kind.as_ref(),
"--source",
sender.as_ref(),
Expand All @@ -1712,9 +1690,6 @@ fn transfer_on_chain(
"--node",
&rpc,
];
if force {
tx_args.push("--force");
}
let mut client = run!(test, Bin::Client, tx_args, Some(120))?;
client.exp_string(TX_APPLIED_SUCCESS)?;
client.assert_success();
Expand Down Expand Up @@ -1742,11 +1717,10 @@ fn transfer_back(
BERTHA,
receiver.to_string(),
ibc_denom,
50000.0,
50_000_000_000.0,
BERTHA_KEY,
port_id_b,
channel_id_b,
true,
None,
None,
false,
Expand Down Expand Up @@ -1820,7 +1794,6 @@ fn transfer_timeout(
ALBERT_KEY,
port_id_a,
channel_id_a,
false,
Some(Duration::new(5, 0)),
None,
false,
Expand Down Expand Up @@ -1955,7 +1928,6 @@ fn transfer(
signer: impl AsRef<str>,
port_id: &PortId,
channel_id: &ChannelId,
force: bool,
timeout_sec: Option<Duration>,
expected_err: Option<&str>,
wait_reveal_pk: bool,
Expand Down Expand Up @@ -1985,9 +1957,6 @@ fn transfer(
"--node",
&rpc,
];
if force {
tx_args.push("--force");
}

let timeout = timeout_sec.unwrap_or_default().as_secs().to_string();
if timeout_sec.is_some() {
Expand Down Expand Up @@ -2479,7 +2448,7 @@ fn check_shielded_balances(

// Check the shielded balance on Chain B
let ibc_denom = format!("{dest_port_id}/{dest_channel_id}/btc");
check_balance(test_b, AB_VIEWING_KEY, ibc_denom, 10)?;
check_balance(test_b, AB_VIEWING_KEY, ibc_denom, 1_000_000_000)?;

Ok(())
}
Expand Down

0 comments on commit 210f34b

Please sign in to comment.