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]
|
|
|
|
async fn wallet_and_accounts() {
|
|
|
|
let tc = Cli::default();
|
2020-10-23 00:28:58 +00:00
|
|
|
let (monero, _container) = Monero::new(&tc).unwrap();
|
2020-10-20 01:18:27 +00:00
|
|
|
let cli = monero.miner_wallet_rpc_client();
|
2020-09-28 06:18:50 +00:00
|
|
|
|
|
|
|
println!("creating wallet ...");
|
|
|
|
|
2020-10-20 01:18:27 +00:00
|
|
|
let _ = cli
|
2020-09-28 06:18:50 +00:00
|
|
|
.create_wallet("wallet")
|
|
|
|
.await
|
|
|
|
.expect("failed to create wallet");
|
|
|
|
|
2020-10-20 01:18:27 +00:00
|
|
|
let got = cli.get_balance(0).await.expect("failed to get balance");
|
2020-09-28 06:18:50 +00:00
|
|
|
let want = 0;
|
|
|
|
|
|
|
|
assert_that!(got).is_equal_to(want);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn create_account_and_retrieve_it() {
|
|
|
|
let tc = Cli::default();
|
2020-10-23 00:28:58 +00:00
|
|
|
let (monero, _container) = Monero::new(&tc).unwrap();
|
2020-10-20 01:18:27 +00:00
|
|
|
let cli = monero.miner_wallet_rpc_client();
|
2020-09-28 06:18:50 +00:00
|
|
|
|
|
|
|
let label = "Iron Man"; // This is intentionally _not_ Alice or Bob.
|
|
|
|
|
|
|
|
let _ = cli
|
|
|
|
.create_wallet("wallet")
|
|
|
|
.await
|
|
|
|
.expect("failed to create wallet");
|
|
|
|
|
|
|
|
let _ = cli
|
|
|
|
.create_account(label)
|
|
|
|
.await
|
|
|
|
.expect("failed to create account");
|
|
|
|
|
|
|
|
let mut found: bool = false;
|
|
|
|
let accounts = cli
|
|
|
|
.get_accounts("") // Empty filter.
|
|
|
|
.await
|
|
|
|
.expect("failed to get accounts");
|
|
|
|
for account in accounts.subaddress_accounts {
|
|
|
|
if account.label == label {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert!(found);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn transfer_and_check_tx_key() {
|
|
|
|
let fund_alice = 1_000_000_000_000;
|
|
|
|
let fund_bob = 0;
|
|
|
|
|
|
|
|
let tc = Cli::default();
|
2020-10-23 00:28:58 +00:00
|
|
|
let (monero, _container) = Monero::new(&tc).unwrap();
|
2020-09-28 06:18:50 +00:00
|
|
|
let _ = monero.init(fund_alice, fund_bob).await;
|
|
|
|
|
|
|
|
let address_bob = monero
|
2020-10-20 01:18:27 +00:00
|
|
|
.bob_wallet_rpc_client()
|
|
|
|
.get_address(0)
|
2020-09-28 06:18:50 +00:00
|
|
|
.await
|
|
|
|
.expect("failed to get Bob's address")
|
|
|
|
.address;
|
|
|
|
|
|
|
|
let transfer_amount = 100;
|
|
|
|
let transfer = monero
|
2020-10-20 01:18:27 +00:00
|
|
|
.alice_wallet_rpc_client()
|
|
|
|
.transfer(0, transfer_amount, &address_bob)
|
2020-09-28 06:18:50 +00:00
|
|
|
.await
|
|
|
|
.expect("transfer failed");
|
|
|
|
|
|
|
|
let tx_id = transfer.tx_hash;
|
|
|
|
let tx_key = transfer.tx_key;
|
|
|
|
|
|
|
|
let cli = monero.miner_wallet_rpc_client();
|
|
|
|
let res = cli
|
|
|
|
.check_tx_key(&tx_id, &tx_key, &address_bob)
|
|
|
|
.await
|
|
|
|
.expect("failed to check tx by key");
|
|
|
|
|
|
|
|
assert_that!(res.received).is_equal_to(transfer_amount);
|
|
|
|
}
|