Skip to content

Commit

Permalink
Only one addr per label should be stored for contracts.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Jul 5, 2024
1 parent 48af807 commit d730924
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
31 changes: 11 additions & 20 deletions src/utils/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ impl TestContext {
let contract_addr = neutron
.contract_addrs
.get(PRICE_ORACLE_NAME)
.and_then(|addrs| addrs.get(0))
.cloned()
.ok_or(Error::MissingContextVariable(String::from(
"contract_addrs::price_oracle",
Expand Down Expand Up @@ -144,7 +143,7 @@ impl TestContext {
}

/// Gets the deployed atroport factory for Neutron.
pub fn get_astroport_factory(&self) -> Result<Vec<CosmWasm>, Error> {
pub fn get_astroport_factory(&self) -> Result<CosmWasm, Error> {
let neutron = self.get_chain(NEUTRON_CHAIN_NAME);

let code_id =
Expand All @@ -154,7 +153,7 @@ impl TestContext {
.ok_or(Error::MissingContextVariable(format!(
"contract_codes::{FACTORY_NAME}",
)))?;
let contract_addrs =
let contract_addr =
neutron
.contract_addrs
.get(FACTORY_NAME)
Expand All @@ -164,19 +163,14 @@ impl TestContext {

let artifacts_path = self.artifacts_dir.as_str();

Ok(contract_addrs
.into_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::<Vec<_>>())
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.
Expand All @@ -185,10 +179,7 @@ impl TestContext {
denom_a: impl AsRef<str>,
denom_b: impl AsRef<str>,
) -> Result<CosmWasm, Error> {
let factories = self.get_astroport_factory()?;
let factory = factories
.get(0)
.ok_or(Error::MissingContextVariable(String::from(FACTORY_NAME)))?;
let factory = self.get_astroport_factory()?;

let pair_info = factory.query_value(&serde_json::json!(
{
Expand Down
23 changes: 7 additions & 16 deletions src/utils/setup/astroport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.get(0))
.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)?;

Expand Down Expand Up @@ -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(())
}
Expand All @@ -383,10 +377,7 @@ impl TestContext {
denom_b: impl Into<String>,
) -> Result<(), Error> {
// Factory contract instance
let contracts = self.get_astroport_factory()?;
let contract_a = contracts
.get(0)
.ok_or(Error::MissingContextVariable(String::from(FACTORY_NAME)))?;
let contract_a = self.get_astroport_factory()?;

// Create the pair
let tx = contract_a.execute(
Expand Down
22 changes: 9 additions & 13 deletions src/utils/setup/valence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -636,13 +632,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.get(0))
.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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub struct LocalChain {
pub admin_addr: String,
pub native_denom: String,
/// contract addresses for deployed instances of contracts
pub contract_addrs: HashMap<String, Vec<String>>,
pub contract_addrs: HashMap<String, String>,
/// The name of the chain
pub chain_name: String,
pub chain_prefix: String,
Expand Down

0 comments on commit d730924

Please sign in to comment.