Skip to content

Commit

Permalink
adds a test that tests the number of decimals we can use in stable pool
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Jul 29, 2024
1 parent fccfb6e commit a3044a2
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions contracts/pool_stable/src/tests/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use soroban_sdk::{symbol_short, testutils::Address as _, Address, Env, IntoVal};

use super::setup::{deploy_stable_liquidity_pool_contract, deploy_token_contract};
use crate::storage::{Asset, PoolResponse, SimulateReverseSwapResponse, SimulateSwapResponse};
use crate::token_contract;
use soroban_decimal::Decimal;

#[test]
Expand Down Expand Up @@ -480,3 +481,95 @@ fn simple_swap_should_panic_after_deadline() {
&Some(99u64),
);
}

#[test]
fn simple_swap_with_two_tokens_both_with_18_decimals() {
let env = Env::default();
env.mock_all_auths();
env.budget().reset_unlimited();

let admin = Address::generate(&env);
let manager = Address::generate(&env);
let factory = Address::generate(&env);
let user = Address::generate(&env);

let mut token1 = token_contract::Client::new(
&env,
&env.register_contract_wasm(None, token_contract::WASM),
);

token1.initialize(
&admin,
&7,
&"name1".into_val(&env),
&"symbol1".into_val(&env),
);

let mut token2 = token_contract::Client::new(
&env,
&env.register_contract_wasm(None, token_contract::WASM),
);

token2.initialize(
&admin,
&7,
&"name2".into_val(&env),
&"symbol2".into_val(&env),
);

if token2.address < token1.address {
std::mem::swap(&mut token1, &mut token2);
}

let swap_fees = 0i64;
let pool = deploy_stable_liquidity_pool_contract(
&env,
None,
(&token1.address, &token2.address),
swap_fees,
None,
None,
None,
manager,
factory,
None,
);

token1.mint(&user, &1_100);
token2.mint(&user, &1_100);
pool.provide_liquidity(&user, &1_000, &1_000, &None, &None::<u64>);

let spread = 100i64; // 1% maximum spread allowed
pool.swap(
&user,
&token1.address,
&1,
&None,
&Some(spread),
&None::<u64>,
);

let share_token_address = pool.query_share_token_address();
let result = pool.query_pool_info();

assert_eq!(
result,
PoolResponse {
asset_a: Asset {
address: token1.address.clone(),
amount: 1_001i128,
},
asset_b: Asset {
address: token2.address.clone(),
amount: 999i128,
},
asset_lp_share: Asset {
address: share_token_address.clone(),
amount: 1_000i128,
},
stake_address: pool.query_stake_contract_address(),
}
);
assert_eq!(token1.balance(&user), 99);
assert_eq!(token2.balance(&user), 101);
}

0 comments on commit a3044a2

Please sign in to comment.