@@ -19,7 +19,7 @@ cfg_native!(
1919 use mocktopus:: mocking:: { MockResult , Mockable } ;
2020) ;
2121
22- const EXPECTED_TX_FEE : i64 = 1000 ;
22+ const DEFAULT_TX_FEE_RATE : i64 = 1000 ;
2323const CONTRACT_CALL_GAS_FEE : i64 = ( QRC20_GAS_LIMIT_DEFAULT * QRC20_GAS_PRICE_DEFAULT ) as i64 ;
2424const SWAP_PAYMENT_GAS_FEE : i64 = ( QRC20_PAYMENT_GAS_LIMIT * QRC20_GAS_PRICE_DEFAULT ) as i64 ;
2525const TAKER_PAYMENT_SPEND_SEARCH_INTERVAL : f64 = 1. ;
@@ -59,9 +59,9 @@ pub fn qrc20_coin_for_test(priv_key: [u8; 32], fallback_swap: Option<&str>) -> (
5959 ( ctx, coin)
6060}
6161
62- fn check_tx_fee ( coin : & Qrc20Coin , expected_tx_fee : ActualFeeRate ) {
63- let actual_tx_fee = block_on ( coin. get_fee_rate ( ) ) . unwrap ( ) ;
64- assert_eq ! ( actual_tx_fee , expected_tx_fee ) ;
62+ fn check_fee_rate ( coin : & Qrc20Coin , expected_fee_rate : ActualFeeRate ) {
63+ let actual_fee_rate = block_on ( coin. get_fee_rate ( ) ) . unwrap ( ) ;
64+ assert_eq ! ( actual_fee_rate , expected_fee_rate ) ;
6565}
6666
6767#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -144,7 +144,7 @@ fn test_withdraw_impl_fee_details() {
144144 // 1000 from satoshi,
145145 // where decimals = 8,
146146 // 1000 is fixed fee
147- "miner_fee" : "0.00001 " ,
147+ "miner_fee" : "0.00000299 " ,
148148 "gas_limit" : 2_500_000 ,
149149 "gas_price" : 40 ,
150150 // (gas_limit * gas_price) from satoshi in Qtum
@@ -715,12 +715,12 @@ fn test_get_trade_fee() {
715715 172 , 110 , 180 , 13 , 123 , 179 , 10 , 49 ,
716716 ] ;
717717 let ( _ctx, coin) = qrc20_coin_for_test ( priv_key, None ) ;
718- // check if the coin's tx fee is expected
719- check_tx_fee ( & coin, ActualFeeRate :: FixedPerKb ( EXPECTED_TX_FEE as u64 ) ) ;
718+ // check if the coin's tx fee rate is expected
719+ check_fee_rate ( & coin, ActualFeeRate :: FixedPerKb ( DEFAULT_TX_FEE_RATE as u64 ) ) ;
720720
721721 let actual_trade_fee = block_on_f01 ( coin. get_trade_fee ( ) ) . unwrap ( ) ;
722722 let expected_trade_fee_amount = big_decimal_from_sat (
723- 2 * CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + EXPECTED_TX_FEE ,
723+ 2 * CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + DEFAULT_TX_FEE_RATE ,
724724 coin. utxo . decimals ,
725725 ) ;
726726 let expected = TradeFee {
@@ -742,20 +742,22 @@ fn test_sender_trade_preimage_zero_allowance() {
742742 231 , 153 , 202 , 20 , 238 , 120 , 64 ,
743743 ] ;
744744 let ( _ctx, coin) = qrc20_coin_for_test ( priv_key, None ) ;
745- // check if the coin's tx fee is expected
746- check_tx_fee ( & coin, ActualFeeRate :: FixedPerKb ( EXPECTED_TX_FEE as u64 ) ) ;
745+ const EXPECTED_PAYMENT_TX_FEE : i64 = 535 ;
746+ const EXPECTED_REFUND_TX_FEE : i64 = 396 ;
747+ // check if the coin's tx fee rate is expected
748+ check_fee_rate ( & coin, ActualFeeRate :: FixedPerKb ( DEFAULT_TX_FEE_RATE as u64 ) ) ;
747749
748750 let allowance = block_on ( coin. allowance ( coin. swap_contract_address ) ) . expect ( "!allowance" ) ;
749751 assert_eq ! ( allowance, 0 . into( ) ) ;
750752
751753 let erc20_payment_fee_with_one_approve = big_decimal_from_sat (
752- CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + EXPECTED_TX_FEE ,
754+ CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + EXPECTED_PAYMENT_TX_FEE ,
753755 coin. utxo . decimals ,
754756 ) ;
755- let sender_refund_fee = big_decimal_from_sat ( CONTRACT_CALL_GAS_FEE + EXPECTED_TX_FEE , coin. utxo . decimals ) ;
757+ let sender_refund_fee = big_decimal_from_sat ( CONTRACT_CALL_GAS_FEE + EXPECTED_REFUND_TX_FEE , coin. utxo . decimals ) ;
756758
757759 let actual =
758- block_on ( coin. get_sender_trade_fee ( TradePreimageValue :: Exact ( 1 . into ( ) ) , FeeApproxStage :: WithoutApprox , true ) )
760+ block_on ( coin. get_sender_trade_fee ( TradePreimageValue :: Exact ( 1 . into ( ) ) , FeeApproxStage :: TradePreimageMax ) ) // pass TradePreimageMax to add change output txfee, to correct the max vol calc
759761 . expect ( "!get_sender_trade_fee" ) ;
760762 // one `approve` contract call should be included into the expected trade fee
761763 let expected = TradeFee {
@@ -778,24 +780,28 @@ fn test_sender_trade_preimage_with_allowance() {
778780 143 , 221 , 19 , 47 , 74 , 175 , 100 ,
779781 ] ;
780782 let ( _ctx, coin) = qrc20_coin_for_test ( priv_key, None ) ;
781- // check if the coin's tx fee is expected
782- check_tx_fee ( & coin, ActualFeeRate :: FixedPerKb ( EXPECTED_TX_FEE as u64 ) ) ;
783+ const EXPECTED_PAYMENT_WITHOUT_APPROVE_TX_FEE : i64 = 576 ;
784+ const EXPECTED_PAYMENT_WITH_APPROVES_TX_FEE : i64 = 790 ;
785+ const EXPECTED_REFUND_TX_FEE : i64 = 544 ;
786+ // check if the coin's tx fee rate is expected
787+ check_fee_rate ( & coin, ActualFeeRate :: FixedPerKb ( DEFAULT_TX_FEE_RATE as u64 ) ) ;
783788
784789 let allowance = block_on ( coin. allowance ( coin. swap_contract_address ) ) . expect ( "!allowance" ) ;
785790 assert_eq ! ( allowance, 300_000_000 . into( ) ) ;
786791
787- let erc20_payment_fee_without_approve =
788- big_decimal_from_sat ( SWAP_PAYMENT_GAS_FEE + EXPECTED_TX_FEE , coin. utxo . decimals ) ;
792+ let erc20_payment_fee_without_approve = big_decimal_from_sat (
793+ SWAP_PAYMENT_GAS_FEE + EXPECTED_PAYMENT_WITHOUT_APPROVE_TX_FEE ,
794+ coin. utxo . decimals ,
795+ ) ;
789796 let erc20_payment_fee_with_two_approves = big_decimal_from_sat (
790- 2 * CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + EXPECTED_TX_FEE ,
797+ 2 * CONTRACT_CALL_GAS_FEE + SWAP_PAYMENT_GAS_FEE + EXPECTED_PAYMENT_WITH_APPROVES_TX_FEE ,
791798 coin. utxo . decimals ,
792799 ) ;
793- let sender_refund_fee = big_decimal_from_sat ( CONTRACT_CALL_GAS_FEE + EXPECTED_TX_FEE , coin. utxo . decimals ) ;
800+ let sender_refund_fee = big_decimal_from_sat ( CONTRACT_CALL_GAS_FEE + EXPECTED_REFUND_TX_FEE , coin. utxo . decimals ) ;
794801
795802 let actual = block_on ( coin. get_sender_trade_fee (
796803 TradePreimageValue :: Exact ( BigDecimal :: try_from ( 2.5 ) . unwrap ( ) ) ,
797- FeeApproxStage :: WithoutApprox ,
798- true ,
804+ FeeApproxStage :: TradePreimageMax ,
799805 ) )
800806 . expect ( "!get_sender_trade_fee" ) ;
801807 // the expected fee should not include any `approve` contract call
@@ -808,8 +814,7 @@ fn test_sender_trade_preimage_with_allowance() {
808814
809815 let actual = block_on ( coin. get_sender_trade_fee (
810816 TradePreimageValue :: Exact ( BigDecimal :: try_from ( 3.5 ) . unwrap ( ) ) ,
811- FeeApproxStage :: WithoutApprox ,
812- true ,
817+ FeeApproxStage :: TradePreimageMax ,
813818 ) )
814819 . expect ( "!get_sender_trade_fee" ) ;
815820 // two `approve` contract calls should be included into the expected trade fee
@@ -865,11 +870,10 @@ fn test_get_sender_trade_fee_preimage_for_correct_ticker() {
865870 ) )
866871 . unwrap ( ) ;
867872
868- let actual =
869- block_on ( coin. get_sender_trade_fee ( TradePreimageValue :: Exact ( 0 . into ( ) ) , FeeApproxStage :: OrderIssue , true ) )
870- . err ( )
871- . unwrap ( )
872- . into_inner ( ) ;
873+ let actual = block_on ( coin. get_sender_trade_fee ( TradePreimageValue :: Exact ( 0 . into ( ) ) , FeeApproxStage :: OrderIssue ) )
874+ . err ( )
875+ . unwrap ( )
876+ . into_inner ( ) ;
873877 // expecting TradePreimageError::NotSufficientBalance
874878 let expected = TradePreimageError :: NotSufficientBalance {
875879 coin : "tQTUM" . to_string ( ) ,
@@ -889,8 +893,9 @@ fn test_receiver_trade_preimage() {
889893 143 , 221 , 19 , 47 , 74 , 175 , 100 ,
890894 ] ;
891895 let ( _ctx, coin) = qrc20_coin_for_test ( priv_key, None ) ;
892- // check if the coin's tx fee is expected
893- check_tx_fee ( & coin, ActualFeeRate :: FixedPerKb ( EXPECTED_TX_FEE as u64 ) ) ;
896+ const EXPECTED_TX_FEE : i64 = 544 ;
897+ // check if the coin's tx fee rate is expected
898+ check_fee_rate ( & coin, ActualFeeRate :: FixedPerKb ( DEFAULT_TX_FEE_RATE as u64 ) ) ;
894899
895900 let actual =
896901 block_on_f01 ( coin. get_receiver_trade_fee ( FeeApproxStage :: WithoutApprox ) ) . expect ( "!get_receiver_trade_fee" ) ;
@@ -914,8 +919,9 @@ fn test_taker_fee_tx_fee() {
914919 143 , 221 , 19 , 47 , 74 , 175 , 100 ,
915920 ] ;
916921 let ( _ctx, coin) = qrc20_coin_for_test ( priv_key, None ) ;
917- // check if the coin's tx fee is expected
918- check_tx_fee ( & coin, ActualFeeRate :: FixedPerKb ( EXPECTED_TX_FEE as u64 ) ) ;
922+ const EXPECTED_TX_FEE : i64 = 447 ;
923+ // check if the coin's tx fee rate is expected
924+ check_fee_rate ( & coin, ActualFeeRate :: FixedPerKb ( DEFAULT_TX_FEE_RATE as u64 ) ) ;
919925 let expected_balance = CoinBalance {
920926 spendable : BigDecimal :: from ( 5u32 ) ,
921927 unspendable : BigDecimal :: from ( 0u32 ) ,
0 commit comments