Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): don't use .wait() and use block_on instead #2220

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 28 additions & 26 deletions mm2src/coins/eth/eth_tests.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::*;
use crate::eth::for_tests::{eth_coin_for_test, eth_coin_from_keypair};
use crate::{DexFee, IguanaPrivKey};
use common::{block_on, now_sec};
use common::{block_on, block_on_f01, now_sec};
#[cfg(not(target_arch = "wasm32"))]
use ethkey::{Generator, Random};
use mm2_core::mm_ctx::MmCtxBuilder;
Expand Down Expand Up @@ -184,18 +184,16 @@ fn test_wait_for_payment_spend_timeout() {
184, 42, 106,
];

assert!(coin
.wait_for_htlc_tx_spend(WaitForHTLCTxSpendArgs {
tx_bytes: &tx_bytes,
secret_hash: &[],
wait_until,
from_block,
swap_contract_address: &coin.swap_contract_address(),
check_every: TAKER_PAYMENT_SPEND_SEARCH_INTERVAL,
watcher_reward: false
})
.wait()
.is_err());
assert!(block_on_f01(coin.wait_for_htlc_tx_spend(WaitForHTLCTxSpendArgs {
tx_bytes: &tx_bytes,
secret_hash: &[],
wait_until,
from_block,
swap_contract_address: &coin.swap_contract_address(),
check_every: TAKER_PAYMENT_SPEND_SEARCH_INTERVAL,
watcher_reward: false
}))
.is_err());
}

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -222,7 +220,7 @@ fn test_withdraw_impl_manual_fee() {
memo: None,
ibc_source_channel: None,
};
coin.get_balance().wait().unwrap();
block_on_f01(coin.get_balance()).unwrap();

let tx_details = block_on(withdraw_impl(coin, withdraw_req)).unwrap();
let expected = Some(
Expand Down Expand Up @@ -271,7 +269,7 @@ fn test_withdraw_impl_fee_details() {
memo: None,
ibc_source_channel: None,
};
coin.get_balance().wait().unwrap();
block_on_f01(coin.get_balance()).unwrap();

let tx_details = block_on(withdraw_impl(coin, withdraw_req)).unwrap();
let expected = Some(
Expand Down Expand Up @@ -476,10 +474,8 @@ fn get_receiver_trade_preimage() {
paid_from_trading_vol: false,
};

let actual = coin
.get_receiver_trade_fee(FeeApproxStage::WithoutApprox)
.wait()
.expect("!get_sender_trade_fee");
let actual =
block_on_f01(coin.get_receiver_trade_fee(FeeApproxStage::WithoutApprox)).expect("!get_sender_trade_fee");
assert_eq!(actual, expected_fee);
}

Expand Down Expand Up @@ -582,7 +578,9 @@ fn validate_dex_fee_invalid_sender_eth() {
min_block_number: 0,
uuid: &[],
};
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
let error = block_on_f01(coin.validate_fee(validate_fee_args))
.unwrap_err()
.into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")),
_ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error),
Expand Down Expand Up @@ -617,7 +615,9 @@ fn validate_dex_fee_invalid_sender_erc() {
min_block_number: 0,
uuid: &[],
};
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
let error = block_on_f01(coin.validate_fee(validate_fee_args))
.unwrap_err()
.into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("was sent from wrong address")),
_ => panic!("Expected `WrongPaymentTx` wrong sender address, found {:?}", error),
Expand Down Expand Up @@ -655,7 +655,9 @@ fn validate_dex_fee_eth_confirmed_before_min_block() {
min_block_number: 11784793,
uuid: &[],
};
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
let error = block_on_f01(coin.validate_fee(validate_fee_args))
.unwrap_err()
.into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")),
_ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error),
Expand Down Expand Up @@ -693,7 +695,9 @@ fn validate_dex_fee_erc_confirmed_before_min_block() {
min_block_number: 11823975,
uuid: &[],
};
let error = coin.validate_fee(validate_fee_args).wait().unwrap_err().into_inner();
let error = block_on_f01(coin.validate_fee(validate_fee_args))
.unwrap_err()
.into_inner();
match error {
ValidatePaymentError::WrongPaymentTx(err) => assert!(err.contains("confirmed before min_block")),
_ => panic!("Expected `WrongPaymentTx` early confirmation, found {:?}", error),
Expand Down Expand Up @@ -815,9 +819,7 @@ fn polygon_check_if_my_payment_sent() {
amount: &BigDecimal::default(),
payment_instructions: &None,
};
let my_payment = coin
.check_if_my_payment_sent(if_my_payment_sent_args)
.wait()
let my_payment = block_on_f01(coin.check_if_my_payment_sent(if_my_payment_sent_args))
.unwrap()
.unwrap();
let expected_hash = BytesJson::from("69a20008cea0c15ee483b5bbdff942752634aa072dfd2ff715fe87eec302de11");
Expand Down
22 changes: 10 additions & 12 deletions mm2src/coins/lightning/ln_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use bitcoin::hash_types::{BlockHash, TxMerkleNode, Txid};
use bitcoin_hashes::{sha256d, Hash};
use common::executor::{abortable_queue::AbortableQueue, AbortableSystem, SpawnFuture, Timer};
use common::log::{debug, error, info};
use common::wait_until_sec;
use common::{block_on_f01, wait_until_sec};
use futures::compat::Future01CompatExt;
use futures::future::join_all;
use keys::hash::H256;
Expand Down Expand Up @@ -570,17 +570,15 @@ impl FeeEstimator for Platform {
ConfirmationTarget::HighPriority => self.confirmations_targets.high_priority,
};
let fee_per_kb = tokio::task::block_in_place(move || {
self.rpc_client()
.estimate_fee_sat(
platform_coin.decimals(),
// Todo: when implementing Native client detect_fee_method should be used for Native and
// EstimateFeeMethod::Standard for Electrum
&EstimateFeeMethod::Standard,
&conf.estimate_fee_mode,
n_blocks,
)
.wait()
.unwrap_or(latest_fees)
block_on_f01(self.rpc_client().estimate_fee_sat(
platform_coin.decimals(),
// Todo: when implementing Native client detect_fee_method should be used for Native and
// EstimateFeeMethod::Standard for Electrum
&EstimateFeeMethod::Standard,
&conf.estimate_fee_mode,
n_blocks,
))
.unwrap_or(latest_fees)
});

// Set default fee to last known fee for the corresponding confirmation target
Expand Down
Loading
Loading