Skip to content

Commit

Permalink
Added an unhappy flow e2e test for the ibc shielded-recv middleware. …
Browse files Browse the repository at this point in the history
…Added new e2e test to ci jobs
  • Loading branch information
batconjurer authored and sug0 committed Dec 18, 2024
1 parent a641272 commit ac598c3
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"e2e::ibc_tests::ibc_pfm_happy_flows": 485,
"e2e::ibc_tests::ibc_pfm_unhappy_flows": 485,
"e2e::ibc_tests::ibc_upgrade_client": 280,
"e2e::ibc_tests::ibc_shielded_recv_middleware_happy_flow": 280,
"e2e::ibc_tests::ibc_shielded_recv_middleware_unhappy_flow": 280,
"e2e::eth_bridge_tests::test_add_to_bridge_pool": 10,
"e2e::ledger_tests::double_signing_gets_slashed": 12,
"e2e::ledger_tests::ledger_many_txs_in_a_block": 55,
Expand Down
88 changes: 87 additions & 1 deletion crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ fn ibc_pfm_unhappy_flows() -> Result<()> {
Ok(())
}

/// Test that we are able to use the shielded receive
/// Test that we are able to use the shielded-receive
/// middleware to shield funds specified in the memo
/// message.
#[test]
Expand Down Expand Up @@ -2027,12 +2027,98 @@ fn ibc_shielded_recv_middleware_happy_flow() -> Result<()> {
wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?;

// Check the token on Namada
check_balance(&test, AA_VIEWING_KEY, NAM, 0)?;
check_balance(&test, AB_VIEWING_KEY, NAM, 8)?;
check_balance(&test, overflow_addr, NAM, 2)?;

Ok(())
}

/// Test that if the received amount underflows the minimum
/// amount, we error out and refund assets.
#[test]
fn ibc_shielded_recv_middleware_unhappy_flow() -> Result<()> {
let update_genesis =
|mut genesis: templates::All<templates::Unvalidated>, base_dir: &_| {
genesis.parameters.parameters.epochs_per_year =
epochs_per_year_from_min_duration(1800);
genesis.parameters.ibc_params.default_mint_limit =
Amount::max_signed();
genesis
.parameters
.ibc_params
.default_per_epoch_throughput_limit = Amount::max_signed();
setup::set_validators(1, genesis, base_dir, |_| 0, vec![])
};
let (ledger, gaia, test, test_gaia) =
run_namada_cosmos(CosmosChainType::Gaia(None), update_genesis)?;
let _bg_ledger = ledger.background();
let _bg_gaia = gaia.background();
sleep(5);

let hermes_dir = setup_hermes(&test, &test_gaia)?;
let port_id_namada = FT_PORT_ID.parse().unwrap();
let port_id_gaia = FT_PORT_ID.parse().unwrap();
let (channel_id_namada, channel_id_gaia) = create_channel_with_hermes(
&hermes_dir,
&test,
&test_gaia,
&port_id_namada,
&port_id_gaia,
)?;

// Start relaying
let hermes = run_hermes(&hermes_dir)?;
let _bg_hermes = hermes.background();

let nam_addr = find_address(&test, NAM)?;
let overflow_addr = "tnam1qrqzqa0l0rzzrlr20n487l6n865t8ndv6uhseulq";
let ibc_denom_on_gaia = format!("transfer/{channel_id_gaia}/{nam_addr}");
check_balance(&test, ALBERT, NAM, 2_000_000)?;

let memo_path = gen_ibc_shielding_data(
&test,
AB_PAYMENT_ADDRESS,
&ibc_denom_on_gaia,
8,
&port_id_namada,
&channel_id_namada,
)?;
let memo = packet_forward_memo(
MASP.to_string().into(),
&PortId::transfer(),
&channel_id_namada,
None,
Some(shielded_recv_memo(
&memo_path,
Amount::native_whole(8),
overflow_addr.parse().unwrap(),
)),
);
transfer(
&test,
ALBERT,
"PacketForwardMiddleware",
NAM,
7,
Some(ALBERT_KEY),
&PortId::transfer(),
&channel_id_namada,
None,
None,
None,
Some(&memo),
)?;
wait_for_packet_relay(&hermes_dir, &port_id_gaia, &channel_id_gaia, &test)?;

// Check the token on Namada
check_balance(&test, ALBERT, NAM, 2_000_000)?;
check_balance(&test, AB_VIEWING_KEY, NAM, 0)?;
check_balance(&test, overflow_addr, NAM, 0)?;

Ok(())
}

fn run_namada_cosmos(
chain_type: CosmosChainType,
mut update_genesis: impl FnMut(
Expand Down

0 comments on commit ac598c3

Please sign in to comment.