mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-17 20:04:25 -05:00
PR feedback:
Removed network prefix and use the same for container and network. Add sentence explaining prefix
This commit is contained in:
parent
a04f04f1a5
commit
306176b3e6
@ -49,29 +49,25 @@ const WAIT_WALLET_SYNC_MILLIS: u64 = 1000;
|
|||||||
pub struct Monero {
|
pub struct Monero {
|
||||||
monerod: Monerod,
|
monerod: Monerod,
|
||||||
wallets: Vec<MoneroWalletRpc>,
|
wallets: Vec<MoneroWalletRpc>,
|
||||||
container_prefix: String,
|
prefix: String,
|
||||||
}
|
}
|
||||||
impl<'c> Monero {
|
impl<'c> Monero {
|
||||||
/// Starts a new regtest monero container setup consisting out of 1 monerod
|
/// Starts a new regtest monero container setup consisting out of 1 monerod
|
||||||
/// node and n wallets. The containers will be prefixed with
|
/// node and n wallets. The containers and network will be prefixed with
|
||||||
/// `container_prefix` if provided. There will be 1 miner wallet started
|
/// `prefix` if provided. There will be 1 miner wallet started
|
||||||
/// automatically. Default monerod container name will be: `monerod`
|
/// automatically. Default monerod container name will be: `monerod`
|
||||||
/// Default miner wallet container name will be: `miner`
|
/// Default miner wallet container name will be: `miner`
|
||||||
/// Default network will be: `monero`
|
/// Default network will be: `monero`
|
||||||
|
/// Each default will be prefixed with `prefix`.
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
cli: &'c Cli,
|
cli: &'c Cli,
|
||||||
container_prefix: Option<String>,
|
prefix: Option<String>,
|
||||||
network_prefix: Option<String>,
|
|
||||||
additional_wallets: Vec<String>,
|
additional_wallets: Vec<String>,
|
||||||
) -> Result<(Self, Vec<Container<'c, Cli, image::Monero>>)> {
|
) -> Result<(Self, Vec<Container<'c, Cli, image::Monero>>)> {
|
||||||
let container_prefix = container_prefix.unwrap_or_else(|| "".to_string());
|
let prefix = prefix.unwrap_or_else(|| "".to_string());
|
||||||
|
|
||||||
let monerod_name = format!("{}{}", container_prefix, MONEROD_DAEMON_CONTAINER_NAME);
|
let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME);
|
||||||
let network = format!(
|
let network = format!("{}{}", prefix, MONEROD_DEFAULT_NETWORK);
|
||||||
"{}{}",
|
|
||||||
network_prefix.unwrap_or_else(|| "".to_string()),
|
|
||||||
MONEROD_DEFAULT_NETWORK
|
|
||||||
);
|
|
||||||
|
|
||||||
tracing::info!("Starting monerod...");
|
tracing::info!("Starting monerod...");
|
||||||
let (monerod, monerod_container) = Monerod::new(cli, monerod_name, network)?;
|
let (monerod, monerod_container) = Monerod::new(cli, monerod_name, network)?;
|
||||||
@ -79,14 +75,14 @@ impl<'c> Monero {
|
|||||||
let mut wallets = vec![];
|
let mut wallets = vec![];
|
||||||
|
|
||||||
tracing::info!("Starting miner wallet...");
|
tracing::info!("Starting miner wallet...");
|
||||||
let miner = format!("{}{}", container_prefix, "miner");
|
let miner = format!("{}{}", prefix, "miner");
|
||||||
let (miner_wallet, miner_container) = MoneroWalletRpc::new(cli, &miner, &monerod).await?;
|
let (miner_wallet, miner_container) = MoneroWalletRpc::new(cli, &miner, &monerod).await?;
|
||||||
|
|
||||||
wallets.push(miner_wallet);
|
wallets.push(miner_wallet);
|
||||||
containers.push(miner_container);
|
containers.push(miner_container);
|
||||||
for wallet in additional_wallets.iter() {
|
for wallet in additional_wallets.iter() {
|
||||||
tracing::info!("Starting wallet: {}...", wallet);
|
tracing::info!("Starting wallet: {}...", wallet);
|
||||||
let wallet = format!("{}{}", container_prefix, wallet);
|
let wallet = format!("{}{}", prefix, wallet);
|
||||||
let (wallet, container) = MoneroWalletRpc::new(cli, &wallet, &monerod).await?;
|
let (wallet, container) = MoneroWalletRpc::new(cli, &wallet, &monerod).await?;
|
||||||
wallets.push(wallet);
|
wallets.push(wallet);
|
||||||
containers.push(container);
|
containers.push(container);
|
||||||
@ -96,7 +92,7 @@ impl<'c> Monero {
|
|||||||
Self {
|
Self {
|
||||||
monerod,
|
monerod,
|
||||||
wallets,
|
wallets,
|
||||||
container_prefix,
|
prefix,
|
||||||
},
|
},
|
||||||
containers,
|
containers,
|
||||||
))
|
))
|
||||||
@ -107,7 +103,7 @@ impl<'c> Monero {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn wallet(&self, name: &str) -> Result<&MoneroWalletRpc> {
|
pub fn wallet(&self, name: &str) -> Result<&MoneroWalletRpc> {
|
||||||
let name = format!("{}{}", self.container_prefix, name);
|
let name = format!("{}{}", self.prefix, name);
|
||||||
let wallet = self
|
let wallet = self
|
||||||
.wallets
|
.wallets
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -7,7 +7,7 @@ use tokio::time;
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn init_miner_and_mine_to_miner_address() {
|
async fn init_miner_and_mine_to_miner_address() {
|
||||||
let tc = Cli::default();
|
let tc = Cli::default();
|
||||||
let (monero, _monerod_container) = Monero::new(&tc, None, None, vec![]).await.unwrap();
|
let (monero, _monerod_container) = Monero::new(&tc, None, vec![]).await.unwrap();
|
||||||
|
|
||||||
monero.init(0, 0).await.unwrap();
|
monero.init(0, 0).await.unwrap();
|
||||||
let monerod = monero.monerod();
|
let monerod = monero.monerod();
|
||||||
|
@ -9,7 +9,7 @@ async fn fund_transfer_and_check_tx_key() {
|
|||||||
let send_to_bob = 5_000_000_000;
|
let send_to_bob = 5_000_000_000;
|
||||||
|
|
||||||
let tc = Cli::default();
|
let tc = Cli::default();
|
||||||
let (monero, _containers) = Monero::new(&tc, Some("test_".to_string()), None, vec![
|
let (monero, _containers) = Monero::new(&tc, Some("test_".to_string()), vec![
|
||||||
"alice".to_string(),
|
"alice".to_string(),
|
||||||
"bob".to_string(),
|
"bob".to_string(),
|
||||||
])
|
])
|
||||||
|
@ -32,13 +32,12 @@ mod tests {
|
|||||||
.set_default();
|
.set_default();
|
||||||
|
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _container) =
|
let (monero, _container) = Monero::new(&cli, Some("hp".to_string()), vec![
|
||||||
Monero::new(&cli, Some("hp".to_string()), Some("hp".to_string()), vec![
|
"alice".to_string(),
|
||||||
"alice".to_string(),
|
"bob".to_string(),
|
||||||
"bob".to_string(),
|
])
|
||||||
])
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
|
|
||||||
let (
|
let (
|
||||||
@ -112,13 +111,12 @@ mod tests {
|
|||||||
.set_default();
|
.set_default();
|
||||||
|
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _container) =
|
let (monero, _container) = Monero::new(&cli, Some("br".to_string()), vec![
|
||||||
Monero::new(&cli, Some("br".to_string()), Some("br".to_string()), vec![
|
"alice".to_string(),
|
||||||
"alice".to_string(),
|
"bob".to_string(),
|
||||||
"bob".to_string(),
|
])
|
||||||
])
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
|
|
||||||
let (
|
let (
|
||||||
@ -194,13 +192,12 @@ mod tests {
|
|||||||
.set_default();
|
.set_default();
|
||||||
|
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _containers) =
|
let (monero, _containers) = Monero::new(&cli, Some("ap".to_string()), vec![
|
||||||
Monero::new(&cli, Some("ap".to_string()), Some("ap".to_string()), vec![
|
"alice".to_string(),
|
||||||
"alice".to_string(),
|
"bob".to_string(),
|
||||||
"bob".to_string(),
|
])
|
||||||
])
|
.await
|
||||||
.await
|
.unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
|
|
||||||
|
@ -238,12 +238,10 @@ async fn swap_as_bob(
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn on_chain_happy_path() {
|
async fn on_chain_happy_path() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _container) = Monero::new(
|
let (monero, _container) = Monero::new(&cli, Some("ochp".to_string()), vec![
|
||||||
&cli,
|
"alice".to_string(),
|
||||||
Some("ochp".to_string()),
|
"bob".to_string(),
|
||||||
Some("ochp".to_string()),
|
])
|
||||||
vec!["alice".to_string(), "bob".to_string()],
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
@ -336,12 +334,10 @@ async fn on_chain_happy_path() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn on_chain_both_refund_if_alice_never_redeems() {
|
async fn on_chain_both_refund_if_alice_never_redeems() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _container) = Monero::new(
|
let (monero, _container) = Monero::new(&cli, Some("ocbr".to_string()), vec![
|
||||||
&cli,
|
"alice".to_string(),
|
||||||
Some("ocbr".to_string()),
|
"bob".to_string(),
|
||||||
Some("ocbr".to_string()),
|
])
|
||||||
vec!["alice".to_string(), "bob".to_string()],
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
@ -433,12 +429,10 @@ async fn on_chain_both_refund_if_alice_never_redeems() {
|
|||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn on_chain_alice_punishes_if_bob_never_acts_after_fund() {
|
async fn on_chain_alice_punishes_if_bob_never_acts_after_fund() {
|
||||||
let cli = Cli::default();
|
let cli = Cli::default();
|
||||||
let (monero, _container) = Monero::new(
|
let (monero, _container) = Monero::new(&cli, Some("ocap".to_string()), vec![
|
||||||
&cli,
|
"alice".to_string(),
|
||||||
Some("ocap".to_string()),
|
"bob".to_string(),
|
||||||
Some("ocap".to_string()),
|
])
|
||||||
vec!["alice".to_string(), "bob".to_string()],
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let bitcoind = init_bitcoind(&cli).await;
|
let bitcoind = init_bitcoind(&cli).await;
|
||||||
|
Loading…
Reference in New Issue
Block a user