mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-07-05 12:04:39 -04:00
Merge #248
248: Wait for wallet to catch up instead of block generation r=thomaseizinger a=da-kami
The monero harness wallet always starts a miner that mines new blocks every second.
This can conflict with additionally triggering block generation and cause this error:
```
monero_rpc::rpc::monerod: generate blocks response: {
"error": {
"code": -7,
"message": "Block not accepted"
},
"id": "1",
"jsonrpc": "2.0"
}
```
See error in CI run here: 2001131193
Since the miner is generating blocks anyway we can wait for the wallet to catch up.
Refresh is done upon querying the balance, thus the refresh calls were removed.
---
Note: we could also opt for starting the miner optionally. This would make this test more efficient, but is a more intrusive change, thus I opted for this fix for now.
Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
commit
17278d1278
1 changed files with 17 additions and 12 deletions
|
@ -1,7 +1,9 @@
|
||||||
use crate::testutils::init_tracing;
|
use crate::testutils::init_tracing;
|
||||||
use monero_harness::Monero;
|
use monero_harness::{Monero, MoneroWalletRpc};
|
||||||
use spectral::prelude::*;
|
use spectral::prelude::*;
|
||||||
|
use std::time::Duration;
|
||||||
use testcontainers::clients::Cli;
|
use testcontainers::clients::Cli;
|
||||||
|
use tokio::time::sleep;
|
||||||
|
|
||||||
mod testutils;
|
mod testutils;
|
||||||
|
|
||||||
|
@ -22,9 +24,6 @@ async fn fund_transfer_and_check_tx_key() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let alice_wallet = monero.wallet("alice").unwrap();
|
let alice_wallet = monero.wallet("alice").unwrap();
|
||||||
let bob_wallet = monero.wallet("bob").unwrap();
|
let bob_wallet = monero.wallet("bob").unwrap();
|
||||||
let miner_wallet = monero.wallet("miner").unwrap();
|
|
||||||
|
|
||||||
let miner_address = miner_wallet.address().await.unwrap().address;
|
|
||||||
|
|
||||||
// fund alice
|
// fund alice
|
||||||
monero
|
monero
|
||||||
|
@ -33,7 +32,6 @@ async fn fund_transfer_and_check_tx_key() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// check alice balance
|
// check alice balance
|
||||||
alice_wallet.refresh().await.unwrap();
|
|
||||||
let got_alice_balance = alice_wallet.balance().await.unwrap();
|
let got_alice_balance = alice_wallet.balance().await.unwrap();
|
||||||
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
||||||
|
|
||||||
|
@ -44,14 +42,8 @@ async fn fund_transfer_and_check_tx_key() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
monero
|
wait_for_wallet_to_catch_up(bob_wallet, send_to_bob).await;
|
||||||
.monerod()
|
|
||||||
.client()
|
|
||||||
.generate_blocks(10, &miner_address)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
bob_wallet.refresh().await.unwrap();
|
|
||||||
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
||||||
assert_that(&got_bob_balance).is_equal_to(send_to_bob);
|
assert_that(&got_bob_balance).is_equal_to(send_to_bob);
|
||||||
|
|
||||||
|
@ -66,3 +58,16 @@ async fn fund_transfer_and_check_tx_key() {
|
||||||
|
|
||||||
assert_that!(res.received).is_equal_to(send_to_bob);
|
assert_that!(res.received).is_equal_to(send_to_bob);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn wait_for_wallet_to_catch_up(wallet: &MoneroWalletRpc, expected_balance: u64) {
|
||||||
|
let max_retry = 15;
|
||||||
|
let mut retry = 0;
|
||||||
|
loop {
|
||||||
|
retry += 1;
|
||||||
|
let balance = wallet.balance().await.unwrap();
|
||||||
|
if balance == expected_balance || max_retry == retry {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue