Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: Repeated Instantiations of Contract Should Overwrite Addresses #6

Merged
merged 2 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 19 additions & 28 deletions src/utils/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -149,7 +148,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 @@ -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)
Expand All @@ -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::<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 @@ -190,10 +184,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
.first()
.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.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)?;

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
.first()
.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 @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ pub struct LocalChain {
pub connection_ids: HashMap<String, String>,
pub admin_addr: String,
pub native_denom: String,
/// contract addresses for deployed instances of contracts
pub contract_addrs: HashMap<String, Vec<String>>,
/// contract address for the deployed instance of a contract
pub contract_addrs: HashMap<String, String>,
/// The name of the chain
pub chain_name: String,
pub chain_prefix: String,
Expand Down
Loading