mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 22:42:35 -04:00
Remove lib
Removed lib and moved the tests into a src folder. Moved the types in the lib to appropriate modules.
This commit is contained in:
parent
485220929e
commit
7d8fe742e8
24 changed files with 172 additions and 218 deletions
|
@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks};
|
use crate::{bitcoin::timelocks::BlockHeight, config::Config, protocol::ExpiredTimelocks};
|
||||||
|
|
||||||
pub use crate::bitcoin::{
|
pub use crate::bitcoin::{
|
||||||
timelocks::Timelock,
|
timelocks::Timelock,
|
||||||
|
|
|
@ -36,6 +36,7 @@ impl Display for Swap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Database(sled::Db);
|
pub struct Database(sled::Db);
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
|
|
|
@ -5,8 +5,7 @@ use crate::{
|
||||||
bitcoin::{EncryptedSignature, TxCancel, TxRefund},
|
bitcoin::{EncryptedSignature, TxCancel, TxRefund},
|
||||||
monero,
|
monero,
|
||||||
monero::monero_private_key,
|
monero::monero_private_key,
|
||||||
protocol::{alice, alice::AliceState},
|
protocol::{alice, alice::AliceState, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Large enum variant is fine because this is only used for database
|
// Large enum variant is fine because this is only used for database
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
use ::bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::protocol::{bob, bob::BobState, SwapAmounts};
|
||||||
protocol::{bob, bob::BobState},
|
|
||||||
SwapAmounts,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
pub enum Bob {
|
pub enum Bob {
|
||||||
|
|
|
@ -1,77 +0,0 @@
|
||||||
#![warn(
|
|
||||||
unused_extern_crates,
|
|
||||||
rust_2018_idioms,
|
|
||||||
clippy::cast_possible_truncation,
|
|
||||||
clippy::cast_sign_loss,
|
|
||||||
clippy::fallible_impl_from,
|
|
||||||
clippy::cast_precision_loss,
|
|
||||||
clippy::cast_possible_wrap,
|
|
||||||
clippy::dbg_macro
|
|
||||||
)]
|
|
||||||
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
|
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![allow(
|
|
||||||
non_snake_case,
|
|
||||||
missing_debug_implementations,
|
|
||||||
missing_copy_implementations
|
|
||||||
)]
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::fmt::{self, Display};
|
|
||||||
|
|
||||||
pub mod bitcoin;
|
|
||||||
pub mod cli;
|
|
||||||
pub mod config;
|
|
||||||
pub mod database;
|
|
||||||
pub mod fs;
|
|
||||||
pub mod monero;
|
|
||||||
pub mod network;
|
|
||||||
pub mod protocol;
|
|
||||||
pub mod seed;
|
|
||||||
pub mod trace;
|
|
||||||
|
|
||||||
pub type Never = std::convert::Infallible;
|
|
||||||
|
|
||||||
/// Commands sent from Bob to the main task.
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub enum Cmd {
|
|
||||||
VerifyAmounts(SwapAmounts),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Responses sent from the main task back to Bob.
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
|
||||||
pub enum Rsp {
|
|
||||||
VerifiedAmounts,
|
|
||||||
Abort,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// XMR/BTC swap amounts.
|
|
||||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
|
||||||
// TODO(Franck): review necessity of this struct
|
|
||||||
pub struct SwapAmounts {
|
|
||||||
/// Amount of BTC to swap.
|
|
||||||
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
|
||||||
pub btc: bitcoin::Amount,
|
|
||||||
/// Amount of XMR to swap.
|
|
||||||
#[serde(with = "monero::monero_amount")]
|
|
||||||
pub xmr: monero::Amount,
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Display in XMR and BTC (not picos and sats).
|
|
||||||
impl Display for SwapAmounts {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(
|
|
||||||
f,
|
|
||||||
"{} sats for {} piconeros",
|
|
||||||
self.btc.as_sat(),
|
|
||||||
self.xmr.as_piconero()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum ExpiredTimelocks {
|
|
||||||
None,
|
|
||||||
Cancel,
|
|
||||||
Punish,
|
|
||||||
}
|
|
|
@ -14,26 +14,31 @@
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
use anyhow::{bail, Context, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
|
use cli::{Command, Options, Resume};
|
||||||
|
use config::Config;
|
||||||
|
use database::{Database, Swap};
|
||||||
use libp2p::{core::Multiaddr, PeerId};
|
use libp2p::{core::Multiaddr, PeerId};
|
||||||
|
use network::transport::build;
|
||||||
use prettytable::{row, Table};
|
use prettytable::{row, Table};
|
||||||
|
use protocol::{alice, alice::AliceState, bob, bob::BobState, SwapAmounts};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use swap::{
|
use trace::init_tracing;
|
||||||
bitcoin,
|
|
||||||
cli::{Command, Options, Resume},
|
|
||||||
config::Config,
|
|
||||||
database::{Database, Swap},
|
|
||||||
monero, network,
|
|
||||||
network::transport::build,
|
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
|
||||||
seed::Seed,
|
|
||||||
trace::init_tracing,
|
|
||||||
SwapAmounts,
|
|
||||||
};
|
|
||||||
use tracing::{info, log::LevelFilter};
|
use tracing::{info, log::LevelFilter};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
pub mod bitcoin;
|
||||||
|
pub mod cli;
|
||||||
|
pub mod config;
|
||||||
|
pub mod database;
|
||||||
|
pub mod monero;
|
||||||
|
pub mod network;
|
||||||
|
pub mod protocol;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
pub mod trace;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
|
||||||
|
@ -258,10 +263,9 @@ 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<(Arc<swap::bitcoin::Wallet>, Arc<swap::monero::Wallet>)> {
|
) -> Result<(Arc<bitcoin::Wallet>, Arc<monero::Wallet>)> {
|
||||||
let bitcoin_wallet =
|
let bitcoin_wallet =
|
||||||
swap::bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network)
|
bitcoin::Wallet::new(bitcoin_wallet_name, bitcoind_url, config.bitcoin_network).await?;
|
||||||
.await?;
|
|
||||||
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
let bitcoin_balance = bitcoin_wallet.balance().await?;
|
||||||
info!(
|
info!(
|
||||||
"Connection to Bitcoin wallet succeeded, balance: {}",
|
"Connection to Bitcoin wallet succeeded, balance: {}",
|
||||||
|
@ -284,8 +288,8 @@ async fn alice_swap(
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
state: AliceState,
|
state: AliceState,
|
||||||
listen_addr: Multiaddr,
|
listen_addr: Multiaddr,
|
||||||
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
config: Config,
|
config: Config,
|
||||||
db: Database,
|
db: Database,
|
||||||
seed: Seed,
|
seed: Seed,
|
||||||
|
@ -316,8 +320,8 @@ async fn alice_swap(
|
||||||
async fn bob_swap(
|
async fn bob_swap(
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
state: BobState,
|
state: BobState,
|
||||||
bitcoin_wallet: Arc<swap::bitcoin::Wallet>,
|
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||||
monero_wallet: Arc<swap::monero::Wallet>,
|
monero_wallet: Arc<monero::Wallet>,
|
||||||
db: Database,
|
db: Database,
|
||||||
alice_peer_id: PeerId,
|
alice_peer_id: PeerId,
|
||||||
alice_addr: Multiaddr,
|
alice_addr: Multiaddr,
|
||||||
|
|
|
@ -9,10 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt::Debug, io, marker::PhantomData};
|
use std::{fmt::Debug, io, marker::PhantomData};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::{
|
use crate::protocol::{alice, bob, SwapAmounts};
|
||||||
protocol::{alice, bob},
|
|
||||||
SwapAmounts,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Time to wait for a response back once we send a request.
|
/// Time to wait for a response back once we send a request.
|
||||||
pub const TIMEOUT: u64 = 3600; // One hour.
|
pub const TIMEOUT: u64 = 3600; // One hour.
|
||||||
|
|
|
@ -1,2 +1,37 @@
|
||||||
|
use crate::monero;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fmt::{self, Display};
|
||||||
|
|
||||||
pub mod alice;
|
pub mod alice;
|
||||||
pub mod bob;
|
pub mod bob;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum ExpiredTimelocks {
|
||||||
|
None,
|
||||||
|
Cancel,
|
||||||
|
Punish,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// XMR/BTC swap amounts.
|
||||||
|
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||||
|
// TODO(Franck): review necessity of this struct
|
||||||
|
pub struct SwapAmounts {
|
||||||
|
/// Amount of BTC to swap.
|
||||||
|
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
|
||||||
|
pub btc: bitcoin::Amount,
|
||||||
|
/// Amount of XMR to swap.
|
||||||
|
#[serde(with = "monero::monero_amount")]
|
||||||
|
pub xmr: monero::Amount,
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Display in XMR and BTC (not picos and sats).
|
||||||
|
impl Display for SwapAmounts {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"{} sats for {} piconeros",
|
||||||
|
self.btc.as_sat(),
|
||||||
|
self.xmr.as_piconero()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -15,8 +15,7 @@ use crate::{
|
||||||
transport::SwapTransport,
|
transport::SwapTransport,
|
||||||
Seed, TokioExecutor,
|
Seed, TokioExecutor,
|
||||||
},
|
},
|
||||||
protocol::bob,
|
protocol::{bob, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::{amounts::*, message0::Message0, message1::Message1, message2::Message2, state::*};
|
pub use self::{amounts::*, message0::Message0, message1::Message1, message2::Message2, state::*};
|
||||||
|
|
|
@ -10,9 +10,8 @@ use crate::{
|
||||||
protocol::{
|
protocol::{
|
||||||
alice,
|
alice,
|
||||||
alice::{Behaviour, OutEvent},
|
alice::{Behaviour, OutEvent},
|
||||||
bob,
|
bob, SwapAmounts,
|
||||||
},
|
},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(missing_debug_implementations)]
|
#[allow(missing_debug_implementations)]
|
||||||
|
|
|
@ -19,8 +19,7 @@ use crate::{
|
||||||
monero,
|
monero,
|
||||||
monero::CreateWalletForOutput,
|
monero::CreateWalletForOutput,
|
||||||
network::request_response::AliceToBob,
|
network::request_response::AliceToBob,
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, ExpiredTimelocks, SwapAmounts},
|
||||||
ExpiredTimelocks, SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
|
@ -24,8 +24,7 @@ use crate::{
|
||||||
monero,
|
monero,
|
||||||
monero::Transfer,
|
monero::Transfer,
|
||||||
network::request_response::AliceToBob,
|
network::request_response::AliceToBob,
|
||||||
protocol::{alice, alice::event_loop::EventLoopHandle},
|
protocol::{alice, alice::event_loop::EventLoopHandle, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn negotiate(
|
pub async fn negotiate(
|
||||||
|
|
|
@ -18,17 +18,20 @@ use crate::{
|
||||||
database::{Database, Swap},
|
database::{Database, Swap},
|
||||||
monero,
|
monero,
|
||||||
monero::CreateWalletForOutput,
|
monero::CreateWalletForOutput,
|
||||||
protocol::alice::{
|
protocol::{
|
||||||
event_loop::EventLoopHandle,
|
alice::{
|
||||||
steps::{
|
event_loop::EventLoopHandle,
|
||||||
build_bitcoin_punish_transaction, build_bitcoin_redeem_transaction,
|
steps::{
|
||||||
extract_monero_private_key, lock_xmr, negotiate, publish_bitcoin_punish_transaction,
|
build_bitcoin_punish_transaction, build_bitcoin_redeem_transaction,
|
||||||
publish_bitcoin_redeem_transaction, publish_cancel_transaction,
|
extract_monero_private_key, lock_xmr, negotiate,
|
||||||
wait_for_bitcoin_encrypted_signature, wait_for_bitcoin_refund, wait_for_locked_bitcoin,
|
publish_bitcoin_punish_transaction, publish_bitcoin_redeem_transaction,
|
||||||
|
publish_cancel_transaction, wait_for_bitcoin_encrypted_signature,
|
||||||
|
wait_for_bitcoin_refund, wait_for_locked_bitcoin,
|
||||||
|
},
|
||||||
|
AliceState,
|
||||||
},
|
},
|
||||||
AliceState,
|
ExpiredTimelocks,
|
||||||
},
|
},
|
||||||
ExpiredTimelocks,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
trait Rng: RngCore + CryptoRng + Send {}
|
trait Rng: RngCore + CryptoRng + Send {}
|
||||||
|
|
|
@ -14,8 +14,7 @@ use crate::{
|
||||||
transport::SwapTransport,
|
transport::SwapTransport,
|
||||||
Seed, TokioExecutor,
|
Seed, TokioExecutor,
|
||||||
},
|
},
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
|
|
|
@ -16,7 +16,7 @@ use tracing::{debug, error};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
network::request_response::{AliceToBob, AmountsProtocol, BobToAlice, Codec, TIMEOUT},
|
network::request_response::{AliceToBob, AmountsProtocol, BobToAlice, Codec, TIMEOUT},
|
||||||
SwapAmounts,
|
protocol::SwapAmounts,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
|
|
@ -17,8 +17,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
monero,
|
monero,
|
||||||
monero::monero_private_key,
|
monero::monero_private_key,
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob, ExpiredTimelocks, SwapAmounts},
|
||||||
ExpiredTimelocks, SwapAmounts,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -8,8 +8,10 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::{Database, Swap},
|
database::{Database, Swap},
|
||||||
protocol::bob::{self, event_loop::EventLoopHandle, state::*},
|
protocol::{
|
||||||
ExpiredTimelocks, SwapAmounts,
|
bob::{self, event_loop::EventLoopHandle, state::*},
|
||||||
|
ExpiredTimelocks, SwapAmounts,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(Franck): Make this a method on a struct
|
// TODO(Franck): Make this a method on a struct
|
||||||
|
|
|
@ -3,20 +3,27 @@ use libp2p::{core::Multiaddr, PeerId};
|
||||||
use monero_harness::{image, Monero};
|
use monero_harness::{image, Monero};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use swap::{
|
use tempfile::tempdir;
|
||||||
|
use testcontainers::{clients::Cli, Container};
|
||||||
|
use tracing_core::dispatcher::DefaultGuard;
|
||||||
|
use tracing_log::LogTracer;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero, network,
|
monero, network,
|
||||||
network::transport::build,
|
network::transport::build,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
protocol::{alice, alice::AliceState, bob, bob::BobState,seed::Seed,
|
||||||
seed::Seed,
|
SwapAmounts},
|
||||||
SwapAmounts,
|
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::{clients::Cli, Container};
|
mod happy_path;
|
||||||
use tracing_core::dispatcher::DefaultGuard;
|
mod happy_path_restart_alice;
|
||||||
use tracing_log::LogTracer;
|
mod happy_path_restart_bob_after_comm;
|
||||||
|
mod happy_path_restart_bob_before_comm;
|
||||||
|
mod punish;
|
||||||
|
mod refund_restart_alice;
|
||||||
|
|
||||||
pub async fn init_containers(cli: &Cli) -> (Monero, Containers<'_>) {
|
pub async fn init_containers(cli: &Cli) -> (Monero, Containers<'_>) {
|
||||||
let bitcoind = Bitcoind::new(&cli, "0.19.1").unwrap();
|
let bitcoind = Bitcoind::new(&cli, "0.19.1").unwrap();
|
||||||
|
@ -51,13 +58,13 @@ pub async fn init_wallets(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let xmr_wallet = Arc::new(swap::monero::Wallet {
|
let xmr_wallet = Arc::new(monero::Wallet {
|
||||||
inner: monero.wallet(name).unwrap().client(),
|
inner: monero.wallet(name).unwrap().client(),
|
||||||
network: config.monero_network,
|
network: config.monero_network,
|
||||||
});
|
});
|
||||||
|
|
||||||
let btc_wallet = Arc::new(
|
let btc_wallet = Arc::new(
|
||||||
swap::bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
bitcoin::Wallet::new(name, bitcoind.node_url.clone(), config.bitcoin_network)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
|
@ -131,8 +138,8 @@ pub async fn init_alice(
|
||||||
AliceState,
|
AliceState,
|
||||||
alice::event_loop::EventLoop,
|
alice::event_loop::EventLoop,
|
||||||
alice::event_loop::EventLoopHandle,
|
alice::event_loop::EventLoopHandle,
|
||||||
Arc<swap::bitcoin::Wallet>,
|
Arc<bitcoin::Wallet>,
|
||||||
Arc<swap::monero::Wallet>,
|
Arc<monero::Wallet>,
|
||||||
Database,
|
Database,
|
||||||
) {
|
) {
|
||||||
let (alice_btc_wallet, alice_xmr_wallet) = init_wallets(
|
let (alice_btc_wallet, alice_xmr_wallet) = init_wallets(
|
||||||
|
@ -213,8 +220,8 @@ pub async fn init_bob(
|
||||||
BobState,
|
BobState,
|
||||||
bob::event_loop::EventLoop,
|
bob::event_loop::EventLoop,
|
||||||
bob::event_loop::EventLoopHandle,
|
bob::event_loop::EventLoopHandle,
|
||||||
Arc<swap::bitcoin::Wallet>,
|
Arc<bitcoin::Wallet>,
|
||||||
Arc<swap::monero::Wallet>,
|
Arc<monero::Wallet>,
|
||||||
Database,
|
Database,
|
||||||
) {
|
) {
|
||||||
let (bob_btc_wallet, bob_xmr_wallet) = init_wallets(
|
let (bob_btc_wallet, bob_xmr_wallet) = init_wallets(
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{join, select},
|
future::{join, select},
|
||||||
FutureExt,
|
FutureExt,
|
||||||
|
@ -6,18 +5,17 @@ use futures::{
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use testcontainers::clients::Cli;
|
||||||
|
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
};
|
};
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
/// Run the following tests with RUST_MIN_STACK=10000000
|
/// Run the following tests with RUST_MIN_STACK=10000000
|
||||||
|
|
||||||
|
@ -28,11 +26,11 @@ async fn happy_path() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
tests::Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = tests::init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let btc_alice = bitcoin::Amount::ZERO;
|
let btc_alice = bitcoin::Amount::ZERO;
|
|
@ -1,21 +1,21 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use tempfile::tempdir;
|
||||||
|
use testcontainers::clients::Cli;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
|
database,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob},
|
protocol::{alice, alice::AliceState, bob},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests,
|
||||||
|
tests::{init_alice, init_bob, init_tracing},
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
||||||
|
@ -24,11 +24,11 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
tests::Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = tests::init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
||||||
|
@ -120,15 +120,15 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
||||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
||||||
|
|
||||||
let resume_state =
|
let resume_state =
|
||||||
if let swap::database::Swap::Alice(state) = alice_db.get_state(alice_swap_id).unwrap() {
|
if let database::Swap::Alice(state) = alice_db.get_state(alice_swap_id).unwrap() {
|
||||||
assert!(matches!(state, swap::database::Alice::EncSigLearned {..}));
|
assert!(matches!(state, database::Alice::EncSigLearned {..}));
|
||||||
state.into()
|
state.into()
|
||||||
} else {
|
} else {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_alice_event_loop(alice_multiaddr, alice_seed);
|
tests::init_alice_event_loop(alice_multiaddr, alice_seed);
|
||||||
tokio::spawn(async move { event_loop_after_restart.run().await });
|
tokio::spawn(async move { event_loop_after_restart.run().await });
|
||||||
|
|
||||||
let alice_state = alice::swap::swap(
|
let alice_state = alice::swap::swap(
|
|
@ -1,21 +1,20 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use tempfile::tempdir;
|
||||||
|
use testcontainers::clients::Cli;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
|
database,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, bob, bob::BobState},
|
protocol::{alice, bob, bob::BobState},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests::{init_alice, init_bob, init_bob_event_loop, init_containers, init_tracing, Containers},
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
||||||
|
@ -24,11 +23,11 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
||||||
|
@ -121,16 +120,15 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
||||||
|
|
||||||
let bob_db = Database::open(bob_db_datadir.path()).unwrap();
|
let bob_db = Database::open(bob_db_datadir.path()).unwrap();
|
||||||
|
|
||||||
let resume_state =
|
let resume_state = if let database::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap() {
|
||||||
if let swap::database::Swap::Bob(state) = bob_db.get_state(bob_swap_id).unwrap() {
|
assert!(matches!(state, database::Bob::EncSigSent {..}));
|
||||||
assert!(matches!(state, swap::database::Bob::EncSigSent {..}));
|
state.into()
|
||||||
state.into()
|
} else {
|
||||||
} else {
|
unreachable!()
|
||||||
unreachable!()
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
let (event_loop_after_restart, event_loop_handle_after_restart) =
|
||||||
testutils::init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
||||||
tokio::spawn(event_loop_after_restart.run());
|
tokio::spawn(event_loop_after_restart.run());
|
||||||
|
|
||||||
let bob_state = bob::swap::swap(
|
let bob_state = bob::swap::swap(
|
|
@ -1,22 +1,20 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use tempfile::tempdir;
|
||||||
|
use testcontainers::clients::Cli;
|
||||||
|
use tokio::select;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests::{init_alice, init_bob, init_bob_event_loop, init_containers, init_tracing, Containers},
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use tokio::select;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
||||||
|
@ -25,11 +23,11 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
||||||
|
@ -117,7 +115,7 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (bob_event_loop_2, bob_event_loop_handle_2) =
|
let (bob_event_loop_2, bob_event_loop_handle_2) =
|
||||||
testutils::init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
init_bob_event_loop(alice_peer_id, alice_multiaddr);
|
||||||
|
|
||||||
let bob_fut = bob::swap::swap(
|
let bob_fut = bob::swap::swap(
|
||||||
bob_restart_state,
|
bob_restart_state,
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use futures::{
|
use futures::{
|
||||||
future::{join, select, Either},
|
future::{join, select, Either},
|
||||||
FutureExt,
|
FutureExt,
|
||||||
|
@ -6,18 +5,17 @@ use futures::{
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use testcontainers::clients::Cli;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests::{init_alice, init_bob, init_containers, init_tracing, Containers},
|
||||||
};
|
};
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
/// Bob locks Btc and Alice locks Xmr. Bob does not act; he fails to send Alice
|
/// Bob locks Btc and Alice locks Xmr. Bob does not act; he fails to send Alice
|
||||||
/// the encsig and fail to refund or redeem. Alice punishes.
|
/// the encsig and fail to refund or redeem. Alice punishes.
|
||||||
|
@ -28,11 +26,11 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
|
@ -1,23 +1,23 @@
|
||||||
use crate::testutils::{init_alice, init_bob};
|
|
||||||
use futures::future::try_join;
|
use futures::future::try_join;
|
||||||
use get_port::get_port;
|
use get_port::get_port;
|
||||||
use libp2p::Multiaddr;
|
use libp2p::Multiaddr;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use swap::{
|
use tempfile::tempdir;
|
||||||
|
use testcontainers::clients::Cli;
|
||||||
|
use tokio::select;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
bitcoin,
|
bitcoin,
|
||||||
config::Config,
|
config::Config,
|
||||||
database::Database,
|
database::Database,
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||||
seed::Seed,
|
seed::Seed,
|
||||||
|
tests::{
|
||||||
|
init_alice, init_alice_event_loop, init_bob, init_containers, init_tracing, Containers,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use tempfile::tempdir;
|
|
||||||
use testcontainers::clients::Cli;
|
|
||||||
use testutils::init_tracing;
|
|
||||||
use tokio::select;
|
|
||||||
use uuid::Uuid;
|
|
||||||
|
|
||||||
pub mod testutils;
|
|
||||||
|
|
||||||
// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
|
||||||
// then also refunds.
|
// then also refunds.
|
||||||
|
@ -28,11 +28,11 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (
|
let (
|
||||||
monero,
|
monero,
|
||||||
testutils::Containers {
|
Containers {
|
||||||
bitcoind,
|
bitcoind,
|
||||||
monerods: _monerods,
|
monerods: _monerods,
|
||||||
},
|
},
|
||||||
) = testutils::init_containers(&cli).await;
|
) = init_containers(&cli).await;
|
||||||
|
|
||||||
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
let btc_to_swap = bitcoin::Amount::from_sat(1_000_000);
|
||||||
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
let xmr_to_swap = monero::Amount::from_piconero(1_000_000_000_000);
|
||||||
|
@ -124,7 +124,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut alice_event_loop_2, alice_event_loop_handle_2) =
|
let (mut alice_event_loop_2, alice_event_loop_handle_2) =
|
||||||
testutils::init_alice_event_loop(alice_multiaddr, alice_seed);
|
init_alice_event_loop(alice_multiaddr, alice_seed);
|
||||||
|
|
||||||
let alice_final_state = {
|
let alice_final_state = {
|
||||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
Loading…
Add table
Add a link
Reference in a new issue