mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-24 06:59:36 -05:00
Simple fund and send in test
This commit is contained in:
parent
f5643a4ea4
commit
738c67a421
@ -84,9 +84,7 @@ impl Default for Monero {
|
|||||||
args: Args::default(),
|
args: Args::default(),
|
||||||
ports: None,
|
ports: None,
|
||||||
entrypoint: Some("".into()),
|
entrypoint: Some("".into()),
|
||||||
wait_for_message:
|
wait_for_message: "core RPC server started ok".to_string(),
|
||||||
"The daemon is running offline and will not attempt to sync to the Monero network"
|
|
||||||
.to_string(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,7 +165,7 @@ pub struct MonerodArgs {
|
|||||||
pub struct WalletArgs {
|
pub struct WalletArgs {
|
||||||
pub disable_rpc_login: bool,
|
pub disable_rpc_login: bool,
|
||||||
pub confirm_external_bind: bool,
|
pub confirm_external_bind: bool,
|
||||||
pub wallet_file: String,
|
pub wallet_dir: String,
|
||||||
pub rpc_bind_ip: String,
|
pub rpc_bind_ip: String,
|
||||||
pub rpc_bind_port: u16,
|
pub rpc_bind_port: u16,
|
||||||
pub daemon_address: String,
|
pub daemon_address: String,
|
||||||
@ -259,7 +257,7 @@ impl WalletArgs {
|
|||||||
WalletArgs {
|
WalletArgs {
|
||||||
disable_rpc_login: true,
|
disable_rpc_login: true,
|
||||||
confirm_external_bind: true,
|
confirm_external_bind: true,
|
||||||
wallet_file: wallet_name.into(),
|
wallet_dir: wallet_name.into(),
|
||||||
rpc_bind_ip: "0.0.0.0".into(),
|
rpc_bind_ip: "0.0.0.0".into(),
|
||||||
rpc_bind_port: rpc_port,
|
rpc_bind_port: rpc_port,
|
||||||
daemon_address,
|
daemon_address,
|
||||||
@ -279,10 +277,8 @@ impl WalletArgs {
|
|||||||
args.push("--confirm-external-bind".to_string())
|
args.push("--confirm-external-bind".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.wallet_file.is_empty() {
|
if !self.wallet_dir.is_empty() {
|
||||||
args.push(format!("--wallet-dir /monero"));
|
args.push(format!("--wallet-dir {}", self.wallet_dir));
|
||||||
// args.push(format!("--wallet-file {}", self.wallet_file));
|
|
||||||
// args.push(format!("--password {}", self.wallet_file));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.rpc_bind_ip.is_empty() {
|
if !self.rpc_bind_ip.is_empty() {
|
||||||
@ -300,11 +296,6 @@ impl WalletArgs {
|
|||||||
if self.log_level != 0 {
|
if self.log_level != 0 {
|
||||||
args.push(format!("--log-level {}", self.log_level));
|
args.push(format!("--log-level {}", self.log_level));
|
||||||
}
|
}
|
||||||
// args.push(format!("--daemon-login username:password"));
|
|
||||||
// docker run --rm -d --net host -e DAEMON_HOST=node.xmr.to -e DAEMON_PORT=18081
|
|
||||||
// -e RPC_BIND_PORT=18083 -e RPC_USER=user -e RPC_PASSWD=passwd -v
|
|
||||||
// <path/to/and/including/wallet_folder>:/monero xmrto/monero monero-wallet-rpc
|
|
||||||
// --wallet-file wallet --password-file wallet.passwd
|
|
||||||
|
|
||||||
args.join(" ")
|
args.join(" ")
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
rpc::{
|
rpc::{
|
||||||
monerod,
|
monerod,
|
||||||
wallet::{self, GetAddress, Transfer},
|
wallet::{self, Transfer},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,6 +77,8 @@ impl<'c> Monero {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Starts a new wallet container which is attached to
|
||||||
|
/// MONEROD_DEFAULT_NETWORK and MONEROD_DAEMON_CONTAINER_NAME
|
||||||
pub async fn new_wallet(
|
pub async fn new_wallet(
|
||||||
cli: &'c Cli,
|
cli: &'c Cli,
|
||||||
name: &str,
|
name: &str,
|
||||||
@ -141,6 +143,15 @@ impl<'c> Monero {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sends amount to address
|
||||||
|
pub async fn transfer(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||||
|
let miner_wallet = self.wallet_rpc_client();
|
||||||
|
|
||||||
|
let transfer = miner_wallet.transfer(0, amount, address).await?;
|
||||||
|
|
||||||
|
Ok(transfer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mine a block ever BLOCK_TIME_SECS seconds.
|
/// Mine a block ever BLOCK_TIME_SECS seconds.
|
||||||
|
@ -4,7 +4,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use digest_auth::AuthContext;
|
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
@ -264,6 +264,24 @@ impl Client {
|
|||||||
let r: Response<GenerateFromKeys> = serde_json::from_str(&response)?;
|
let r: Response<GenerateFromKeys> = serde_json::from_str(&response)?;
|
||||||
Ok(r.result)
|
Ok(r.result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn refresh(&self) -> Result<Refreshed> {
|
||||||
|
let request = Request::new("refresh", "");
|
||||||
|
|
||||||
|
let response = self
|
||||||
|
.inner
|
||||||
|
.post(self.url.clone())
|
||||||
|
.json(&request)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
debug!("refresh RPC response: {}", response);
|
||||||
|
|
||||||
|
let r: Response<Refreshed> = serde_json::from_str(&response)?;
|
||||||
|
Ok(r.result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
@ -393,3 +411,9 @@ pub struct GenerateFromKeys {
|
|||||||
pub address: String,
|
pub address: String,
|
||||||
pub info: String,
|
pub info: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, Deserialize)]
|
||||||
|
pub struct Refreshed {
|
||||||
|
pub blocks_fetched: u32,
|
||||||
|
pub received_money: bool,
|
||||||
|
}
|
||||||
|
@ -3,87 +3,77 @@ use spectral::prelude::*;
|
|||||||
use testcontainers::clients::Cli;
|
use testcontainers::clients::Cli;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn wallet_and_accounts() {
|
async fn fund_transfer_and_check_tx_key() {
|
||||||
let tc = Cli::default();
|
|
||||||
let (monero, _monerod_container) = Monero::new_monerod(&tc).unwrap();
|
|
||||||
let (wallet, _wallet_container) = Monero::new_wallet(&tc, "wallet").unwrap();
|
|
||||||
// let cli = monero.miner_wallet_rpc_client();
|
|
||||||
//
|
|
||||||
// println!("creating wallet ...");
|
|
||||||
//
|
|
||||||
// let _ = cli
|
|
||||||
// .create_wallet("wallet")
|
|
||||||
// .await
|
|
||||||
// .expect("failed to create wallet");
|
|
||||||
//
|
|
||||||
// let got = cli.get_balance(0).await.expect("failed to get balance");
|
|
||||||
// let want = 0;
|
|
||||||
//
|
|
||||||
// assert_that!(got).is_equal_to(want);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::test]
|
|
||||||
async fn create_account_and_retrieve_it() {
|
|
||||||
let tc = Cli::default();
|
|
||||||
let (monero, _container) = Monero::new_monerod(&tc).unwrap();
|
|
||||||
// let cli = monero.miner_wallet_rpc_client();
|
|
||||||
//
|
|
||||||
// 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: u64 = 1_000_000_000_000;
|
let fund_alice: u64 = 1_000_000_000_000;
|
||||||
let fund_bob = 0;
|
let fund_bob = 0;
|
||||||
|
|
||||||
let tc = Cli::default();
|
let tc = Cli::default();
|
||||||
let (monero, _container) = Monero::new_monerod(&tc).unwrap();
|
let (monerod, _monerod_container) = Monero::new_monerod(&tc).unwrap();
|
||||||
// let _ = monero.init(fund_alice, fund_bob).await;
|
|
||||||
//
|
let (miner_wallet, _wallet_container) = Monero::new_wallet(&tc, "miner").await.unwrap();
|
||||||
// let address_bob = monero
|
let (alice_wallet, _alice_wallet_container) = Monero::new_wallet(&tc, "alice").await.unwrap();
|
||||||
// .bob_wallet_rpc_client()
|
let (bob_wallet, _bob_wallet_container) = Monero::new_wallet(&tc, "bob").await.unwrap();
|
||||||
// .get_address(0)
|
|
||||||
// .await
|
let address = miner_wallet
|
||||||
// .expect("failed to get Bob's address")
|
.wallet_rpc_client()
|
||||||
// .address;
|
.get_address(0)
|
||||||
//
|
.await
|
||||||
// let transfer_amount = 100;
|
.unwrap()
|
||||||
// let transfer = monero
|
.address;
|
||||||
// .alice_wallet_rpc_client()
|
|
||||||
// .transfer(0, transfer_amount, &address_bob)
|
monerod.start_miner(&address).await.unwrap();
|
||||||
// .await
|
|
||||||
// .expect("transfer failed");
|
let block_height = monerod
|
||||||
//
|
.monerod_rpc_client()
|
||||||
// let tx_id = transfer.tx_hash;
|
.get_block_count()
|
||||||
// let tx_key = transfer.tx_key;
|
.await
|
||||||
//
|
.unwrap();
|
||||||
// let cli = monero.miner_wallet_rpc_client();
|
|
||||||
// let res = cli
|
miner_wallet
|
||||||
// .check_tx_key(&tx_id, &tx_key, &address_bob)
|
.wait_for_wallet_height(block_height)
|
||||||
// .await
|
.await
|
||||||
// .expect("failed to check tx by key");
|
.unwrap();
|
||||||
//
|
|
||||||
// assert_that!(res.received).is_equal_to(transfer_amount);
|
let alice_address = alice_wallet
|
||||||
|
.wallet_rpc_client()
|
||||||
|
.get_address(0)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.address;
|
||||||
|
|
||||||
|
let transfer = miner_wallet
|
||||||
|
.transfer(&alice_address, fund_alice)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
monerod
|
||||||
|
.monerod_rpc_client()
|
||||||
|
.generate_blocks(10, &address)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let refreshed = alice_wallet.wallet_rpc_client().refresh().await.unwrap();
|
||||||
|
assert_that(&refreshed.received_money).is_true();
|
||||||
|
|
||||||
|
let got_alice_balance = alice_wallet
|
||||||
|
.wallet_rpc_client()
|
||||||
|
.get_balance(0)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let got_bob_balance = bob_wallet.wallet_rpc_client().get_balance(0).await.unwrap();
|
||||||
|
|
||||||
|
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
||||||
|
assert_that(&got_bob_balance).is_equal_to(fund_bob);
|
||||||
|
|
||||||
|
let tx_id = transfer.tx_hash;
|
||||||
|
let tx_key = transfer.tx_key;
|
||||||
|
|
||||||
|
let res = alice_wallet
|
||||||
|
.wallet_rpc_client()
|
||||||
|
.check_tx_key(&tx_id, &tx_key, &alice_address)
|
||||||
|
.await
|
||||||
|
.expect("failed to check tx by key");
|
||||||
|
|
||||||
|
assert_that!(res.received).is_equal_to(fund_alice);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user