mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-01 11:06:13 -04:00
Merge #261
261: Sweep xmr funds from generated temp wallet r=da-kami a=da-kami Fixes #252 Please review by commit :) Did a few cleanups before actually doing the feature. Please note the comment that influenced this solution: https://github.com/comit-network/xmr-btc-swap/issues/252#issuecomment-789387074 Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
commit
cba9f119b6
16 changed files with 326 additions and 341 deletions
|
@ -33,7 +33,9 @@ use tracing_log::LogTracer;
|
|||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
const TEST_WALLET_NAME: &str = "testwallet";
|
||||
const MONERO_WALLET_NAME_BOB: &str = "bob";
|
||||
const MONERO_WALLET_NAME_ALICE: &str = "alice";
|
||||
const BITCOIN_TEST_WALLET_NAME: &str = "testwallet";
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StartingBalances {
|
||||
|
@ -54,15 +56,18 @@ struct BobParams {
|
|||
}
|
||||
|
||||
impl BobParams {
|
||||
pub fn builder(&self, event_loop_handle: bob::EventLoopHandle) -> bob::Builder {
|
||||
bob::Builder::new(
|
||||
pub async fn builder(&self, event_loop_handle: bob::EventLoopHandle) -> Result<bob::Builder> {
|
||||
let receive_address = self.monero_wallet.get_main_address().await?;
|
||||
|
||||
Ok(bob::Builder::new(
|
||||
Database::open(&self.db_path.clone().as_path()).unwrap(),
|
||||
self.swap_id,
|
||||
self.bitcoin_wallet.clone(),
|
||||
self.monero_wallet.clone(),
|
||||
self.execution_params,
|
||||
event_loop_handle,
|
||||
)
|
||||
receive_address,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn new_eventloop(&self) -> Result<(bob::EventLoop, bob::EventLoopHandle)> {
|
||||
|
@ -107,6 +112,8 @@ impl TestContext {
|
|||
let swap = self
|
||||
.bob_params
|
||||
.builder(event_loop_handle)
|
||||
.await
|
||||
.unwrap()
|
||||
.with_init_params(self.btc_amount)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
@ -124,7 +131,13 @@ impl TestContext {
|
|||
|
||||
let (event_loop, event_loop_handle) = self.bob_params.new_eventloop().unwrap();
|
||||
|
||||
let swap = self.bob_params.builder(event_loop_handle).build().unwrap();
|
||||
let swap = self
|
||||
.bob_params
|
||||
.builder(event_loop_handle)
|
||||
.await
|
||||
.unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
let join_handle = tokio::spawn(event_loop.run());
|
||||
|
||||
|
@ -237,13 +250,15 @@ impl TestContext {
|
|||
self.bob_starting_balances.btc - self.btc_amount - lock_tx_bitcoin_fee
|
||||
);
|
||||
|
||||
// unload the generated wallet by opening the original wallet
|
||||
self.bob_monero_wallet.open().await.unwrap();
|
||||
// refresh the original wallet to make sure the balance is caught up
|
||||
self.bob_monero_wallet.refresh().await.unwrap();
|
||||
|
||||
// Ensure that Bob's balance is refreshed as we use a newly created wallet
|
||||
self.bob_monero_wallet.as_ref().refresh().await.unwrap();
|
||||
let xmr_balance_after_swap = self.bob_monero_wallet.as_ref().get_balance().await.unwrap();
|
||||
assert_eq!(
|
||||
xmr_balance_after_swap,
|
||||
self.bob_starting_balances.xmr + self.xmr_amount
|
||||
);
|
||||
assert!(xmr_balance_after_swap > self.bob_starting_balances.xmr);
|
||||
}
|
||||
|
||||
pub async fn assert_bob_refunded(&self, state: BobState) {
|
||||
|
@ -353,7 +368,7 @@ where
|
|||
let bob_seed = Seed::random().unwrap();
|
||||
|
||||
let (alice_bitcoin_wallet, alice_monero_wallet) = init_test_wallets(
|
||||
"alice",
|
||||
MONERO_WALLET_NAME_ALICE,
|
||||
containers.bitcoind_url.clone(),
|
||||
&monero,
|
||||
alice_starting_balances.clone(),
|
||||
|
@ -375,7 +390,7 @@ where
|
|||
};
|
||||
|
||||
let (bob_bitcoin_wallet, bob_monero_wallet) = init_test_wallets(
|
||||
"bob",
|
||||
MONERO_WALLET_NAME_BOB,
|
||||
containers.bitcoind_url,
|
||||
&monero,
|
||||
bob_starting_balances.clone(),
|
||||
|
@ -529,11 +544,11 @@ async fn init_bitcoind(node_url: Url, spendable_quantity: u32) -> Result<Client>
|
|||
let bitcoind_client = Client::new(node_url.clone());
|
||||
|
||||
bitcoind_client
|
||||
.createwallet(TEST_WALLET_NAME, None, None, None, None)
|
||||
.createwallet(BITCOIN_TEST_WALLET_NAME, None, None, None, None)
|
||||
.await?;
|
||||
|
||||
let reward_address = bitcoind_client
|
||||
.with_wallet(TEST_WALLET_NAME)?
|
||||
.with_wallet(BITCOIN_TEST_WALLET_NAME)?
|
||||
.getnewaddress(None, None)
|
||||
.await?;
|
||||
|
||||
|
@ -550,12 +565,12 @@ pub async fn mint(node_url: Url, address: bitcoin::Address, amount: bitcoin::Amo
|
|||
let bitcoind_client = Client::new(node_url.clone());
|
||||
|
||||
bitcoind_client
|
||||
.send_to_address(TEST_WALLET_NAME, address.clone(), amount)
|
||||
.send_to_address(BITCOIN_TEST_WALLET_NAME, address.clone(), amount)
|
||||
.await?;
|
||||
|
||||
// Confirm the transaction
|
||||
let reward_address = bitcoind_client
|
||||
.with_wallet(TEST_WALLET_NAME)?
|
||||
.with_wallet(BITCOIN_TEST_WALLET_NAME)?
|
||||
.getnewaddress(None, None)
|
||||
.await?;
|
||||
bitcoind_client
|
||||
|
@ -571,9 +586,12 @@ async fn init_monero_container(
|
|||
Monero,
|
||||
Vec<Container<'_, Cli, monero_harness::image::Monero>>,
|
||||
) {
|
||||
let (monero, monerods) = Monero::new(&cli, None, vec!["alice".to_string(), "bob".to_string()])
|
||||
.await
|
||||
.unwrap();
|
||||
let (monero, monerods) = Monero::new(&cli, vec![
|
||||
MONERO_WALLET_NAME_ALICE.to_string(),
|
||||
MONERO_WALLET_NAME_BOB.to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
(monero, monerods)
|
||||
}
|
||||
|
@ -597,7 +615,7 @@ async fn init_test_wallets(
|
|||
let xmr_wallet = swap::monero::Wallet::new_with_client(
|
||||
monero.wallet(name).unwrap().client(),
|
||||
monero::Network::default(),
|
||||
"irrelevant_for_tests".to_string(),
|
||||
name.to_string(),
|
||||
);
|
||||
|
||||
let electrum_rpc_url = {
|
||||
|
@ -680,18 +698,20 @@ pub fn init_tracing() -> DefaultGuard {
|
|||
let global_filter = tracing::Level::WARN;
|
||||
let swap_filter = tracing::Level::DEBUG;
|
||||
let xmr_btc_filter = tracing::Level::DEBUG;
|
||||
let monero_harness_filter = tracing::Level::INFO;
|
||||
let monero_rpc_filter = tracing::Level::DEBUG;
|
||||
let monero_harness_filter = tracing::Level::DEBUG;
|
||||
let bitcoin_harness_filter = tracing::Level::INFO;
|
||||
let testcontainers_filter = tracing::Level::DEBUG;
|
||||
|
||||
use tracing_subscriber::util::SubscriberInitExt as _;
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(format!(
|
||||
"{},swap={},xmr_btc={},monero_harness={},bitcoin_harness={},testcontainers={}",
|
||||
"{},swap={},xmr_btc={},monero_harness={},monero_rpc={},bitcoin_harness={},testcontainers={}",
|
||||
global_filter,
|
||||
swap_filter,
|
||||
xmr_btc_filter,
|
||||
monero_harness_filter,
|
||||
monero_rpc_filter,
|
||||
bitcoin_harness_filter,
|
||||
testcontainers_filter
|
||||
))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue