2021-03-01 06:17:02 +00:00
|
|
|
use monero_harness::{Monero, MoneroWalletRpc};
|
2021-04-15 08:39:59 +00:00
|
|
|
use monero_rpc::wallet::MoneroWalletRpc as _;
|
2020-09-28 06:18:50 +00:00
|
|
|
use spectral::prelude::*;
|
2021-03-02 02:13:52 +00:00
|
|
|
use std::time::Duration;
|
2020-09-28 06:18:50 +00:00
|
|
|
use testcontainers::clients::Cli;
|
2021-03-02 02:13:52 +00:00
|
|
|
use tokio::time::sleep;
|
2021-03-28 22:54:48 +00:00
|
|
|
use tracing_subscriber::util::SubscriberInitExt;
|
2021-01-11 01:55:19 +00:00
|
|
|
|
2020-09-28 06:18:50 +00:00
|
|
|
#[tokio::test]
|
2020-11-02 03:42:08 +00:00
|
|
|
async fn fund_transfer_and_check_tx_key() {
|
2021-03-28 22:54:48 +00:00
|
|
|
let _guard = tracing_subscriber::fmt()
|
|
|
|
.with_env_filter("warn,test=debug,monero_harness=debug,monero_rpc=debug")
|
|
|
|
.set_default();
|
2021-01-11 01:55:19 +00:00
|
|
|
|
2020-11-01 23:02:28 +00:00
|
|
|
let fund_alice: u64 = 1_000_000_000_000;
|
2020-11-02 10:12:38 +00:00
|
|
|
let fund_bob = 0;
|
|
|
|
let send_to_bob = 5_000_000_000;
|
2020-09-28 06:18:50 +00:00
|
|
|
|
|
|
|
let tc = Cli::default();
|
2021-04-16 02:05:12 +00:00
|
|
|
let (monero, _containers) = Monero::new(&tc, vec!["alice", "bob"]).await.unwrap();
|
2020-11-02 05:00:35 +00:00
|
|
|
let alice_wallet = monero.wallet("alice").unwrap();
|
|
|
|
let bob_wallet = monero.wallet("bob").unwrap();
|
2020-11-02 03:42:08 +00:00
|
|
|
|
2021-04-08 08:56:26 +00:00
|
|
|
monero.init_miner().await.unwrap();
|
|
|
|
monero.init_wallet("alice", vec![fund_alice]).await.unwrap();
|
|
|
|
monero.init_wallet("bob", vec![fund_bob]).await.unwrap();
|
|
|
|
monero.start_miner().await.unwrap();
|
2020-11-02 03:42:08 +00:00
|
|
|
|
2020-11-02 07:58:52 +00:00
|
|
|
// check alice balance
|
2020-11-02 05:00:35 +00:00
|
|
|
let got_alice_balance = alice_wallet.balance().await.unwrap();
|
2020-11-02 03:42:08 +00:00
|
|
|
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
2020-11-02 07:58:52 +00:00
|
|
|
|
|
|
|
// transfer from alice to bob
|
2020-11-02 10:12:38 +00:00
|
|
|
let bob_address = bob_wallet.address().await.unwrap().address;
|
2020-11-03 00:46:25 +00:00
|
|
|
let transfer = alice_wallet
|
|
|
|
.transfer(&bob_address, send_to_bob)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2021-03-01 06:17:02 +00:00
|
|
|
wait_for_wallet_to_catch_up(bob_wallet, send_to_bob).await;
|
2020-11-02 07:58:52 +00:00
|
|
|
|
|
|
|
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
2020-11-02 10:12:38 +00:00
|
|
|
assert_that(&got_bob_balance).is_equal_to(send_to_bob);
|
2020-11-02 03:42:08 +00:00
|
|
|
|
2020-11-02 07:58:52 +00:00
|
|
|
// check if tx was actually seen
|
2020-11-02 03:42:08 +00:00
|
|
|
let tx_id = transfer.tx_hash;
|
2021-04-15 08:39:59 +00:00
|
|
|
let tx_key = transfer.tx_key.unwrap().to_string();
|
2020-11-02 07:58:52 +00:00
|
|
|
let res = bob_wallet
|
2020-11-03 00:49:53 +00:00
|
|
|
.client()
|
2021-04-15 08:39:59 +00:00
|
|
|
.check_tx_key(tx_id, tx_key, bob_address)
|
2020-11-02 03:42:08 +00:00
|
|
|
.await
|
|
|
|
.expect("failed to check tx by key");
|
|
|
|
|
2020-11-02 10:12:38 +00:00
|
|
|
assert_that!(res.received).is_equal_to(send_to_bob);
|
2020-09-28 06:18:50 +00:00
|
|
|
}
|
2021-03-01 06:17:02 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-03-02 02:13:52 +00:00
|
|
|
sleep(Duration::from_secs(1)).await;
|
2021-03-01 06:17:02 +00:00
|
|
|
}
|
|
|
|
}
|