From 9e3ef7ea24ff7d69035b82237c6dc56e8316fff1 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Tue, 19 Jan 2021 14:48:07 +1100 Subject: [PATCH] Remove `StartingBalances` from release code --- swap/src/main.rs | 23 ++++++----------------- swap/src/protocol/alice.rs | 3 --- swap/tests/testutils/mod.rs | 28 +++++++++++++--------------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/swap/src/main.rs b/swap/src/main.rs index 7a1bfc22..b139e95b 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -67,7 +67,7 @@ async fn main() -> Result<()> { btc: receive_bitcoin, }; - let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets( + let (bitcoin_wallet, monero_wallet) = setup_wallets( bitcoind_url, bitcoin_wallet_name.as_str(), monero_wallet_rpc_url, @@ -88,7 +88,6 @@ async fn main() -> Result<()> { swap_id, bitcoin_wallet, monero_wallet, - starting_balances, db_path, listen_addr, ) @@ -112,7 +111,7 @@ async fn main() -> Result<()> { xmr: receive_monero, }; - let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets( + let (bitcoin_wallet, monero_wallet) = setup_wallets( bitcoind_url, bitcoin_wallet_name.as_str(), monero_wallet_rpc_url, @@ -162,7 +161,7 @@ async fn main() -> Result<()> { monero_wallet_rpc_url, listen_addr, }) => { - let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets( + let (bitcoin_wallet, monero_wallet) = setup_wallets( bitcoind_url, bitcoin_wallet_name.as_str(), monero_wallet_rpc_url, @@ -176,7 +175,6 @@ async fn main() -> Result<()> { swap_id, bitcoin_wallet, monero_wallet, - starting_balances, db_path, listen_addr, ) @@ -194,7 +192,7 @@ async fn main() -> Result<()> { alice_peer_id, alice_addr, }) => { - let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets( + let (bitcoin_wallet, monero_wallet) = setup_wallets( bitcoind_url, bitcoin_wallet_name.as_str(), monero_wallet_rpc_url, @@ -226,11 +224,7 @@ async fn setup_wallets( bitcoin_wallet_name: &str, monero_wallet_rpc_url: url::Url, config: Config, -) -> Result<( - Arc, - Arc, - StartingBalances, -)> { +) -> Result<(Arc, Arc)> { let bitcoin_wallet = swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network) .await?; @@ -249,10 +243,5 @@ async fn setup_wallets( ); let monero_wallet = Arc::new(monero_wallet); - let starting_balances = StartingBalances { - btc: bitcoin_balance, - xmr: monero_balance, - }; - - Ok((bitcoin_wallet, monero_wallet, starting_balances)) + Ok((bitcoin_wallet, monero_wallet)) } diff --git a/swap/src/protocol/alice.rs b/swap/src/protocol/alice.rs index 4d2a734e..10b80862 100644 --- a/swap/src/protocol/alice.rs +++ b/swap/src/protocol/alice.rs @@ -64,7 +64,6 @@ pub struct SwapFactory { pub bitcoin_wallet: Arc, pub monero_wallet: Arc, - pub starting_balances: StartingBalances, } impl SwapFactory { @@ -75,7 +74,6 @@ impl SwapFactory { swap_id: Uuid, bitcoin_wallet: Arc, monero_wallet: Arc, - starting_balances: StartingBalances, db_path: PathBuf, listen_address: Multiaddr, ) -> Self { @@ -92,7 +90,6 @@ impl SwapFactory { listen_address, bitcoin_wallet, monero_wallet, - starting_balances, } } diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index 185abf33..ac32ff9c 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -19,9 +19,16 @@ use tracing_core::dispatcher::DefaultGuard; use tracing_log::LogTracer; use uuid::Uuid; +#[derive(Debug, Clone)] +pub struct StartingBalances { + pub xmr: monero::Amount, + pub btc: bitcoin::Amount, +} + pub struct TestContext { swap_amounts: SwapAmounts, alice_swap_factory: alice::SwapFactory, + alice_starting_balances: StartingBalances, bob_swap_factory: bob::SwapFactory, bob_starting_balances: StartingBalances, } @@ -79,7 +86,7 @@ impl TestContext { .unwrap(); assert_eq!( btc_balance_after_swap, - self.alice_swap_factory.starting_balances.btc + self.swap_amounts.btc + self.alice_starting_balances.btc + self.swap_amounts.btc - bitcoin::Amount::from_sat(bitcoin::TX_FEE) ); @@ -90,10 +97,7 @@ impl TestContext { .get_balance() .await .unwrap(); - assert!( - xmr_balance_after_swap - <= self.alice_swap_factory.starting_balances.xmr - self.swap_amounts.xmr - ); + assert!(xmr_balance_after_swap <= self.alice_starting_balances.xmr - self.swap_amounts.xmr); } pub async fn assert_alice_refunded(&self, state: AliceState) { @@ -106,10 +110,7 @@ impl TestContext { .balance() .await .unwrap(); - assert_eq!( - btc_balance_after_swap, - self.alice_swap_factory.starting_balances.btc - ); + assert_eq!(btc_balance_after_swap, self.alice_starting_balances.btc); // Ensure that Alice's balance is refreshed as we use a newly created wallet self.alice_swap_factory @@ -141,7 +142,7 @@ impl TestContext { .unwrap(); assert_eq!( btc_balance_after_swap, - self.alice_swap_factory.starting_balances.btc + self.swap_amounts.btc + self.alice_starting_balances.btc + self.swap_amounts.btc - bitcoin::Amount::from_sat(2 * bitcoin::TX_FEE) ); @@ -152,10 +153,7 @@ impl TestContext { .get_balance() .await .unwrap(); - assert!( - xmr_balance_after_swap - <= self.alice_swap_factory.starting_balances.xmr - self.swap_amounts.xmr - ); + assert!(xmr_balance_after_swap <= self.alice_starting_balances.xmr - self.swap_amounts.xmr); } pub async fn assert_bob_redeemed(&self, state: BobState) { @@ -331,7 +329,6 @@ where Uuid::new_v4(), alice_bitcoin_wallet, alice_monero_wallet, - alice_starting_balances, tempdir().unwrap().path().to_path_buf(), listen_address, ) @@ -364,6 +361,7 @@ where let test = TestContext { swap_amounts, alice_swap_factory, + alice_starting_balances, bob_swap_factory, bob_starting_balances, };