mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-23 14:39:37 -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 {
|
||||
monerod: Monerod,
|
||||
wallets: Vec<MoneroWalletRpc>,
|
||||
container_prefix: String,
|
||||
prefix: String,
|
||||
}
|
||||
impl<'c> Monero {
|
||||
/// Starts a new regtest monero container setup consisting out of 1 monerod
|
||||
/// node and n wallets. The containers will be prefixed with
|
||||
/// `container_prefix` if provided. There will be 1 miner wallet started
|
||||
/// node and n wallets. The containers and network will be prefixed with
|
||||
/// `prefix` if provided. There will be 1 miner wallet started
|
||||
/// automatically. Default monerod container name will be: `monerod`
|
||||
/// Default miner wallet container name will be: `miner`
|
||||
/// Default network will be: `monero`
|
||||
/// Each default will be prefixed with `prefix`.
|
||||
pub async fn new(
|
||||
cli: &'c Cli,
|
||||
container_prefix: Option<String>,
|
||||
network_prefix: Option<String>,
|
||||
prefix: Option<String>,
|
||||
additional_wallets: Vec<String>,
|
||||
) -> 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 network = format!(
|
||||
"{}{}",
|
||||
network_prefix.unwrap_or_else(|| "".to_string()),
|
||||
MONEROD_DEFAULT_NETWORK
|
||||
);
|
||||
let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME);
|
||||
let network = format!("{}{}", prefix, MONEROD_DEFAULT_NETWORK);
|
||||
|
||||
tracing::info!("Starting monerod...");
|
||||
let (monerod, monerod_container) = Monerod::new(cli, monerod_name, network)?;
|
||||
@ -79,14 +75,14 @@ impl<'c> Monero {
|
||||
let mut wallets = vec![];
|
||||
|
||||
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?;
|
||||
|
||||
wallets.push(miner_wallet);
|
||||
containers.push(miner_container);
|
||||
for wallet in additional_wallets.iter() {
|
||||
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?;
|
||||
wallets.push(wallet);
|
||||
containers.push(container);
|
||||
@ -96,7 +92,7 @@ impl<'c> Monero {
|
||||
Self {
|
||||
monerod,
|
||||
wallets,
|
||||
container_prefix,
|
||||
prefix,
|
||||
},
|
||||
containers,
|
||||
))
|
||||
@ -107,7 +103,7 @@ impl<'c> Monero {
|
||||
}
|
||||
|
||||
pub fn wallet(&self, name: &str) -> Result<&MoneroWalletRpc> {
|
||||
let name = format!("{}{}", self.container_prefix, name);
|
||||
let name = format!("{}{}", self.prefix, name);
|
||||
let wallet = self
|
||||
.wallets
|
||||
.iter()
|
||||
|
@ -7,7 +7,7 @@ use tokio::time;
|
||||
#[tokio::test]
|
||||
async fn init_miner_and_mine_to_miner_address() {
|
||||
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();
|
||||
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 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(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
|
@ -32,13 +32,12 @@ mod tests {
|
||||
.set_default();
|
||||
|
||||
let cli = Cli::default();
|
||||
let (monero, _container) =
|
||||
Monero::new(&cli, Some("hp".to_string()), Some("hp".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let (monero, _container) = Monero::new(&cli, Some("hp".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
|
||||
let (
|
||||
@ -112,13 +111,12 @@ mod tests {
|
||||
.set_default();
|
||||
|
||||
let cli = Cli::default();
|
||||
let (monero, _container) =
|
||||
Monero::new(&cli, Some("br".to_string()), Some("br".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let (monero, _container) = Monero::new(&cli, Some("br".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
|
||||
let (
|
||||
@ -194,13 +192,12 @@ mod tests {
|
||||
.set_default();
|
||||
|
||||
let cli = Cli::default();
|
||||
let (monero, _containers) =
|
||||
Monero::new(&cli, Some("ap".to_string()), Some("ap".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let (monero, _containers) = Monero::new(&cli, Some("ap".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
|
||||
|
@ -238,12 +238,10 @@ async fn swap_as_bob(
|
||||
#[tokio::test]
|
||||
async fn on_chain_happy_path() {
|
||||
let cli = Cli::default();
|
||||
let (monero, _container) = Monero::new(
|
||||
&cli,
|
||||
Some("ochp".to_string()),
|
||||
Some("ochp".to_string()),
|
||||
vec!["alice".to_string(), "bob".to_string()],
|
||||
)
|
||||
let (monero, _container) = Monero::new(&cli, Some("ochp".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
@ -336,12 +334,10 @@ async fn on_chain_happy_path() {
|
||||
#[tokio::test]
|
||||
async fn on_chain_both_refund_if_alice_never_redeems() {
|
||||
let cli = Cli::default();
|
||||
let (monero, _container) = Monero::new(
|
||||
&cli,
|
||||
Some("ocbr".to_string()),
|
||||
Some("ocbr".to_string()),
|
||||
vec!["alice".to_string(), "bob".to_string()],
|
||||
)
|
||||
let (monero, _container) = Monero::new(&cli, Some("ocbr".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
@ -433,12 +429,10 @@ async fn on_chain_both_refund_if_alice_never_redeems() {
|
||||
#[tokio::test]
|
||||
async fn on_chain_alice_punishes_if_bob_never_acts_after_fund() {
|
||||
let cli = Cli::default();
|
||||
let (monero, _container) = Monero::new(
|
||||
&cli,
|
||||
Some("ocap".to_string()),
|
||||
Some("ocap".to_string()),
|
||||
vec!["alice".to_string(), "bob".to_string()],
|
||||
)
|
||||
let (monero, _container) = Monero::new(&cli, Some("ocap".to_string()), vec![
|
||||
"alice".to_string(),
|
||||
"bob".to_string(),
|
||||
])
|
||||
.await
|
||||
.unwrap();
|
||||
let bitcoind = init_bitcoind(&cli).await;
|
||||
|
Loading…
Reference in New Issue
Block a user