2021-01-10 20:55:19 -05:00
|
|
|
use crate::testutils::init_tracing;
|
2020-10-19 21:18:27 -04:00
|
|
|
use monero_harness::Monero;
|
2020-09-28 02:18:50 -04:00
|
|
|
use spectral::prelude::*;
|
|
|
|
use testcontainers::clients::Cli;
|
|
|
|
|
2021-01-10 20:55:19 -05:00
|
|
|
mod testutils;
|
|
|
|
|
2020-09-28 02:18:50 -04:00
|
|
|
#[tokio::test]
|
2020-11-01 22:42:08 -05:00
|
|
|
async fn fund_transfer_and_check_tx_key() {
|
2021-01-10 20:55:19 -05:00
|
|
|
let _guard = init_tracing();
|
|
|
|
|
2020-11-01 18:02:28 -05:00
|
|
|
let fund_alice: u64 = 1_000_000_000_000;
|
2020-11-02 05:12:38 -05:00
|
|
|
let fund_bob = 0;
|
|
|
|
let send_to_bob = 5_000_000_000;
|
2020-09-28 02:18:50 -04:00
|
|
|
|
|
|
|
let tc = Cli::default();
|
2020-11-02 19:21:44 -05:00
|
|
|
let (monero, _containers) = Monero::new(&tc, Some("test_".to_string()), vec![
|
2020-11-02 00:00:35 -05:00
|
|
|
"alice".to_string(),
|
|
|
|
"bob".to_string(),
|
|
|
|
])
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
let alice_wallet = monero.wallet("alice").unwrap();
|
|
|
|
let bob_wallet = monero.wallet("bob").unwrap();
|
2020-11-02 19:46:25 -05:00
|
|
|
let miner_wallet = monero.wallet("miner").unwrap();
|
|
|
|
|
|
|
|
let miner_address = miner_wallet.address().await.unwrap().address;
|
2020-11-01 22:42:08 -05:00
|
|
|
|
2020-11-02 02:58:52 -05:00
|
|
|
// fund alice
|
2020-11-02 19:46:25 -05:00
|
|
|
monero
|
|
|
|
.init(vec![("alice", fund_alice), ("bob", fund_bob)])
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2020-11-01 22:42:08 -05:00
|
|
|
|
2020-11-02 02:58:52 -05:00
|
|
|
// check alice balance
|
2020-11-02 19:46:25 -05:00
|
|
|
alice_wallet.refresh().await.unwrap();
|
2020-11-02 00:00:35 -05:00
|
|
|
let got_alice_balance = alice_wallet.balance().await.unwrap();
|
2020-11-01 22:42:08 -05:00
|
|
|
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
2020-11-02 02:58:52 -05:00
|
|
|
|
|
|
|
// transfer from alice to bob
|
2020-11-02 05:12:38 -05:00
|
|
|
let bob_address = bob_wallet.address().await.unwrap().address;
|
2020-11-02 19:46:25 -05:00
|
|
|
let transfer = alice_wallet
|
|
|
|
.transfer(&bob_address, send_to_bob)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
monero
|
|
|
|
.monerod()
|
2020-11-02 19:49:53 -05:00
|
|
|
.client()
|
2020-11-02 19:46:25 -05:00
|
|
|
.generate_blocks(10, &miner_address)
|
2020-11-02 02:58:52 -05:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2020-11-02 19:46:25 -05:00
|
|
|
bob_wallet.refresh().await.unwrap();
|
2020-11-02 02:58:52 -05:00
|
|
|
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
2020-11-02 05:12:38 -05:00
|
|
|
assert_that(&got_bob_balance).is_equal_to(send_to_bob);
|
2020-11-01 22:42:08 -05:00
|
|
|
|
2020-11-02 02:58:52 -05:00
|
|
|
// check if tx was actually seen
|
2020-11-01 22:42:08 -05:00
|
|
|
let tx_id = transfer.tx_hash;
|
|
|
|
let tx_key = transfer.tx_key;
|
2020-11-02 02:58:52 -05:00
|
|
|
let res = bob_wallet
|
2020-11-02 19:49:53 -05:00
|
|
|
.client()
|
2020-11-02 02:58:52 -05:00
|
|
|
.check_tx_key(&tx_id, &tx_key, &bob_address)
|
2020-11-01 22:42:08 -05:00
|
|
|
.await
|
|
|
|
.expect("failed to check tx by key");
|
|
|
|
|
2020-11-02 05:12:38 -05:00
|
|
|
assert_that!(res.received).is_equal_to(send_to_bob);
|
2020-09-28 02:18:50 -04:00
|
|
|
}
|