Skip to content

Commit

Permalink
WIP: Fix osmosis xcs test
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Jan 9, 2025
1 parent 830d7f0 commit d5bbaba
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3511,7 +3511,7 @@ fn osmosis_basic() -> Result<()> {
}

#[test]
fn osmosis_bingbong() -> Result<()> {
fn osmosis_xcs() -> Result<()> {
// ==========================================================
// This test requires quite a long setup. Jump to the next
// occurrence of `SETUP DONE` in order to skip all of this
Expand Down Expand Up @@ -3965,19 +3965,64 @@ fn osmosis_bingbong() -> Result<()> {
)?
.assert_success();

// Shield some nam
let rpc_namada = get_actor_rpc(&test_namada, Who::Validator(0));

run!(
&test_namada,
Bin::Client,
[
"shield",
"--source",
BERTHA,
"--target",
AA_PAYMENT_ADDRESS,
"--amount",
"0.000056",
"--token",
NAM,
"--node",
&rpc_namada,
],
Some(40)
)?
.assert_success();

shielded_sync(&test_namada, AA_VIEWING_KEY)?;

let query_args = vec![
"balance",
"--owner",
AA_VIEWING_KEY,
"--token",
NAM,
"--node",
&rpc_namada,
];
let mut client = run!(&test_namada, Bin::Client, query_args, Some(40))?;
client.exp_string("nam: 0.000056")?;
client.assert_success();

// ==========================================================
// SETUP DONE
// ==========================================================
// At this point, we have IBC channels between Osmosis, Gaia
// and Namada. There is a LP with nam and samoleans, that we
// can use to swap between the two assets.
// can use to swap between the two assets. Moreover, we have
// shielded some nam tokens.
// ==========================================================

// Transparently swap samoleans with nam
let output_denom = get_gaia_denom_hash(format!(
// We wish to receive samoleans on namada
let output_denom_on_namada = get_gaia_denom_hash(format!(
"transfer/{channel_from_namada_to_gaia}/{COSMOS_COIN}"
));

// But on osmosis, we will end up with this token
let output_denom_on_osmosis = get_gaia_denom_hash(format!(
"transfer/{channel_from_osmosis_to_gaia}/{COSMOS_COIN}"
));
let rpc_namada = get_actor_rpc(&test_namada, Who::Validator(0));

// Transparently swap samoleans with nam
run!(
&test_namada,
Bin::Client,
Expand All @@ -3992,7 +4037,7 @@ fn osmosis_bingbong() -> Result<()> {
"--channel-id",
channel_from_namada_to_osmosis.as_ref(),
"--output-denom",
&output_denom,
&output_denom_on_namada,
"--local-recovery-addr",
&osmosis_jones,
"--swap-contract",
Expand All @@ -4002,7 +4047,7 @@ fn osmosis_bingbong() -> Result<()> {
"--target",
BERTHA,
"--pool-hop",
&format!("1:{output_denom}"),
&format!("1:{output_denom_on_osmosis}"),
"--node",
&rpc_namada,
],
Expand Down Expand Up @@ -4033,42 +4078,6 @@ fn osmosis_bingbong() -> Result<()> {
39,
)?;

// Shield some nam
run!(
&test_namada,
Bin::Client,
[
"shield",
"--source",
BERTHA,
"--target",
AA_PAYMENT_ADDRESS,
"--amount",
"0.000056",
"--token",
NAM,
"--node",
&rpc_namada,
],
Some(40)
)?
.assert_success();

shielded_sync(&test_namada, AA_VIEWING_KEY)?;

let query_args = vec![
"balance",
"--owner",
AA_VIEWING_KEY,
"--token",
NAM,
"--node",
&rpc_namada,
];
let mut client = run!(&test_namada, Bin::Client, query_args, Some(40))?;
client.exp_string("nam: 0.000056")?;
client.assert_success();

// Perform a shielded swap of samoleans and nam
run!(
&test_namada,
Expand All @@ -4084,7 +4093,7 @@ fn osmosis_bingbong() -> Result<()> {
"--channel-id",
channel_from_namada_to_osmosis.as_ref(),
"--output-denom",
&output_denom,
&output_denom_on_namada,
"--local-recovery-addr",
&osmosis_jones,
"--swap-contract",
Expand All @@ -4096,7 +4105,7 @@ fn osmosis_bingbong() -> Result<()> {
"--overflow-addr",
ALBERT,
"--pool-hop",
&format!("1:{output_denom}"),
&format!("1:{output_denom_on_osmosis}"),
"--gas-payer",
ALBERT_KEY,
"--node",
Expand All @@ -4122,22 +4131,16 @@ fn osmosis_bingbong() -> Result<()> {
)?;

// Check that the minimum amount got shielded
shielded_sync(&test_namada, AA_VIEWING_KEY)?;
check_balance(
check_shielded_balance(
&test_namada,
AA_VIEWING_KEY,
format!("transfer/{channel_from_namada_to_gaia}/{COSMOS_COIN}"),
&output_denom_on_namada,
10,
)?;
// 5 is derived from the uniswap formula:
// floor( 61 - ( 164 * 61 / (164 + 56) ) ) minus
// the minimum amount (10) which was shielded
check_balance(
&test_namada,
ALBERT,
format!("transfer/{channel_from_namada_to_gaia}/{COSMOS_COIN}"),
5,
)?;
check_balance(&test_namada, ALBERT, &output_denom_on_namada, 5)?;

Ok(())
}
Expand Down

0 comments on commit d5bbaba

Please sign in to comment.