Skip to content

Commit

Permalink
fixup! Merge branch 'yuji/ibc-masp-recv' (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Mar 19, 2024
1 parent 9764470 commit dcc930e
Showing 1 changed file with 31 additions and 51 deletions.
82 changes: 31 additions & 51 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
&channel_id_a,
None,
None,
None,
false,
)?;
wait_for_packet_relay(&port_id_a, &channel_id_a, &test_a)?;
Expand Down Expand Up @@ -241,6 +242,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
&channel_id_b,
None,
None,
None,
false,
)?;
wait_for_packet_relay(&port_id_a, &channel_id_a, &test_a)?;
Expand All @@ -259,6 +261,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
None,
Some(Duration::new(0, 0)),
None,
false,
Expand Down Expand Up @@ -290,6 +293,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
&channel_id_a,
None,
None,
None,
false,
)?;
wait_for_packet_relay(&port_id_a, &channel_id_a, &test_a)?;
Expand All @@ -307,6 +311,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
&channel_id_a,
None,
None,
None,
false,
)?;
wait_for_packet_relay(&port_id_a, &channel_id_a, &test_a)?;
Expand All @@ -327,6 +332,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
ALBERT_KEY,
&port_id_a,
&channel_id_a,
None,
Some(Duration::new(10, 0)),
None,
false,
Expand Down Expand Up @@ -1238,6 +1244,7 @@ fn transfer_token(
channel_id_a,
None,
None,
None,
false,
)?;
let events = get_events(test_a, height)?;
Expand Down Expand Up @@ -1316,6 +1323,7 @@ fn try_invalid_transfers(
port_id_a,
channel_id_a,
None,
None,
Some("The amount for the IBC transfer should be an integer"),
false,
)?;
Expand All @@ -1332,6 +1340,7 @@ fn try_invalid_transfers(
&"port".parse().unwrap(),
channel_id_a,
None,
None,
// the IBC denom can't be parsed when using an invalid port
Some(&format!("Invalid IBC denom: {nam_addr}")),
false,
Expand All @@ -1348,6 +1357,7 @@ fn try_invalid_transfers(
port_id_a,
&"channel-42".parse().unwrap(),
None,
None,
Some("Error trying to apply a transaction"),
false,
)?;
Expand Down Expand Up @@ -1413,6 +1423,7 @@ fn transfer_back(
channel_id_b,
None,
None,
None,
false,
)?;
let events = get_events(test_b, height)?;
Expand Down Expand Up @@ -1484,6 +1495,7 @@ fn transfer_timeout(
ALBERT_KEY,
port_id_a,
channel_id_a,
None,
Some(Duration::new(5, 0)),
None,
false,
Expand All @@ -1507,7 +1519,13 @@ fn transfer_timeout(
// Update the client state of Chain B on Chain A
update_client_with_height(test_b, test_a, client_id_a, height_b)?;
// Timeout on Chain A
submit_ibc_tx(test_a, msg.to_any(), ALBERT, ALBERT_KEY, false)?;
submit_ibc_tx(
test_a,
make_ibc_data(msg.to_any()),
ALBERT,
ALBERT_KEY,
false,
)?;

Ok(())
}
Expand Down Expand Up @@ -1545,56 +1563,11 @@ fn gen_ibc_shielded_transfer(
Ok(file_path)
}

#[allow(clippy::too_many_arguments)]
fn shielded_transfer(
test_a: &Test,
test_b: &Test,
client_id_a: &ClientId,
client_id_b: &ClientId,
port_id_a: &PortId,
channel_id_a: &ChannelId,
port_id_b: &PortId,
channel_id_b: &ChannelId,
) -> Result<()> {
// Get masp proof for the following IBC transfer from the destination chain
// It will send 10 BTC from Chain A to PA(B) on Chain B
// PA(B) on Chain B will receive BTC on chain A
std::env::set_var(ENV_VAR_CHAIN_ID, test_a.net.chain_id.to_string());
let token_addr = find_address(test_a, BTC)?;
let file_path = gen_ibc_shielded_transfer(
test_b,
AB_PAYMENT_ADDRESS,
token_addr.to_string(),
10,
port_id_b,
channel_id_b,
)?;

// Send a token to the shielded address on Chain A
transfer_on_chain(test_a, ALBERT, AA_PAYMENT_ADDRESS, BTC, 10, ALBERT_KEY)?;
let rpc = get_actor_rpc(test_a, Who::Validator(0));
let tx_args = vec![
"shielded-sync",
"--viewing-keys",
AA_VIEWING_KEY,
"--node",
&rpc,
];
let mut client = run!(test_a, Bin::Client, tx_args, Some(120))?;
client.assert_success();

// Send a token from SP(A) on Chain A to PA(B) on Chain B
let amount = Amount::native_whole(10).to_string_native();
let height = transfer(
submit_ibc_tx(
test_a,
make_ibc_data(msg.to_any()),
ALBERT,
ALBERT_KEY,
false,
)?;

Ok(())
fn get_shielded_transfer_path(client: &mut NamadaCmd) -> Result<PathBuf> {
let (_unread, matched) =
client.exp_regex("Output IBC shielded transfer .*")?;
let file_path = matched.trim().split(' ').last().expect("invalid output");
Ok(PathBuf::from_str(file_path).expect("invalid file path"))
}

fn get_commitment_proof(
Expand Down Expand Up @@ -1697,6 +1670,7 @@ fn transfer(
signer: impl AsRef<str>,
port_id: &PortId,
channel_id: &ChannelId,
memo: Option<&str>,
timeout_sec: Option<Duration>,
expected_err: Option<&str>,
wait_reveal_pk: bool,
Expand Down Expand Up @@ -1726,6 +1700,12 @@ fn transfer(
&rpc,
];

let memo_path = memo.unwrap_or_default();
if memo.is_some() {
tx_args.push("--memo-path");
tx_args.push(memo_path);
}

let timeout = timeout_sec.unwrap_or_default().as_secs().to_string();
if timeout_sec.is_some() {
tx_args.push("--timeout-sec-offset");
Expand Down

0 comments on commit dcc930e

Please sign in to comment.