Skip to content

Commit

Permalink
fixes a failing test due to it using the wrong decimal implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gangov committed Aug 5, 2024
1 parent 53ddae3 commit 8018e66
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions contracts/pool_stable/src/tests/swap.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
extern crate std;

use phoenix::utils::{convert_i128_to_u128, convert_u128_to_i128};
use soroban_sdk::testutils::{AuthorizedFunction, AuthorizedInvocation, Ledger};
use soroban_sdk::U256;
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 soroban_decimal::Decimal;
use soroban_decimal::Decimal256;

#[test]
fn simple_swap() {
Expand Down Expand Up @@ -231,7 +233,14 @@ fn swap_with_high_fee() {
}
);
// 10% fees are deducted from the swap result and sent to fee recipient address
let fees = Decimal::percent(10) * output_amount;
let fees = convert_u128_to_i128(
Decimal256::percent(&env, 10)
.mul(
&env,
&Decimal256::new(&env, convert_i128_to_u128(output_amount)),
)
.to_u128_with_precision(token1.decimals() as i32),
);
assert_eq!(token2.balance(&user1), output_amount - fees);
assert_eq!(token2.balance(&fee_recipient), fees);
}
Expand Down Expand Up @@ -285,7 +294,14 @@ fn swap_simulation_even_pool() {

// This is Stable Swap LP with constant product formula
let output_amount = 98_582i128;
let fees = Decimal::percent(10) * output_amount;
let fees = convert_u128_to_i128(
Decimal256::percent(&env, 10)
.mul(
&env,
&Decimal256::new(&env, convert_i128_to_u128(output_amount)),
)
.to_u128_with_precision(token1.decimals() as i32),
);
assert_eq!(
result,
SimulateSwapResponse {
Expand Down

0 comments on commit 8018e66

Please sign in to comment.