Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
delaaxe committed Sep 25, 2023
1 parent e2259e5 commit 3ba16f3
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/tests/pricing/test_swap_pricing_utils.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use satoru::data::data_store::IDataStoreDispatcherTrait;
use satoru::data::keys;
use satoru::pricing::swap_pricing_utils::{
GetPriceImpactUsdParams, get_price_impact_usd_, get_price_impact_usd, get_next_pool_amount_usd
GetPriceImpactUsdParams, get_price_impact_usd_, get_price_impact_usd, get_next_pool_amount_usd,
get_swap_fees
};
use satoru::market::market::Market;
use satoru::utils::calc;
Expand Down Expand Up @@ -91,3 +92,41 @@ fn given_normal_conditions_when_get_next_pool_amount_usd_then_works() {
// *********************************************************************************************
teardown(data_store.contract_address);
}

#[test]
fn given_normal_conditions_when_get_swap_fees_then_works() {
// *********************************************************************************************
// * SETUP *
// *********************************************************************************************
let (_, _, data_store) = setup();

let market_token = 'market_token'.try_into().unwrap();
let ui_fee_receiver = 'ui_fee_receiver'.try_into().unwrap();
let for_positive_impact = true;

data_store.set_u128(keys::swap_fee_factor_key(market_token, for_positive_impact), 5);
data_store.set_u128(keys::swap_fee_receiver_factor(), 10);
data_store.set_u128(keys::max_ui_fee_factor(), 9);
data_store.set_u128(keys::ui_fee_factor_key(ui_fee_receiver), 9);


// *********************************************************************************************
// * TEST LOGIC *
// *********************************************************************************************

let amount = 1000;
let fees = get_swap_fees(
data_store, market_token, amount, for_positive_impact, ui_fee_receiver
);

assert(fees.fee_receiver_amount == 0, 'invalid');
assert(fees.fee_amount_for_pool == 0, 'invalid');
assert(fees.amount_after_fees == 0x03e8, 'invalid');
assert(fees.ui_fee_receiver_factor == 9, 'invalid');
assert(fees.ui_fee_amount == 0, 'invalid');

// *********************************************************************************************
// * TEARDOWN *
// *********************************************************************************************
teardown(data_store.contract_address);
}

0 comments on commit 3ba16f3

Please sign in to comment.