2020-10-20 01:18:27 +00:00
|
|
|
use monero_harness::Monero;
|
2020-09-28 06:18:50 +00:00
|
|
|
use spectral::prelude::*;
|
|
|
|
use testcontainers::clients::Cli;
|
|
|
|
|
|
|
|
#[tokio::test]
|
2020-11-02 03:42:08 +00:00
|
|
|
async fn fund_transfer_and_check_tx_key() {
|
2020-11-01 23:02:28 +00:00
|
|
|
let fund_alice: u64 = 1_000_000_000_000;
|
2020-11-02 07:58:52 +00:00
|
|
|
let fund_bob = 5_000_000_000;
|
2020-09-28 06:18:50 +00:00
|
|
|
|
|
|
|
let tc = Cli::default();
|
2020-11-02 07:58:52 +00:00
|
|
|
let (monero, _containers) = Monero::new(&tc, Some("test_".to_string()), None, vec![
|
2020-11-02 05:00:35 +00: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 03:42:08 +00:00
|
|
|
|
2020-11-02 05:00:35 +00:00
|
|
|
let alice_address = alice_wallet.address().await.unwrap().address;
|
2020-11-02 07:58:52 +00:00
|
|
|
let bob_address = bob_wallet.address().await.unwrap().address;
|
2020-11-02 03:42:08 +00:00
|
|
|
|
2020-11-02 07:58:52 +00:00
|
|
|
// fund alice
|
|
|
|
monero.fund(&alice_address, fund_alice).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 refreshed = alice_wallet.inner().refresh().await.unwrap();
|
2020-11-02 03:42:08 +00:00
|
|
|
assert_that(&refreshed.received_money).is_true();
|
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
|
|
|
|
let transfer = monero
|
|
|
|
.transfer_from_alice(&bob_address, fund_bob)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let refreshed = bob_wallet.inner().refresh().await.unwrap();
|
|
|
|
assert_that(&refreshed.received_money).is_true();
|
|
|
|
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
2020-11-02 03:42:08 +00:00
|
|
|
assert_that(&got_bob_balance).is_equal_to(fund_bob);
|
|
|
|
|
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;
|
|
|
|
let tx_key = transfer.tx_key;
|
2020-11-02 07:58:52 +00:00
|
|
|
let res = bob_wallet
|
2020-11-02 05:00:35 +00:00
|
|
|
.inner()
|
2020-11-02 07:58:52 +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 07:58:52 +00:00
|
|
|
assert_that!(res.received).is_equal_to(fund_bob);
|
2020-09-28 06:18:50 +00:00
|
|
|
}
|