From 1ced8ae761ee78c368e8f7d1121f7c8ebbc6fa38 Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Sun, 28 Jul 2024 09:30:31 -0700 Subject: [PATCH 1/2] Support only one contract addr (instance) per contract. --- src/utils/fixtures.rs | 47 +++++++++++++++--------------------- src/utils/setup/astroport.rs | 23 ++++++------------ src/utils/setup/valence.rs | 22 +++++++---------- src/utils/test_context.rs | 2 +- 4 files changed, 36 insertions(+), 58 deletions(-) diff --git a/src/utils/fixtures.rs b/src/utils/fixtures.rs index 92aa718..0490849 100644 --- a/src/utils/fixtures.rs +++ b/src/utils/fixtures.rs @@ -104,15 +104,14 @@ impl TestContext { let neutron = self.get_chain(NEUTRON_CHAIN_NAME); let mut contract = self.get_contract(PRICE_ORACLE_NAME)?; - let contract_addr = neutron - .contract_addrs - .get(PRICE_ORACLE_NAME) - .and_then(|addrs| addrs.first()) - .cloned() - .ok_or(Error::MissingContextVariable(String::from( - "contract_addrs::price_oracle", - )))?; - contract.contract_addr = Some(contract_addr); + let contract_addr = + neutron + .contract_addrs + .get(PRICE_ORACLE_NAME) + .ok_or(Error::MissingContextVariable(String::from( + "contract_addrs::price_oracle", + )))?; + contract.contract_addr = Some(contract_addr.clone()); Ok(contract) } @@ -149,7 +148,7 @@ impl TestContext { } /// Gets the deployed atroport factory for Neutron. - pub fn get_astroport_factory(&self) -> Result, Error> { + pub fn get_astroport_factory(&self) -> Result { let neutron = self.get_chain(NEUTRON_CHAIN_NAME); let code_id = @@ -159,7 +158,7 @@ impl TestContext { .ok_or(Error::MissingContextVariable(format!( "contract_codes::{FACTORY_NAME}", )))?; - let contract_addrs = + let contract_addr = neutron .contract_addrs .get(FACTORY_NAME) @@ -169,19 +168,14 @@ impl TestContext { let artifacts_path = self.artifacts_dir.as_str(); - Ok(contract_addrs - .iter() - .map(|addr| { - CosmWasm::new_from_existing( - &neutron.rb, - Some(PathBuf::from(format!( - "{artifacts_path}/{FACTORY_NAME}.wasm" - ))), - Some(*code_id), - Some(addr.clone()), - ) - }) - .collect::>()) + Ok(CosmWasm::new_from_existing( + &neutron.rb, + Some(PathBuf::from(format!( + "{artifacts_path}/{FACTORY_NAME}.wasm" + ))), + Some(*code_id), + Some(contract_addr.clone()), + )) } /// Gets a previously deployed astroport pair. @@ -190,10 +184,7 @@ impl TestContext { denom_a: impl AsRef, denom_b: impl AsRef, ) -> Result { - let factories = self.get_astroport_factory()?; - let factory = factories - .first() - .ok_or(Error::MissingContextVariable(String::from(FACTORY_NAME)))?; + let factory = self.get_astroport_factory()?; let pair_info = factory.query_value(&serde_json::json!( { diff --git a/src/utils/setup/astroport.rs b/src/utils/setup/astroport.rs index bf99007..deac752 100644 --- a/src/utils/setup/astroport.rs +++ b/src/utils/setup/astroport.rs @@ -246,9 +246,7 @@ impl TestContext { neutron .contract_addrs - .entry(TOKEN_REGISTRY_NAME.to_owned()) - .or_default() - .push(addr.clone()); + .insert(TOKEN_REGISTRY_NAME.to_owned(), addr.clone()); self.astroport_token_registry = Some(DeployedContractInfo { code_id, @@ -305,13 +303,11 @@ impl TestContext { "contract_codes::astroport_whitelist", )))?; - let native_registry_addr = neutron - .contract_addrs - .get(TOKEN_REGISTRY_NAME) - .and_then(|maybe_addr| maybe_addr.first()) - .ok_or(Error::MissingContextVariable(String::from( + let native_registry_addr = neutron.contract_addrs.get(TOKEN_REGISTRY_NAME).ok_or( + Error::MissingContextVariable(String::from( "contract_ddrs::astroport_native_coin_registry", - )))?; + )), + )?; let mut contract_a = self.get_contract(FACTORY_NAME)?; @@ -356,9 +352,7 @@ impl TestContext { neutron .contract_addrs - .entry(FACTORY_NAME.to_owned()) - .or_default() - .push(contract.address); + .insert(FACTORY_NAME.to_owned(), contract.address); Ok(()) } @@ -383,10 +377,7 @@ impl TestContext { denom_b: impl Into, ) -> Result<(), Error> { // Factory contract instance - let contracts = self.get_astroport_factory()?; - let contract_a = contracts - .first() - .ok_or(Error::MissingContextVariable(String::from(FACTORY_NAME)))?; + let contract_a = self.get_astroport_factory()?; // Create the pair let tx = contract_a.execute( diff --git a/src/utils/setup/valence.rs b/src/utils/setup/valence.rs index 81e138c..2ab1915 100644 --- a/src/utils/setup/valence.rs +++ b/src/utils/setup/valence.rs @@ -437,9 +437,7 @@ impl TestContext { chain .contract_addrs - .entry(AUCTIONS_MANAGER_CONTRACT_NAME.to_owned()) - .or_default() - .push(contract.address); + .insert(AUCTIONS_MANAGER_CONTRACT_NAME.to_owned(), contract.address); Ok(()) } @@ -488,9 +486,7 @@ impl TestContext { chain .contract_addrs - .entry(PRICE_ORACLE_NAME.to_owned()) - .or_default() - .push(contract.address); + .insert(PRICE_ORACLE_NAME.to_owned(), contract.address); Ok(()) } @@ -637,13 +633,13 @@ impl TestContext { // The auctions manager for this deployment let contract_a = self.get_auctions_manager()?; let neutron = self.get_chain(NEUTRON_CHAIN_NAME); - let oracle = neutron - .contract_addrs - .get(PRICE_ORACLE_NAME) - .and_then(|addrs| addrs.first()) - .ok_or(Error::MissingContextVariable(String::from( - "contract_addrs::price_oracle", - )))?; + let oracle = + neutron + .contract_addrs + .get(PRICE_ORACLE_NAME) + .ok_or(Error::MissingContextVariable(String::from( + "contract_addrs::price_oracle", + )))?; let receipt = contract_a.execute( sender_key, diff --git a/src/utils/test_context.rs b/src/utils/test_context.rs index 171661a..f9bdd5c 100644 --- a/src/utils/test_context.rs +++ b/src/utils/test_context.rs @@ -364,7 +364,7 @@ pub struct LocalChain { pub admin_addr: String, pub native_denom: String, /// contract addresses for deployed instances of contracts - pub contract_addrs: HashMap>, + pub contract_addrs: HashMap, /// The name of the chain pub chain_name: String, pub chain_prefix: String, From 99fc4725e2b4b88922452e90eecc7e581963d042 Mon Sep 17 00:00:00 2001 From: Dowland Aiello Date: Sun, 28 Jul 2024 10:13:25 -0700 Subject: [PATCH 2/2] Update contract_addrs comment. --- src/utils/test_context.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/test_context.rs b/src/utils/test_context.rs index f9bdd5c..bdbae81 100644 --- a/src/utils/test_context.rs +++ b/src/utils/test_context.rs @@ -363,7 +363,7 @@ pub struct LocalChain { pub connection_ids: HashMap, pub admin_addr: String, pub native_denom: String, - /// contract addresses for deployed instances of contracts + /// contract address for the deployed instance of a contract pub contract_addrs: HashMap, /// The name of the chain pub chain_name: String,