Remove unecessary fields from bob::SwapFactory

This commit is contained in:
Franck Royer 2021-01-19 14:36:24 +11:00
parent 3c68026cfe
commit e26629b593
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 15 additions and 36 deletions

View File

@ -112,7 +112,7 @@ async fn main() -> Result<()> {
xmr: receive_monero, xmr: receive_monero,
}; };
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets( let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets(
bitcoind_url, bitcoind_url,
bitcoin_wallet_name.as_str(), bitcoin_wallet_name.as_str(),
monero_wallet_rpc_url, monero_wallet_rpc_url,
@ -133,12 +133,10 @@ async fn main() -> Result<()> {
swap_id, swap_id,
bitcoin_wallet, bitcoin_wallet,
monero_wallet, monero_wallet,
config,
starting_balances,
alice_addr, alice_addr,
alice_peer_id, alice_peer_id,
); );
let (swap, event_loop) = bob_factory.new_swap_as_bob(swap_amounts).await?; let (swap, event_loop) = bob_factory.new_swap_as_bob(swap_amounts, config).await?;
tokio::spawn(async move { event_loop.run().await }); tokio::spawn(async move { event_loop.run().await });
bob::run(swap).await?; bob::run(swap).await?;
@ -196,7 +194,7 @@ async fn main() -> Result<()> {
alice_peer_id, alice_peer_id,
alice_addr, alice_addr,
}) => { }) => {
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets( let (bitcoin_wallet, monero_wallet, _starting_balances) = setup_wallets(
bitcoind_url, bitcoind_url,
bitcoin_wallet_name.as_str(), bitcoin_wallet_name.as_str(),
monero_wallet_rpc_url, monero_wallet_rpc_url,
@ -210,8 +208,6 @@ async fn main() -> Result<()> {
swap_id, swap_id,
bitcoin_wallet, bitcoin_wallet,
monero_wallet, monero_wallet,
config,
starting_balances,
alice_addr, alice_addr,
alice_peer_id, alice_peer_id,
); );

View File

@ -55,26 +55,21 @@ pub struct SwapFactory {
identity: Keypair, identity: Keypair,
peer_id: PeerId, peer_id: PeerId,
db_path: PathBuf, db_path: PathBuf,
config: Config,
alice_connect_address: Multiaddr, alice_connect_address: Multiaddr,
alice_connect_peer_id: PeerId, alice_connect_peer_id: PeerId,
pub bitcoin_wallet: Arc<bitcoin::Wallet>, pub bitcoin_wallet: Arc<bitcoin::Wallet>,
pub monero_wallet: Arc<monero::Wallet>, pub monero_wallet: Arc<monero::Wallet>,
pub starting_balances: StartingBalances,
} }
impl SwapFactory { impl SwapFactory {
#[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
seed: Seed, seed: Seed,
db_path: PathBuf, db_path: PathBuf,
swap_id: Uuid, swap_id: Uuid,
bitcoin_wallet: Arc<bitcoin::Wallet>, bitcoin_wallet: Arc<bitcoin::Wallet>,
monero_wallet: Arc<monero::Wallet>, monero_wallet: Arc<monero::Wallet>,
config: Config,
starting_balances: StartingBalances,
alice_connect_address: Multiaddr, alice_connect_address: Multiaddr,
alice_connect_peer_id: PeerId, alice_connect_peer_id: PeerId,
) -> Self { ) -> Self {
@ -86,24 +81,23 @@ impl SwapFactory {
identity, identity,
peer_id, peer_id,
db_path, db_path,
config,
alice_connect_address, alice_connect_address,
alice_connect_peer_id, alice_connect_peer_id,
bitcoin_wallet, bitcoin_wallet,
monero_wallet, monero_wallet,
starting_balances,
} }
} }
pub async fn new_swap_as_bob( pub async fn new_swap_as_bob(
&self, &self,
swap_amounts: SwapAmounts, swap_amounts: SwapAmounts,
config: Config,
) -> Result<(bob::Swap, bob::EventLoop)> { ) -> Result<(bob::Swap, bob::EventLoop)> {
let initial_state = init_bob_state( let initial_state = init_bob_state(
swap_amounts.btc, swap_amounts.btc,
swap_amounts.xmr, swap_amounts.xmr,
self.bitcoin_wallet.clone(), self.bitcoin_wallet.clone(),
self.config, config,
) )
.await?; .await?;

View File

@ -21,9 +21,9 @@ use uuid::Uuid;
pub struct TestContext { pub struct TestContext {
swap_amounts: SwapAmounts, swap_amounts: SwapAmounts,
alice_swap_factory: alice::SwapFactory, alice_swap_factory: alice::SwapFactory,
bob_swap_factory: bob::SwapFactory, bob_swap_factory: bob::SwapFactory,
bob_starting_balances: StartingBalances,
} }
impl TestContext { impl TestContext {
@ -42,7 +42,7 @@ impl TestContext {
pub async fn new_swap_as_bob(&self) -> bob::Swap { pub async fn new_swap_as_bob(&self) -> bob::Swap {
let (swap, event_loop) = self let (swap, event_loop) = self
.bob_swap_factory .bob_swap_factory
.new_swap_as_bob(self.swap_amounts) .new_swap_as_bob(self.swap_amounts, Config::regtest())
.await .await
.unwrap(); .unwrap();
@ -185,9 +185,7 @@ impl TestContext {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
btc_balance_after_swap, btc_balance_after_swap,
self.bob_swap_factory.starting_balances.btc self.bob_starting_balances.btc - self.swap_amounts.btc - lock_tx_bitcoin_fee
- self.swap_amounts.btc
- lock_tx_bitcoin_fee
); );
// Ensure that Bob's balance is refreshed as we use a newly created wallet // Ensure that Bob's balance is refreshed as we use a newly created wallet
@ -207,7 +205,7 @@ impl TestContext {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
xmr_balance_after_swap, xmr_balance_after_swap,
self.bob_swap_factory.starting_balances.xmr + self.swap_amounts.xmr self.bob_starting_balances.xmr + self.swap_amounts.xmr
); );
} }
@ -233,12 +231,12 @@ impl TestContext {
.unwrap(); .unwrap();
let alice_submitted_cancel = btc_balance_after_swap let alice_submitted_cancel = btc_balance_after_swap
== self.bob_swap_factory.starting_balances.btc == self.bob_starting_balances.btc
- lock_tx_bitcoin_fee - lock_tx_bitcoin_fee
- bitcoin::Amount::from_sat(bitcoin::TX_FEE); - bitcoin::Amount::from_sat(bitcoin::TX_FEE);
let bob_submitted_cancel = btc_balance_after_swap let bob_submitted_cancel = btc_balance_after_swap
== self.bob_swap_factory.starting_balances.btc == self.bob_starting_balances.btc
- lock_tx_bitcoin_fee - lock_tx_bitcoin_fee
- bitcoin::Amount::from_sat(2 * bitcoin::TX_FEE); - bitcoin::Amount::from_sat(2 * bitcoin::TX_FEE);
@ -253,10 +251,7 @@ impl TestContext {
.get_balance() .get_balance()
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(xmr_balance_after_swap, self.bob_starting_balances.xmr);
xmr_balance_after_swap,
self.bob_swap_factory.starting_balances.xmr
);
} }
pub async fn assert_bob_punished(&self, state: BobState) { pub async fn assert_bob_punished(&self, state: BobState) {
@ -282,9 +277,7 @@ impl TestContext {
.unwrap(); .unwrap();
assert_eq!( assert_eq!(
btc_balance_after_swap, btc_balance_after_swap,
self.bob_swap_factory.starting_balances.btc self.bob_starting_balances.btc - self.swap_amounts.btc - lock_tx_bitcoin_fee
- self.swap_amounts.btc
- lock_tx_bitcoin_fee
); );
let xmr_balance_after_swap = self let xmr_balance_after_swap = self
@ -294,10 +287,7 @@ impl TestContext {
.get_balance() .get_balance()
.await .await
.unwrap(); .unwrap();
assert_eq!( assert_eq!(xmr_balance_after_swap, self.bob_starting_balances.xmr);
xmr_balance_after_swap,
self.bob_swap_factory.starting_balances.xmr
);
} }
} }
@ -371,8 +361,6 @@ where
Uuid::new_v4(), Uuid::new_v4(),
bob_bitcoin_wallet, bob_bitcoin_wallet,
bob_monero_wallet, bob_monero_wallet,
config,
bob_starting_balances,
alice_swap_factory.listen_address(), alice_swap_factory.listen_address(),
alice_swap_factory.peer_id(), alice_swap_factory.peer_id(),
); );
@ -381,6 +369,7 @@ where
swap_amounts, swap_amounts,
alice_swap_factory, alice_swap_factory,
bob_swap_factory, bob_swap_factory,
bob_starting_balances,
}; };
testfn(test).await testfn(test).await