Skip to content

Commit

Permalink
don't use block_on on mocked methods
Browse files Browse the repository at this point in the history
because we now use tokio's block_on to wait for this method and not futures' wait. this means we will block_on the same runtime recurrsively and panic. So instead of block_on in mock methods, fut.boxed() like the original methods.

the difference between the two impls of the mock is that
the first one ran synchronously and returned an immediately ready future,
the second one creates an non-ready future to be ran asynchronously by the caller.
  • Loading branch information
mariocynicys committed Sep 16, 2024
1 parent a58dbf7 commit 6d7e8eb
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 216 deletions.
29 changes: 16 additions & 13 deletions mm2src/coins/qrc20/qrc20_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,22 @@ fn test_withdraw_impl_fee_details() {
let (_ctx, coin) = qrc20_coin_for_test(priv_key, None);

Qrc20Coin::get_unspent_ordered_list.mock_safe(|coin, _| {
let cache = block_on(coin.as_ref().recently_spent_outpoints.lock());
let unspents = vec![UnspentInfo {
outpoint: OutPoint {
hash: 1.into(),
index: 0,
},
value: 1000000000,
height: Default::default(),
script: coin
.script_for_address(&block_on(coin.as_ref().derivation_method.unwrap_single_addr()))
.unwrap(),
}];
MockResult::Return(Box::pin(futures::future::ok((unspents, cache))))
let fut = async move {
let cache = coin.as_ref().recently_spent_outpoints.lock().await;
let unspents = vec![UnspentInfo {
outpoint: OutPoint {
hash: 1.into(),
index: 0,
},
value: 1000000000,
height: Default::default(),
script: coin
.script_for_address(&coin.as_ref().derivation_method.unwrap_single_addr().await)
.unwrap(),
}];
Ok((unspents, cache))
};
MockResult::Return(fut.boxed())
});

let withdraw_req = WithdrawRequest {
Expand Down
Loading

0 comments on commit 6d7e8eb

Please sign in to comment.