Skip to content

Commit

Permalink
rename dex_fee_threshold to min_tx_amount in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shamardy committed Sep 27, 2023
1 parent 78da6d9 commit b0cb4aa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
12 changes: 6 additions & 6 deletions mm2src/mm2_main/src/lp_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,34 +1419,34 @@ mod lp_swap_tests {

#[test]
fn test_dex_fee_amount() {
let dex_fee_threshold = MmNumber::from("0.0001");
let min_tx_amount = MmNumber::from("0.0001");

let base = "BTC";
let rel = "ETH";
let amount = 1.into();
let actual_fee = dex_fee_amount(base, rel, &amount, &dex_fee_threshold);
let actual_fee = dex_fee_amount(base, rel, &amount, &min_tx_amount);
let expected_fee = amount / 777u64.into();
assert_eq!(expected_fee, actual_fee);

let base = "KMD";
let rel = "ETH";
let amount = 1.into();
let actual_fee = dex_fee_amount(base, rel, &amount, &dex_fee_threshold);
let actual_fee = dex_fee_amount(base, rel, &amount, &min_tx_amount);
let expected_fee = amount * (9, 7770).into();
assert_eq!(expected_fee, actual_fee);

let base = "BTC";
let rel = "KMD";
let amount = 1.into();
let actual_fee = dex_fee_amount(base, rel, &amount, &dex_fee_threshold);
let actual_fee = dex_fee_amount(base, rel, &amount, &min_tx_amount);
let expected_fee = amount * (9, 7770).into();
assert_eq!(expected_fee, actual_fee);

let base = "BTC";
let rel = "KMD";
let amount: MmNumber = "0.001".parse::<BigDecimal>().unwrap().into();
let actual_fee = dex_fee_amount(base, rel, &amount, &dex_fee_threshold);
assert_eq!(dex_fee_threshold, actual_fee);
let actual_fee = dex_fee_amount(base, rel, &amount, &min_tx_amount);
assert_eq!(min_tx_amount, actual_fee);
}

#[test]
Expand Down
15 changes: 5 additions & 10 deletions mm2src/mm2_main/tests/docker_tests/qrc20_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_
log!("{:?}", block_on(enable_native(&mm, "QTUM", &[], None)));

let qtum_balance = coin.my_spendable_balance().wait().expect("!my_balance");
let qtum_dex_fee_threshold = MmNumber::from("0.000728");
let qtum_min_tx_amount = MmNumber::from("0.000728");

// - `max_possible = balance - locked_amount`, where `locked_amount = 0`
// - `max_trade_fee = trade_fee(balance)`
Expand All @@ -1054,12 +1054,7 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_
// - `max_possible_2 = balance - locked_amount - max_trade_fee`, where `locked_amount = 0`
let max_possible_2 = &qtum_balance - &max_trade_fee;
// - `max_dex_fee = dex_fee(max_possible_2)`
let max_dex_fee = dex_fee_amount(
"QTUM",
"MYCOIN",
&MmNumber::from(max_possible_2),
&qtum_dex_fee_threshold,
);
let max_dex_fee = dex_fee_amount("QTUM", "MYCOIN", &MmNumber::from(max_possible_2), &qtum_min_tx_amount);
debug!("max_dex_fee: {:?}", max_dex_fee.to_fraction());

// - `max_fee_to_send_taker_fee = fee_to_send_taker_fee(max_dex_fee)`
Expand All @@ -1074,11 +1069,11 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_
// where `available = balance - locked_amount - max_trade_fee - max_fee_to_send_taker_fee`
let available = &qtum_balance - &max_trade_fee - &max_fee_to_send_taker_fee;
debug!("total_available: {}", available);
let min_tx_amount = qtum_dex_fee_threshold.clone();
let min_tx_amount = qtum_min_tx_amount.clone();
let expected_max_taker_vol =
max_taker_vol_from_available(MmNumber::from(available), "QTUM", "MYCOIN", &min_tx_amount)
.expect("max_taker_vol_from_available");
let real_dex_fee = dex_fee_amount("QTUM", "MYCOIN", &expected_max_taker_vol, &qtum_dex_fee_threshold);
let real_dex_fee = dex_fee_amount("QTUM", "MYCOIN", &expected_max_taker_vol, &qtum_min_tx_amount);
debug!("real_max_dex_fee: {:?}", real_dex_fee.to_fraction());

// check if the actual max_taker_vol equals to the expected
Expand Down Expand Up @@ -1111,7 +1106,7 @@ fn test_get_max_taker_vol_and_trade_with_dynamic_trade_fee(coin: QtumCoin, priv_
let timelock = now_sec_u32() - 200;
let secret_hash = &[0; 20];

let dex_fee_amount = dex_fee_amount("QTUM", "MYCOIN", &expected_max_taker_vol, &qtum_dex_fee_threshold);
let dex_fee_amount = dex_fee_amount("QTUM", "MYCOIN", &expected_max_taker_vol, &qtum_min_tx_amount);
let _taker_fee_tx = coin
.send_taker_fee(&DEX_FEE_ADDR_RAW_PUBKEY, dex_fee_amount.to_decimal(), &[])
.wait()
Expand Down

0 comments on commit b0cb4aa

Please sign in to comment.