diff --git a/contracts/pool_stable/src/tests/swap.rs b/contracts/pool_stable/src/tests/swap.rs index 42a62e349..2db04e1ec 100644 --- a/contracts/pool_stable/src/tests/swap.rs +++ b/contracts/pool_stable/src/tests/swap.rs @@ -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] @@ -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::); + + let spread = 100i64; // 1% maximum spread allowed + pool.swap( + &user, + &token1.address, + &1, + &None, + &Some(spread), + &None::, + ); + + 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); +}