@ -8,7 +8,7 @@ use futures::Future;
use get_port ::get_port ;
use libp2p ::core ::Multiaddr ;
use libp2p ::PeerId ;
use monero_harness::{ image , Mo nero} ;
use wownero_harness::{ image , Wow nero} ;
use std ::cmp ::Ordering ;
use std ::fmt ;
use std ::path ::{ Path , PathBuf } ;
@ -23,7 +23,7 @@ use swap::protocol::alice::{AliceState, Swap};
use swap ::protocol ::bob ::BobState ;
use swap ::protocol ::{ alice , bob } ;
use swap ::seed ::Seed ;
use swap ::{ asb , bitcoin , cli , env , mo nero} ;
use swap ::{ asb , bitcoin , cli , env , wow nero} ;
use tempfile ::tempdir ;
use testcontainers ::clients ::Cli ;
use testcontainers ::{ Container , Docker , RunArgs } ;
@ -44,20 +44,20 @@ where
let cli = Cli ::default ( ) ;
let _guard = tracing_subscriber ::fmt ( )
. with_env_filter ( "warn,swap=debug, monero_harness=debug,mo nero_rpc=debug,bitcoin_harness=info,testcontainers=info") // add `reqwest::connect::verbose=trace` if you want to logs of the RPC clients
. with_env_filter ( "warn,swap=debug, wownero_harness=debug,wow nero_rpc=debug,bitcoin_harness=info,testcontainers=info") // add `reqwest::connect::verbose=trace` if you want to logs of the RPC clients
. with_test_writer ( )
. set_default ( ) ;
let env_config = C ::get_config ( ) ;
let ( mo nero, containers ) = init_containers ( & cli ) . await ;
mo nero. init_miner ( ) . await . unwrap ( ) ;
let ( wow nero, containers ) = init_containers ( & cli ) . await ;
wow nero. init_miner ( ) . await . unwrap ( ) ;
let btc_amount = bitcoin ::Amount ::from_sat ( 1_000_000 ) ;
let xmr_amount = monero ::Amount ::from_mo nero( btc_amount . as_btc ( ) / FixedRate ::RATE ) . unwrap ( ) ;
let wow_amount = wownero ::Amount ::from_wow nero( btc_amount . as_btc ( ) / FixedRate ::RATE ) . unwrap ( ) ;
let alice_starting_balances =
StartingBalances ::new ( bitcoin ::Amount ::ZERO , xmr _amount, Some ( 10 ) ) ;
StartingBalances ::new ( bitcoin ::Amount ::ZERO , wow _amount, Some ( 10 ) ) ;
let electrs_rpc_port = containers
. electrs
@ -65,10 +65,10 @@ where
. expect ( "Could not map electrs rpc port" ) ;
let alice_seed = Seed ::random ( ) . unwrap ( ) ;
let ( alice_bitcoin_wallet , alice_ mo nero_wallet) = init_test_wallets (
MO NERO_WALLET_NAME_ALICE,
let ( alice_bitcoin_wallet , alice_ wow nero_wallet) = init_test_wallets (
WOW NERO_WALLET_NAME_ALICE,
containers . bitcoind_url . clone ( ) ,
& mo nero,
& wow nero,
alice_starting_balances . clone ( ) ,
tempdir ( ) . unwrap ( ) . path ( ) ,
electrs_rpc_port ,
@ -89,17 +89,17 @@ where
alice_listen_address . clone ( ) ,
env_config ,
alice_bitcoin_wallet . clone ( ) ,
alice_ mo nero_wallet. clone ( ) ,
alice_ wow nero_wallet. clone ( ) ,
)
. await ;
let bob_seed = Seed ::random ( ) . unwrap ( ) ;
let bob_starting_balances = StartingBalances ::new ( btc_amount * 10 , mo nero::Amount ::ZERO , None ) ;
let bob_starting_balances = StartingBalances ::new ( btc_amount * 10 , wow nero::Amount ::ZERO , None ) ;
let ( bob_bitcoin_wallet , bob_ mo nero_wallet) = init_test_wallets (
MO NERO_WALLET_NAME_BOB,
let ( bob_bitcoin_wallet , bob_ wow nero_wallet) = init_test_wallets (
WOW NERO_WALLET_NAME_BOB,
containers . bitcoind_url ,
& mo nero,
& wow nero,
bob_starting_balances . clone ( ) ,
tempdir ( ) . unwrap ( ) . path ( ) ,
electrs_rpc_port ,
@ -112,36 +112,36 @@ where
seed : Seed ::random ( ) . unwrap ( ) ,
db_path : tempdir ( ) . unwrap ( ) . path ( ) . to_path_buf ( ) ,
bitcoin_wallet : bob_bitcoin_wallet . clone ( ) ,
monero_wallet: bob_mo nero_wallet. clone ( ) ,
wownero_wallet: bob_wow nero_wallet. clone ( ) ,
alice_address : alice_listen_address . clone ( ) ,
alice_peer_id : alice_handle . peer_id ,
env_config ,
} ;
mo nero. start_miner ( ) . await . unwrap ( ) ;
wow nero. start_miner ( ) . await . unwrap ( ) ;
let test = TestContext {
env_config ,
btc_amount ,
xmr _amount,
wow _amount,
alice_seed ,
alice_db_path ,
alice_listen_address ,
alice_starting_balances ,
alice_bitcoin_wallet ,
alice_ mo nero_wallet,
alice_ wow nero_wallet,
alice_swap_handle ,
alice_handle ,
bob_params ,
bob_starting_balances ,
bob_bitcoin_wallet ,
bob_ mo nero_wallet,
bob_ wow nero_wallet,
} ;
testfn ( test ) . await . unwrap ( )
}
async fn init_containers ( cli : & Cli ) -> ( Mo nero, Containers < ' _ > ) {
async fn init_containers ( cli : & Cli ) -> ( Wow nero, Containers < ' _ > ) {
let prefix = random_prefix ( ) ;
let bitcoind_name = format! ( "{}_{}" , prefix , "bitcoind" ) ;
let ( bitcoind , bitcoind_url ) =
@ -151,16 +151,16 @@ async fn init_containers(cli: &Cli) -> (Monero, Containers<'_>) {
let electrs = init_electrs_container ( & cli , prefix . clone ( ) , bitcoind_name , prefix )
. await
. expect ( "could not init electrs" ) ;
let ( monero, monerod_container , mo nero_wallet_rpc_containers) =
Monero::new ( & cli , vec! [ MONERO_WALLET_NAME_ALICE , MO NERO_WALLET_NAME_BOB] )
let ( wownero, wownerod_container , wow nero_wallet_rpc_containers) =
Wownero::new ( & cli , vec! [ WOWNERO_WALLET_NAME_ALICE , WOW NERO_WALLET_NAME_BOB] )
. await
. unwrap ( ) ;
( mo nero, Containers {
( wow nero, Containers {
bitcoind_url ,
bitcoind ,
mo nerod_container,
mo nero_wallet_rpc_containers,
wow nerod_container,
wow nero_wallet_rpc_containers,
electrs ,
} )
}
@ -220,7 +220,7 @@ async fn start_alice(
listen_address : Multiaddr ,
env_config : Config ,
bitcoin_wallet : Arc < bitcoin ::Wallet > ,
monero_wallet: Arc < mo nero::Wallet > ,
wownero_wallet: Arc < wow nero::Wallet > ,
) -> ( AliceApplicationHandle , Receiver < alice ::Swap > ) {
let db = Arc ::new ( Database ::open ( db_path . as_path ( ) ) . unwrap ( ) ) ;
@ -245,7 +245,7 @@ async fn start_alice(
swarm ,
env_config ,
bitcoin_wallet ,
mo nero_wallet,
wow nero_wallet,
db ,
FixedRate ::default ( ) ,
min_buy ,
@ -263,18 +263,18 @@ async fn start_alice(
async fn init_test_wallets (
name : & str ,
bitcoind_url : Url ,
monero: & Mo nero,
wownero: & Wow nero,
starting_balances : StartingBalances ,
datadir : & Path ,
electrum_rpc_port : u16 ,
seed : & Seed ,
env_config : Config ,
) -> ( Arc < bitcoin ::Wallet > , Arc < mo nero::Wallet > ) {
mo nero
) -> ( Arc < bitcoin ::Wallet > , Arc < wow nero::Wallet > ) {
wow nero
. init_wallet (
name ,
starting_balances
. xmr _outputs
. wow _outputs
. into_iter ( )
. map ( | amount | amount . as_piconero ( ) )
. collect ( ) ,
@ -282,8 +282,8 @@ async fn init_test_wallets(
. await
. unwrap ( ) ;
let xmr_wallet = swap ::mo nero::Wallet ::connect (
mo nero. wallet ( name ) . unwrap ( ) . client ( ) . clone ( ) ,
let wow_wallet = swap ::wow nero::Wallet ::connect (
wow nero. wallet ( name ) . unwrap ( ) . client ( ) . clone ( ) ,
name . to_string ( ) ,
env_config ,
)
@ -336,52 +336,52 @@ async fn init_test_wallets(
}
}
( Arc ::new ( btc_wallet ) , Arc ::new ( xmr _wallet) )
( Arc ::new ( btc_wallet ) , Arc ::new ( wow _wallet) )
}
const MO NERO_WALLET_NAME_BOB: & str = "bob" ;
const MO NERO_WALLET_NAME_ALICE: & str = "alice" ;
const WOW NERO_WALLET_NAME_BOB: & str = "bob" ;
const WOW NERO_WALLET_NAME_ALICE: & str = "alice" ;
const BITCOIN_TEST_WALLET_NAME : & str = "testwallet" ;
#[ derive(Debug, Clone) ]
pub struct StartingBalances {
pub xmr: mo nero::Amount ,
pub xmr_outputs: Vec < mo nero::Amount > ,
pub wow: wow nero::Amount ,
pub wow_outputs: Vec < wow nero::Amount > ,
pub btc : bitcoin ::Amount ,
}
impl StartingBalances {
/// If monero_outputs is specified the mo nero balance will be:
/// monero_outputs * new_xmr = self_xmr
pub fn new ( btc : bitcoin ::Amount , xmr: monero ::Amount , mo nero_outputs: Option < u64 > ) -> Self {
match mo nero_outputs {
/// If wownero_outputs is specified the wow nero balance will be:
/// wownero_outputs * new_wow = self_wow
pub fn new ( btc : bitcoin ::Amount , wow: wownero ::Amount , wow nero_outputs: Option < u64 > ) -> Self {
match wow nero_outputs {
None = > {
if xmr = = mo nero::Amount ::ZERO {
if wow = = wow nero::Amount ::ZERO {
return Self {
xmr ,
xmr _outputs: vec ! [ ] ,
wow ,
wow _outputs: vec ! [ ] ,
btc ,
} ;
}
Self {
xmr ,
xmr_outputs: vec ! [ xmr ] ,
wow ,
wow_outputs: vec ! [ wow ] ,
btc ,
}
}
Some ( outputs ) = > {
let mut xmr _outputs = Vec ::new ( ) ;
let mut sum_ xmr = mo nero::Amount ::ZERO ;
let mut wow _outputs = Vec ::new ( ) ;
let mut sum_ wow = wow nero::Amount ::ZERO ;
for _ in 0 .. outputs {
xmr_outputs. push ( xmr ) ;
sum_ xmr = sum_xmr + xmr ;
wow_outputs. push ( wow ) ;
sum_ wow = sum_wow + wow ;
}
Self {
xmr: sum_xmr ,
xmr _outputs,
wow: sum_wow ,
wow _outputs,
btc ,
}
}
@ -393,7 +393,7 @@ struct BobParams {
seed : Seed ,
db_path : PathBuf ,
bitcoin_wallet : Arc < bitcoin ::Wallet > ,
monero_wallet: Arc < mo nero::Wallet > ,
wownero_wallet: Arc < wow nero::Wallet > ,
alice_address : Multiaddr ,
alice_peer_id : PeerId ,
env_config : Config ,
@ -408,10 +408,10 @@ impl BobParams {
db ,
swap_id ,
self . bitcoin_wallet . clone ( ) ,
self . mo nero_wallet. clone ( ) ,
self . wow nero_wallet. clone ( ) ,
self . env_config ,
handle ,
self . mo nero_wallet. get_main_address ( ) ,
self . wow nero_wallet. get_main_address ( ) ,
) ? ;
Ok ( ( swap , event_loop ) )
@ -430,10 +430,10 @@ impl BobParams {
db ,
swap_id ,
self . bitcoin_wallet . clone ( ) ,
self . mo nero_wallet. clone ( ) ,
self . wow nero_wallet. clone ( ) ,
self . env_config ,
handle ,
self . mo nero_wallet. get_main_address ( ) ,
self . wow nero_wallet. get_main_address ( ) ,
self . bitcoin_wallet . new_address ( ) . await ? ,
btc_amount ,
) ;
@ -490,7 +490,7 @@ pub struct TestContext {
env_config : Config ,
btc_amount : bitcoin ::Amount ,
xmr_amount: mo nero::Amount ,
wow_amount: wow nero::Amount ,
alice_seed : Seed ,
alice_db_path : PathBuf ,
@ -498,14 +498,14 @@ pub struct TestContext {
alice_starting_balances : StartingBalances ,
alice_bitcoin_wallet : Arc < bitcoin ::Wallet > ,
alice_ monero_wallet: Arc < mo nero::Wallet > ,
alice_ wownero_wallet: Arc < wow nero::Wallet > ,
alice_swap_handle : mpsc ::Receiver < Swap > ,
alice_handle : AliceApplicationHandle ,
bob_params : BobParams ,
bob_starting_balances : StartingBalances ,
bob_bitcoin_wallet : Arc < bitcoin ::Wallet > ,
bob_ monero_wallet: Arc < mo nero::Wallet > ,
bob_ wownero_wallet: Arc < wow nero::Wallet > ,
}
impl TestContext {
@ -518,7 +518,7 @@ impl TestContext {
self . alice_listen_address . clone ( ) ,
self . env_config ,
self . alice_bitcoin_wallet . clone ( ) ,
self . alice_ mo nero_wallet. clone ( ) ,
self . alice_ wow nero_wallet. clone ( ) ,
)
. await ;
@ -570,16 +570,16 @@ impl TestContext {
. unwrap ( ) ;
assert_eventual_balance (
self . alice_ mo nero_wallet. as_ref ( ) ,
self . alice_ wow nero_wallet. as_ref ( ) ,
Ordering ::Less ,
self . alice_redeemed_ xmr _balance( ) ,
self . alice_redeemed_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
}
pub async fn assert_alice_refunded ( & mut self , state : AliceState ) {
assert! ( matches! ( state , AliceState ::Xmr Refunded) ) ;
assert! ( matches! ( state , AliceState ::Wow Refunded) ) ;
assert_eventual_balance (
self . alice_bitcoin_wallet . as_ref ( ) ,
@ -591,9 +591,9 @@ impl TestContext {
// Alice pays fees - comparison does not take exact lock fee into account
assert_eventual_balance (
self . alice_ mo nero_wallet. as_ref ( ) ,
self . alice_ wow nero_wallet. as_ref ( ) ,
Ordering ::Greater ,
self . alice_refunded_ xmr _balance( ) ,
self . alice_refunded_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
@ -611,9 +611,9 @@ impl TestContext {
. unwrap ( ) ;
assert_eventual_balance (
self . alice_ mo nero_wallet. as_ref ( ) ,
self . alice_ wow nero_wallet. as_ref ( ) ,
Ordering ::Less ,
self . alice_punished_ xmr _balance( ) ,
self . alice_punished_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
@ -629,12 +629,12 @@ impl TestContext {
. unwrap ( ) ;
// unload the generated wallet by opening the original wallet
self . bob_ mo nero_wallet. re_open ( ) . await . unwrap ( ) ;
self . bob_ wow nero_wallet. re_open ( ) . await . unwrap ( ) ;
assert_eventual_balance (
self . bob_ mo nero_wallet. as_ref ( ) ,
self . bob_ wow nero_wallet. as_ref ( ) ,
Ordering ::Greater ,
self . bob_redeemed_ xmr _balance( ) ,
self . bob_redeemed_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
@ -673,9 +673,9 @@ impl TestContext {
assert! ( bob_cancelled_and_refunded ) ;
assert_eventual_balance (
self . bob_ mo nero_wallet. as_ref ( ) ,
self . bob_ wow nero_wallet. as_ref ( ) ,
Ordering ::Equal ,
self . bob_refunded_ xmr _balance( ) ,
self . bob_refunded_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
@ -691,16 +691,16 @@ impl TestContext {
. unwrap ( ) ;
assert_eventual_balance (
self . bob_ mo nero_wallet. as_ref ( ) ,
self . bob_ wow nero_wallet. as_ref ( ) ,
Ordering ::Equal ,
self . bob_punished_ xmr _balance( ) ,
self . bob_punished_ wow _balance( ) ,
)
. await
. unwrap ( ) ;
}
fn alice_redeemed_ xmr_balance( & self ) -> mo nero::Amount {
self . alice_starting_balances . xmr - self . xmr _amount
fn alice_redeemed_ wow_balance( & self ) -> wow nero::Amount {
self . alice_starting_balances . wow - self . wow _amount
}
async fn alice_redeemed_btc_balance ( & self ) -> bitcoin ::Amount {
@ -712,17 +712,17 @@ impl TestContext {
self . alice_starting_balances . btc + self . btc_amount - fee
}
fn bob_redeemed_ xmr_balance( & self ) -> mo nero::Amount {
self . bob_starting_balances . xmr
fn bob_redeemed_ wow_balance( & self ) -> wow nero::Amount {
self . bob_starting_balances . wow
}
async fn bob_redeemed_btc_balance ( & self , state : BobState ) -> Result < bitcoin ::Amount > {
self . bob_bitcoin_wallet . sync ( ) . await ? ;
let lock_tx_id = if let BobState ::Xmr Redeemed { tx_lock_id } = state {
let lock_tx_id = if let BobState ::Wow Redeemed { tx_lock_id } = state {
tx_lock_id
} else {
bail ! ( "Bob in not in xmr redeemed state: {:?}", state ) ;
bail ! ( "Bob in not in wow redeemed state: {:?}", state ) ;
} ;
let lock_tx_bitcoin_fee = self . bob_bitcoin_wallet . transaction_fee ( lock_tx_id ) . await ? ;
@ -730,20 +730,20 @@ impl TestContext {
Ok ( self . bob_starting_balances . btc - self . btc_amount - lock_tx_bitcoin_fee )
}
fn alice_refunded_ xmr_balance( & self ) -> mo nero::Amount {
self . alice_starting_balances . xmr - self . xmr _amount
fn alice_refunded_ wow_balance( & self ) -> wow nero::Amount {
self . alice_starting_balances . wow - self . wow _amount
}
fn alice_refunded_btc_balance ( & self ) -> bitcoin ::Amount {
self . alice_starting_balances . btc
}
fn bob_refunded_ xmr_balance( & self ) -> mo nero::Amount {
self . bob_starting_balances . xmr
fn bob_refunded_ wow_balance( & self ) -> wow nero::Amount {
self . bob_starting_balances . wow
}
fn alice_punished_ xmr_balance( & self ) -> mo nero::Amount {
self . alice_starting_balances . xmr - self . xmr _amount
fn alice_punished_ wow_balance( & self ) -> wow nero::Amount {
self . alice_starting_balances . wow - self . wow _amount
}
async fn alice_punished_btc_balance ( & self ) -> bitcoin ::Amount {
@ -760,8 +760,8 @@ impl TestContext {
self . alice_starting_balances . btc + self . btc_amount - cancel_fee - punish_fee
}
fn bob_punished_ xmr_balance( & self ) -> mo nero::Amount {
self . bob_starting_balances . xmr
fn bob_punished_ wow_balance( & self ) -> wow nero::Amount {
self . bob_starting_balances . wow
}
async fn bob_punished_btc_balance ( & self , state : BobState ) -> Result < bitcoin ::Amount > {
@ -836,8 +836,8 @@ trait Wallet {
}
#[ async_trait ]
impl Wallet for mo nero::Wallet {
type Amount = mo nero::Amount ;
impl Wallet for wow nero::Wallet {
type Amount = wow nero::Amount ;
async fn refresh ( & self ) -> Result < ( ) > {
self . refresh ( ) . await ? ;
@ -931,16 +931,16 @@ pub async fn mint(node_url: Url, address: bitcoin::Address, amount: bitcoin::Amo
struct Containers < ' a > {
bitcoind_url : Url ,
bitcoind : Container < ' a , Cli , bitcoind ::Bitcoind > ,
mo nerod_container: Container < ' a , Cli , image ::Mo nerod> ,
mo nero_wallet_rpc_containers: Vec < Container < ' a , Cli , image ::Mo neroWalletRpc> > ,
wow nerod_container: Container < ' a , Cli , image ::Wow nerod> ,
wow nero_wallet_rpc_containers: Vec < Container < ' a , Cli , image ::Wow neroWalletRpc> > ,
electrs : Container < ' a , Cli , electrs ::Electrs > ,
}
pub mod alice_run_until {
use swap ::protocol ::alice ::AliceState ;
pub fn is_ xmr _lock_transaction_sent( state : & AliceState ) -> bool {
matches! ( state , AliceState ::Xmr LockTransactionSent { .. } )
pub fn is_ wow _lock_transaction_sent( state : & AliceState ) -> bool {
matches! ( state , AliceState ::Wow LockTransactionSent { .. } )
}
pub fn is_encsig_learned ( state : & AliceState ) -> bool {
@ -956,11 +956,11 @@ pub mod bob_run_until {
}
pub fn is_lock_proof_received ( state : & BobState ) -> bool {
matches! ( state , BobState ::Xmr LockProofReceived { .. } )
matches! ( state , BobState ::Wow LockProofReceived { .. } )
}
pub fn is_ xmr _locked( state : & BobState ) -> bool {
matches! ( state , BobState ::Xmr Locked( .. ) )
pub fn is_ wow _locked( state : & BobState ) -> bool {
matches! ( state , BobState ::Wow Locked( .. ) )
}
pub fn is_encsig_sent ( state : & BobState ) -> bool {