Fix usage of StartingBalance in Alice and Bob

This commit is contained in:
Daniel Karzel 2021-01-15 19:03:11 +11:00
parent 87edec0d50
commit 59f9a1c286

View File

@ -22,6 +22,7 @@ use tracing_core::dispatcher::DefaultGuard;
use tracing_log::LogTracer; use tracing_log::LogTracer;
use uuid::Uuid; use uuid::Uuid;
#[derive(Debug, Clone)]
pub struct StartingBalances { pub struct StartingBalances {
pub xmr: monero::Amount, pub xmr: monero::Amount,
pub btc: bitcoin::Amount, pub btc: bitcoin::Amount,
@ -106,16 +107,8 @@ impl AliceHarness {
let db_path = tempdir().unwrap().path().to_path_buf(); let db_path = tempdir().unwrap().path().to_path_buf();
let xmr_starting_balance = swap_amounts.xmr * 10; let (btc_wallet, xmr_wallet) =
let (btc_wallet, xmr_wallet) = init_wallets( init_wallets("alice", bitcoind, monero, starting_balances.clone(), config).await;
"alice",
bitcoind,
monero,
None,
Some(xmr_starting_balance),
config,
)
.await;
// TODO: This should be done by changing the production code // TODO: This should be done by changing the production code
let network_seed = network::Seed::new(seed); let network_seed = network::Seed::new(seed);
@ -228,14 +221,16 @@ where
) )
.await; .await;
let bob_btc_starting_balance = swap_amounts.btc * 10; let bob_starting_balances = StartingBalances {
xmr: monero::Amount::ZERO,
btc: swap_amounts.btc * 10,
};
let (bob_btc_wallet, bob_xmr_wallet) = init_wallets( let (bob_btc_wallet, bob_xmr_wallet) = init_wallets(
"bob", "bob",
&containers.bitcoind, &containers.bitcoind,
&monero, &monero,
Some(bob_btc_starting_balance), bob_starting_balances.clone(),
None,
config, config,
) )
.await; .await;
@ -263,8 +258,8 @@ where
bitcoin_wallet: bob_btc_wallet, bitcoin_wallet: bob_btc_wallet,
monero_wallet: bob_xmr_wallet, monero_wallet: bob_xmr_wallet,
swap_id: Uuid::new_v4(), swap_id: Uuid::new_v4(),
xmr_starting_balance: monero::Amount::ZERO, xmr_starting_balance: bob_starting_balances.xmr,
btc_starting_balance: bob_btc_starting_balance, btc_starting_balance: bob_starting_balances.btc,
}; };
testfn(alice_factory, bob, swap_amounts).await testfn(alice_factory, bob, swap_amounts).await
@ -284,24 +279,13 @@ pub async fn init_wallets(
name: &str, name: &str,
bitcoind: &Bitcoind<'_>, bitcoind: &Bitcoind<'_>,
monero: &Monero, monero: &Monero,
btc_starting_balance: Option<bitcoin::Amount>, starting_balances: StartingBalances,
xmr_starting_balance: Option<monero::Amount>,
config: Config, config: Config,
) -> (Arc<bitcoin::Wallet>, Arc<monero::Wallet>) { ) -> (Arc<bitcoin::Wallet>, Arc<monero::Wallet>) {
match xmr_starting_balance { monero
Some(amount) => { .init(vec![(name, starting_balances.xmr.as_piconero())])
monero .await
.init(vec![(name, amount.as_piconero())]) .unwrap();
.await
.unwrap();
}
None => {
monero
.init(vec![(name, monero::Amount::ZERO.as_piconero())])
.await
.unwrap();
}
};
let xmr_wallet = Arc::new(swap::monero::Wallet { let xmr_wallet = Arc::new(swap::monero::Wallet {
inner: monero.wallet(name).unwrap().client(), inner: monero.wallet(name).unwrap().client(),
@ -314,9 +298,12 @@ pub async fn init_wallets(
.unwrap(), .unwrap(),
); );
if let Some(amount) = btc_starting_balance { if starting_balances.btc != bitcoin::Amount::ZERO {
bitcoind bitcoind
.mint(btc_wallet.inner.new_address().await.unwrap(), amount) .mint(
btc_wallet.inner.new_address().await.unwrap(),
starting_balances.btc,
)
.await .await
.unwrap(); .unwrap();
} }
@ -391,8 +378,10 @@ pub async fn init_alice(
"alice", "alice",
bitcoind, bitcoind,
monero, monero,
None, StartingBalances {
Some(xmr_starting_balance), xmr: xmr_starting_balance,
btc: bitcoin::Amount::ZERO,
},
config, config,
) )
.await; .await;
@ -473,8 +462,10 @@ pub async fn init_bob(
"bob", "bob",
bitcoind, bitcoind,
monero, monero,
Some(btc_starting_balance), StartingBalances {
None, xmr: monero::Amount::ZERO,
btc: btc_starting_balance,
},
config, config,
) )
.await; .await;