mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Remove StartingBalances
from release code
This commit is contained in:
parent
181999e04f
commit
9e3ef7ea24
@ -67,7 +67,7 @@ async fn main() -> Result<()> {
|
|||||||
btc: receive_bitcoin,
|
btc: receive_bitcoin,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets(
|
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
monero_wallet_rpc_url,
|
monero_wallet_rpc_url,
|
||||||
@ -88,7 +88,6 @@ async fn main() -> Result<()> {
|
|||||||
swap_id,
|
swap_id,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
starting_balances,
|
|
||||||
db_path,
|
db_path,
|
||||||
listen_addr,
|
listen_addr,
|
||||||
)
|
)
|
||||||
@ -112,7 +111,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) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
monero_wallet_rpc_url,
|
monero_wallet_rpc_url,
|
||||||
@ -162,7 +161,7 @@ async fn main() -> Result<()> {
|
|||||||
monero_wallet_rpc_url,
|
monero_wallet_rpc_url,
|
||||||
listen_addr,
|
listen_addr,
|
||||||
}) => {
|
}) => {
|
||||||
let (bitcoin_wallet, monero_wallet, starting_balances) = setup_wallets(
|
let (bitcoin_wallet, monero_wallet) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
monero_wallet_rpc_url,
|
monero_wallet_rpc_url,
|
||||||
@ -176,7 +175,6 @@ async fn main() -> Result<()> {
|
|||||||
swap_id,
|
swap_id,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
starting_balances,
|
|
||||||
db_path,
|
db_path,
|
||||||
listen_addr,
|
listen_addr,
|
||||||
)
|
)
|
||||||
@ -194,7 +192,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) = setup_wallets(
|
||||||
bitcoind_url,
|
bitcoind_url,
|
||||||
bitcoin_wallet_name.as_str(),
|
bitcoin_wallet_name.as_str(),
|
||||||
monero_wallet_rpc_url,
|
monero_wallet_rpc_url,
|
||||||
@ -226,11 +224,7 @@ async fn setup_wallets(
|
|||||||
bitcoin_wallet_name: &str,
|
bitcoin_wallet_name: &str,
|
||||||
monero_wallet_rpc_url: url::Url,
|
monero_wallet_rpc_url: url::Url,
|
||||||
config: Config,
|
config: Config,
|
||||||
) -> Result<(
|
) -> Result<(Arc<swap::bitcoin::Wallet>, Arc<swap::monero::Wallet>)> {
|
||||||
Arc<swap::bitcoin::Wallet>,
|
|
||||||
Arc<swap::monero::Wallet>,
|
|
||||||
StartingBalances,
|
|
||||||
)> {
|
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet =
|
||||||
swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network)
|
swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network)
|
||||||
.await?;
|
.await?;
|
||||||
@ -249,10 +243,5 @@ async fn setup_wallets(
|
|||||||
);
|
);
|
||||||
let monero_wallet = Arc::new(monero_wallet);
|
let monero_wallet = Arc::new(monero_wallet);
|
||||||
|
|
||||||
let starting_balances = StartingBalances {
|
Ok((bitcoin_wallet, monero_wallet))
|
||||||
btc: bitcoin_balance,
|
|
||||||
xmr: monero_balance,
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((bitcoin_wallet, monero_wallet, starting_balances))
|
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,6 @@ pub struct SwapFactory {
|
|||||||
|
|
||||||
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 {
|
||||||
@ -75,7 +74,6 @@ impl SwapFactory {
|
|||||||
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>,
|
||||||
starting_balances: StartingBalances,
|
|
||||||
db_path: PathBuf,
|
db_path: PathBuf,
|
||||||
listen_address: Multiaddr,
|
listen_address: Multiaddr,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -92,7 +90,6 @@ impl SwapFactory {
|
|||||||
listen_address,
|
listen_address,
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
monero_wallet,
|
monero_wallet,
|
||||||
starting_balances,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,16 @@ 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 xmr: monero::Amount,
|
||||||
|
pub btc: bitcoin::Amount,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct TestContext {
|
pub struct TestContext {
|
||||||
swap_amounts: SwapAmounts,
|
swap_amounts: SwapAmounts,
|
||||||
alice_swap_factory: alice::SwapFactory,
|
alice_swap_factory: alice::SwapFactory,
|
||||||
|
alice_starting_balances: StartingBalances,
|
||||||
bob_swap_factory: bob::SwapFactory,
|
bob_swap_factory: bob::SwapFactory,
|
||||||
bob_starting_balances: StartingBalances,
|
bob_starting_balances: StartingBalances,
|
||||||
}
|
}
|
||||||
@ -79,7 +86,7 @@ impl TestContext {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
btc_balance_after_swap,
|
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)
|
- bitcoin::Amount::from_sat(bitcoin::TX_FEE)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -90,10 +97,7 @@ impl TestContext {
|
|||||||
.get_balance()
|
.get_balance()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(
|
assert!(xmr_balance_after_swap <= self.alice_starting_balances.xmr - self.swap_amounts.xmr);
|
||||||
xmr_balance_after_swap
|
|
||||||
<= self.alice_swap_factory.starting_balances.xmr - self.swap_amounts.xmr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn assert_alice_refunded(&self, state: AliceState) {
|
pub async fn assert_alice_refunded(&self, state: AliceState) {
|
||||||
@ -106,10 +110,7 @@ impl TestContext {
|
|||||||
.balance()
|
.balance()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(btc_balance_after_swap, self.alice_starting_balances.btc);
|
||||||
btc_balance_after_swap,
|
|
||||||
self.alice_swap_factory.starting_balances.btc
|
|
||||||
);
|
|
||||||
|
|
||||||
// Ensure that Alice's balance is refreshed as we use a newly created wallet
|
// Ensure that Alice's balance is refreshed as we use a newly created wallet
|
||||||
self.alice_swap_factory
|
self.alice_swap_factory
|
||||||
@ -141,7 +142,7 @@ impl TestContext {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
btc_balance_after_swap,
|
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)
|
- bitcoin::Amount::from_sat(2 * bitcoin::TX_FEE)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -152,10 +153,7 @@ impl TestContext {
|
|||||||
.get_balance()
|
.get_balance()
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(
|
assert!(xmr_balance_after_swap <= self.alice_starting_balances.xmr - self.swap_amounts.xmr);
|
||||||
xmr_balance_after_swap
|
|
||||||
<= self.alice_swap_factory.starting_balances.xmr - self.swap_amounts.xmr
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn assert_bob_redeemed(&self, state: BobState) {
|
pub async fn assert_bob_redeemed(&self, state: BobState) {
|
||||||
@ -331,7 +329,6 @@ where
|
|||||||
Uuid::new_v4(),
|
Uuid::new_v4(),
|
||||||
alice_bitcoin_wallet,
|
alice_bitcoin_wallet,
|
||||||
alice_monero_wallet,
|
alice_monero_wallet,
|
||||||
alice_starting_balances,
|
|
||||||
tempdir().unwrap().path().to_path_buf(),
|
tempdir().unwrap().path().to_path_buf(),
|
||||||
listen_address,
|
listen_address,
|
||||||
)
|
)
|
||||||
@ -364,6 +361,7 @@ where
|
|||||||
let test = TestContext {
|
let test = TestContext {
|
||||||
swap_amounts,
|
swap_amounts,
|
||||||
alice_swap_factory,
|
alice_swap_factory,
|
||||||
|
alice_starting_balances,
|
||||||
bob_swap_factory,
|
bob_swap_factory,
|
||||||
bob_starting_balances,
|
bob_starting_balances,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user