No prefix for wallets in monero harness

Prefixing docker-containers and -networks is a necessity to be able to spin up multiple containers and networks.
However, there is no reason to prefix the wallet names that live inside a container. One cannot add a wallet with
the same name twice, so the prefixing of wallets does not bring any advantage. When re-opening a wallet by name
the wallet name prefix is cumbersome and was thus removed.
pull/261/head
Daniel Karzel 3 years ago
parent 9f53dab3c6
commit 2bb1c1e177

@ -44,52 +44,42 @@ const WAIT_WALLET_SYNC_MILLIS: u64 = 1000;
pub struct Monero { pub struct Monero {
monerod: Monerod, monerod: Monerod,
wallets: Vec<MoneroWalletRpc>, wallets: Vec<MoneroWalletRpc>,
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 and network will be prefixed, either /// node and n wallets. The docker container and network will be prefixed
/// randomly generated or as defined in `prefix` if provided. There will /// with a randomly generated `prefix`. One miner wallet is started
/// be 1 miner wallet started automatically. Default monerod container /// automatically.
/// name will be: `prefix`_`monerod` Default miner wallet container name /// monerod container name is: `prefix`_`monerod`
/// will be: `prefix`_`miner` Default network will be: `prefix`_`monero` /// network is: `prefix`_`monero`
/// miner wallet container name is: `miner`
pub async fn new( pub async fn new(
cli: &'c Cli, cli: &'c Cli,
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 prefix = format!("{}_", prefix.unwrap_or_else(random_prefix)); let prefix = format!("{}_", random_prefix());
let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME); let monerod_name = format!("{}{}", prefix, MONEROD_DAEMON_CONTAINER_NAME);
let network = format!("{}{}", prefix, MONEROD_DEFAULT_NETWORK); let network = format!("{}{}", prefix, MONEROD_DEFAULT_NETWORK);
tracing::info!("Starting monerod... {}", monerod_name); tracing::info!("Starting monerod: {}", monerod_name);
let (monerod, monerod_container) = Monerod::new(cli, monerod_name, network)?; let (monerod, monerod_container) = Monerod::new(cli, monerod_name, network)?;
let mut containers = vec![monerod_container]; let mut containers = vec![monerod_container];
let mut wallets = vec![]; let mut wallets = vec![];
let miner = format!("{}{}", prefix, "miner"); let miner = "miner";
tracing::info!("Starting miner wallet... {}", miner); tracing::info!("Starting miner wallet: {}", 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!("{}{}", 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);
} }
Ok(( Ok((Self { monerod, wallets }, containers))
Self {
monerod,
wallets,
prefix,
},
containers,
))
} }
pub fn monerod(&self) -> &Monerod { pub fn monerod(&self) -> &Monerod {
@ -97,7 +87,6 @@ impl<'c> Monero {
} }
pub fn wallet(&self, name: &str) -> Result<&MoneroWalletRpc> { pub fn wallet(&self, name: &str) -> Result<&MoneroWalletRpc> {
let name = format!("{}{}", self.prefix, name);
let wallet = self let wallet = self
.wallets .wallets
.iter() .iter()

@ -12,7 +12,7 @@ async fn init_miner_and_mine_to_miner_address() {
let _guard = init_tracing(); let _guard = init_tracing();
let tc = Cli::default(); let tc = Cli::default();
let (monero, _monerod_container) = Monero::new(&tc, None, vec![]).await.unwrap(); let (monero, _monerod_container) = Monero::new(&tc, vec![]).await.unwrap();
monero.init(vec![]).await.unwrap(); monero.init(vec![]).await.unwrap();

@ -16,12 +16,9 @@ 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()), vec![ let (monero, _containers) = Monero::new(&tc, vec!["alice".to_string(), "bob".to_string()])
"alice".to_string(), .await
"bob".to_string(), .unwrap();
])
.await
.unwrap();
let alice_wallet = monero.wallet("alice").unwrap(); let alice_wallet = monero.wallet("alice").unwrap();
let bob_wallet = monero.wallet("bob").unwrap(); let bob_wallet = monero.wallet("bob").unwrap();

@ -597,7 +597,7 @@ async fn init_test_wallets(
let xmr_wallet = swap::monero::Wallet::new_with_client( let xmr_wallet = swap::monero::Wallet::new_with_client(
monero.wallet(name).unwrap().client(), monero.wallet(name).unwrap().client(),
monero::Network::default(), monero::Network::default(),
"irrelevant_for_tests".to_string(), name.to_string(),
); );
let electrum_rpc_url = { let electrum_rpc_url = {

Loading…
Cancel
Save