mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-18 10:57:21 -05:00
Remove Alice and Bob from utility struct
This commit is contained in:
parent
306176b3e6
commit
f0fbe785c8
@ -113,7 +113,7 @@ impl<'c> Monero {
|
||||
Ok(wallet)
|
||||
}
|
||||
|
||||
pub async fn init(&self, alice_amount: u64, bob_amount: u64) -> Result<()> {
|
||||
pub async fn init(&self, wallet_amount: Vec<(&str, u64)>) -> Result<()> {
|
||||
let miner_wallet = self.wallet("miner")?;
|
||||
let miner_address = miner_wallet.address().await?.address;
|
||||
|
||||
@ -123,21 +123,15 @@ impl<'c> Monero {
|
||||
tracing::info!("Generated {:?} blocks", block);
|
||||
miner_wallet.refresh().await?;
|
||||
|
||||
if alice_amount > 0 {
|
||||
let alice_wallet = self.wallet("alice")?;
|
||||
let alice_address = alice_wallet.address().await?.address;
|
||||
miner_wallet.transfer(&alice_address, alice_amount).await?;
|
||||
tracing::info!("Funded alice wallet with {}", alice_amount);
|
||||
monerod.inner().generate_blocks(10, &miner_address).await?;
|
||||
alice_wallet.refresh().await?;
|
||||
}
|
||||
if bob_amount > 0 {
|
||||
let bob_wallet = self.wallet("bob")?;
|
||||
let bob_address = bob_wallet.address().await?.address;
|
||||
miner_wallet.transfer(&bob_address, bob_amount).await?;
|
||||
tracing::info!("Funded bob wallet with {}", bob_amount);
|
||||
monerod.inner().generate_blocks(10, &miner_address).await?;
|
||||
bob_wallet.refresh().await?;
|
||||
for (wallet, amount) in wallet_amount.iter() {
|
||||
if *amount > 0 {
|
||||
let wallet = self.wallet(wallet)?;
|
||||
let address = wallet.address().await?.address;
|
||||
miner_wallet.transfer(&address, *amount).await?;
|
||||
tracing::info!("Funded {} wallet with {}", wallet.name, amount);
|
||||
monerod.inner().generate_blocks(10, &miner_address).await?;
|
||||
wallet.refresh().await?;
|
||||
}
|
||||
}
|
||||
|
||||
monerod.start_miner(&miner_address).await?;
|
||||
@ -151,30 +145,6 @@ impl<'c> Monero {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn fund(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||
self.transfer("miner", address, amount).await
|
||||
}
|
||||
|
||||
pub async fn transfer_from_alice(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||
self.transfer("alice", address, amount).await
|
||||
}
|
||||
|
||||
pub async fn transfer_from_bob(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||
self.transfer("bob", address, amount).await
|
||||
}
|
||||
|
||||
async fn transfer(&self, from_wallet: &str, address: &str, amount: u64) -> Result<Transfer> {
|
||||
let from = self.wallet(from_wallet)?;
|
||||
let transfer = from.transfer(address, amount).await?;
|
||||
let miner_address = self.wallet("miner")?.address().await?.address;
|
||||
self.monerod
|
||||
.inner()
|
||||
.generate_blocks(10, &miner_address)
|
||||
.await?;
|
||||
from.inner().refresh().await?;
|
||||
Ok(transfer)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@ -292,9 +262,7 @@ impl<'c> MoneroWalletRpc {
|
||||
|
||||
/// Sends amount to address
|
||||
pub async fn transfer(&self, address: &str, amount: u64) -> Result<Transfer> {
|
||||
let transfer = self.inner().transfer(0, amount, address).await?;
|
||||
self.inner().refresh().await?;
|
||||
Ok(transfer)
|
||||
self.inner().transfer(0, amount, address).await
|
||||
}
|
||||
|
||||
pub async fn address(&self) -> Result<GetAddress> {
|
||||
|
@ -9,7 +9,8 @@ async fn init_miner_and_mine_to_miner_address() {
|
||||
let tc = Cli::default();
|
||||
let (monero, _monerod_container) = Monero::new(&tc, None, vec![]).await.unwrap();
|
||||
|
||||
monero.init(0, 0).await.unwrap();
|
||||
monero.init(vec![]).await.unwrap();
|
||||
|
||||
let monerod = monero.monerod();
|
||||
let miner_wallet = monero.wallet("miner").unwrap();
|
||||
|
||||
|
@ -17,23 +17,36 @@ async fn fund_transfer_and_check_tx_key() {
|
||||
.unwrap();
|
||||
let alice_wallet = monero.wallet("alice").unwrap();
|
||||
let bob_wallet = monero.wallet("bob").unwrap();
|
||||
let miner_wallet = monero.wallet("miner").unwrap();
|
||||
|
||||
let miner_address = miner_wallet.address().await.unwrap().address;
|
||||
|
||||
// fund alice
|
||||
monero.init(fund_alice, fund_bob).await.unwrap();
|
||||
monero
|
||||
.init(vec![("alice", fund_alice), ("bob", fund_bob)])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// check alice balance
|
||||
alice_wallet.inner().refresh().await.unwrap();
|
||||
alice_wallet.refresh().await.unwrap();
|
||||
let got_alice_balance = alice_wallet.balance().await.unwrap();
|
||||
assert_that(&got_alice_balance).is_equal_to(fund_alice);
|
||||
|
||||
// transfer from alice to bob
|
||||
let bob_address = bob_wallet.address().await.unwrap().address;
|
||||
let transfer = monero
|
||||
.transfer_from_alice(&bob_address, send_to_bob)
|
||||
let transfer = alice_wallet
|
||||
.transfer(&bob_address, send_to_bob)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
bob_wallet.inner().refresh().await.unwrap();
|
||||
monero
|
||||
.monerod()
|
||||
.inner()
|
||||
.generate_blocks(10, &miner_address)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
bob_wallet.refresh().await.unwrap();
|
||||
let got_bob_balance = bob_wallet.balance().await.unwrap();
|
||||
assert_that(&got_bob_balance).is_equal_to(send_to_bob);
|
||||
|
||||
|
@ -130,7 +130,10 @@ pub async fn init_test(
|
||||
|
||||
let fund_alice = TEN_XMR;
|
||||
let fund_bob = 0;
|
||||
monero.init(fund_alice, fund_bob).await.unwrap();
|
||||
monero
|
||||
.init(vec![("alice", fund_alice), ("bob", fund_bob)])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let alice_monero_wallet = wallet::monero::Wallet(monero.wallet("alice").unwrap().inner());
|
||||
let bob_monero_wallet = wallet::monero::Wallet(monero.wallet("bob").unwrap().inner());
|
||||
|
Loading…
Reference in New Issue
Block a user