mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-09-20 12:54:37 -04:00
Deterministic peer id from seed for alice
This includes the introduction of the --data-dir parameter instead of the --database. Both the seed file and the database are stored in the data-dir, the database in sub-folder `database`.
This commit is contained in:
parent
64ba8d6a87
commit
0a21040e08
18 changed files with 377 additions and 35 deletions
|
@ -11,6 +11,7 @@ use swap::{
|
|||
config::Config,
|
||||
monero,
|
||||
protocol::{alice, bob},
|
||||
seed::Seed,
|
||||
};
|
||||
use testcontainers::clients::Cli;
|
||||
use testutils::init_tracing;
|
||||
|
@ -65,6 +66,7 @@ async fn happy_path() {
|
|||
xmr_alice,
|
||||
alice_multiaddr.clone(),
|
||||
config,
|
||||
&Seed::random().unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use swap::{
|
|||
database::Database,
|
||||
monero,
|
||||
protocol::{alice, alice::AliceState, bob},
|
||||
seed::Seed,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::clients::Cli;
|
||||
|
@ -42,6 +43,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||
|
||||
let config = Config::regtest();
|
||||
|
||||
let alice_seed = Seed::random().unwrap();
|
||||
let (
|
||||
start_state,
|
||||
mut alice_event_loop,
|
||||
|
@ -57,6 +59,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
config,
|
||||
&alice_seed,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -125,7 +128,7 @@ async fn given_alice_restarts_after_encsig_is_learned_resume_swap() {
|
|||
};
|
||||
|
||||
let (mut event_loop_after_restart, event_loop_handle_after_restart) =
|
||||
testutils::init_alice_event_loop(alice_multiaddr);
|
||||
testutils::init_alice_event_loop(alice_multiaddr, &alice_seed);
|
||||
tokio::spawn(async move { event_loop_after_restart.run().await });
|
||||
|
||||
let alice_state = alice::swap::swap(
|
||||
|
|
|
@ -8,6 +8,7 @@ use swap::{
|
|||
database::Database,
|
||||
monero,
|
||||
protocol::{alice, bob, bob::BobState},
|
||||
seed::Seed,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::clients::Cli;
|
||||
|
@ -57,6 +58,7 @@ async fn given_bob_restarts_after_encsig_is_sent_resume_swap() {
|
|||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
config,
|
||||
&Seed::random().unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use swap::{
|
|||
database::Database,
|
||||
monero,
|
||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||
seed::Seed,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::clients::Cli;
|
||||
|
@ -59,6 +60,7 @@ async fn given_bob_restarts_after_xmr_is_locked_resume_swap() {
|
|||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
Config::regtest(),
|
||||
&Seed::random().unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use swap::{
|
|||
config::Config,
|
||||
monero,
|
||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||
seed::Seed,
|
||||
};
|
||||
use testcontainers::clients::Cli;
|
||||
use testutils::init_tracing;
|
||||
|
@ -63,6 +64,7 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
config,
|
||||
&Seed::random().unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use swap::{
|
|||
database::Database,
|
||||
monero,
|
||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||
seed::Seed,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use testcontainers::clients::Cli;
|
||||
|
@ -47,6 +48,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
|||
.parse()
|
||||
.expect("failed to parse Alice's address");
|
||||
|
||||
let alice_seed = Seed::random().unwrap();
|
||||
let (
|
||||
alice_state,
|
||||
mut alice_event_loop_1,
|
||||
|
@ -62,6 +64,7 @@ async fn given_alice_restarts_after_xmr_is_locked_abort_swap() {
|
|||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
Config::regtest(),
|
||||
&alice_seed,
|
||||
)
|
||||
.await;
|
||||
|
||||
|
@ -121,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) =
|
||||
testutils::init_alice_event_loop(alice_multiaddr);
|
||||
testutils::init_alice_event_loop(alice_multiaddr, &alice_seed);
|
||||
|
||||
let alice_final_state = {
|
||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
||||
|
|
|
@ -7,9 +7,10 @@ use swap::{
|
|||
bitcoin,
|
||||
config::Config,
|
||||
database::Database,
|
||||
monero,
|
||||
monero, network,
|
||||
network::transport::build,
|
||||
protocol::{alice, alice::AliceState, bob, bob::BobState},
|
||||
seed::Seed,
|
||||
SwapAmounts,
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
@ -106,13 +107,13 @@ pub async fn init_alice_state(
|
|||
|
||||
pub fn init_alice_event_loop(
|
||||
listen: Multiaddr,
|
||||
seed: &Seed,
|
||||
) -> (
|
||||
alice::event_loop::EventLoop,
|
||||
alice::event_loop::EventLoopHandle,
|
||||
) {
|
||||
let alice_behaviour = alice::Behaviour::default();
|
||||
let alice_behaviour = alice::Behaviour::new(network::Seed::new(seed.bytes()));
|
||||
let alice_transport = build(alice_behaviour.identity()).unwrap();
|
||||
|
||||
alice::event_loop::EventLoop::new(alice_transport, alice_behaviour, listen).unwrap()
|
||||
}
|
||||
|
||||
|
@ -125,6 +126,7 @@ pub async fn init_alice(
|
|||
xmr_starting_balance: monero::Amount,
|
||||
listen: Multiaddr,
|
||||
config: Config,
|
||||
seed: &Seed,
|
||||
) -> (
|
||||
AliceState,
|
||||
alice::event_loop::EventLoop,
|
||||
|
@ -146,7 +148,7 @@ pub async fn init_alice(
|
|||
let alice_start_state =
|
||||
init_alice_state(btc_to_swap, xmr_to_swap, alice_btc_wallet.clone(), config).await;
|
||||
|
||||
let (event_loop, event_loop_handle) = init_alice_event_loop(listen);
|
||||
let (event_loop, event_loop_handle) = init_alice_event_loop(listen, seed);
|
||||
|
||||
let alice_db_datadir = tempdir().unwrap();
|
||||
let alice_db = Database::open(alice_db_datadir.path()).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue