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

Set adapter addr on install_adapter #21

Merged
merged 7 commits into from
Jul 18, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Address of App/Adapter returned and set by default.

### Fixed

## [0.17.0] - 2023-07-05
Expand Down
23 changes: 23 additions & 0 deletions framework/contracts/account/manager/tests/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,26 @@ fn installing_specific_version_should_install_expected() -> AResult {

Ok(())
}

#[test]
fn account_install_adapter() -> AResult {
let sender = Addr::unchecked(common::OWNER);
let chain = Mock::new(&sender);
let deployment = Abstract::deploy_on(chain.clone(), Empty {})?;
let account = create_default_account(&deployment.account_factory)?;

deployment
.version_control
.claim_namespace(1, "tester".to_owned())?;

let adapter = BootMockAdapter1V1::new_test(chain);
adapter.deploy(V1.parse().unwrap(), MockInitMsg)?;
let adapter_addr = account.install_adapter(adapter, &MockInitMsg, None)?;
let module_addr = account
.manager
.module_info(common::mock_modules::adapter_1::MOCK_ADAPTER_ID)?
.unwrap()
.address;
assert_that!(adapter_addr).is_equal_to(module_addr);
Ok(())
}
24 changes: 24 additions & 0 deletions framework/contracts/account/manager/tests/apps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod common;
use abstract_app::gen_app_mock;
use abstract_core::PROXY;
use abstract_interface::*;

Expand All @@ -8,6 +9,10 @@ use cw_orch::deploy::Deploy;
use cw_orch::prelude::*;
use speculoos::prelude::*;

const APP_ID: &str = "tester:app";
const APP_VERSION: &str = "1.0.0";
gen_app_mock!(MockApp, APP_ID, APP_VERSION, &[]);

#[test]
fn execute_on_proxy_through_manager() -> AResult {
let sender = Addr::unchecked(common::OWNER);
Expand Down Expand Up @@ -49,3 +54,22 @@ fn execute_on_proxy_through_manager() -> AResult {

Ok(())
}

#[test]
fn account_install_app() -> AResult {
let sender = Addr::unchecked(common::OWNER);
let chain = Mock::new(&sender);
let deployment = Abstract::deploy_on(chain.clone(), Empty {})?;
let account = create_default_account(&deployment.account_factory)?;

deployment
.version_control
.claim_namespace(1, "tester".to_owned())?;

let app = MockApp::new_test(chain);
app.deploy(APP_VERSION.parse().unwrap())?;
let app_addr = account.install_app(app, &MockInitMsg, None)?;
let module_addr = account.manager.module_info(APP_ID)?.unwrap().address;
assert_that!(app_addr).is_equal_to(module_addr);
Ok(())
}
8 changes: 5 additions & 3 deletions framework/contracts/native/module-factory/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub fn execute_create_module(
),
ModuleReference::Adapter(addr) => {
let module_id = new_module.info.id_with_version();
let new_module_addr = addr.to_string();
let register_msg: CosmosMsg<Empty> = wasm_execute(
account_base.manager.into_string(),
&ManagerMsg::RegisterModule {
Expand All @@ -102,10 +103,11 @@ pub fn execute_create_module(
vec![],
)?
.into();
Ok(
ModuleFactoryResponse::new("execute_create_module", vec![("module", &module_id)])
.add_message(register_msg),
Ok(ModuleFactoryResponse::new(
"execute_create_module",
vec![("module", module_id), ("new_module", new_module_addr)],
)
.add_message(register_msg))
}
ModuleReference::Standalone(code_id) => instantiate_contract(
block_height,
Expand Down
6 changes: 2 additions & 4 deletions framework/contracts/native/version-control/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ pub fn handle_module_list_query(
mod_lib
.range(deps.storage, start_bound, None, Order::Ascending)
.take(limit)
.collect::<StdResult<Vec<_>>>()?
.into_iter(),
.collect::<StdResult<Vec<_>>>()?,
);
};

Expand Down Expand Up @@ -162,8 +161,7 @@ pub fn handle_namespaces_query(
.account_id
.prefix(account_id)
.range(deps.storage, None, None, Order::Ascending)
.collect::<StdResult<Vec<_>>>()?
.into_iter(),
.collect::<StdResult<Vec<_>>>()?,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> PrimaryKey<'a> for &ChannelEntry {
impl<'a> Prefixer<'a> for &ChannelEntry {
fn prefix(&self) -> Vec<Key> {
let mut res = self.connected_chain.prefix();
res.extend(self.protocol.prefix().into_iter());
res.extend(self.protocol.prefix());
res
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> PrimaryKey<'a> for &ContractEntry {
impl<'a> Prefixer<'a> for &ContractEntry {
fn prefix(&self) -> Vec<Key> {
let mut res = self.protocol.prefix();
res.extend(self.contract.prefix().into_iter());
res.extend(self.contract.prefix());
res
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ impl<'a> PrimaryKey<'a> for &DexAssetPairing {
impl<'a> Prefixer<'a> for &DexAssetPairing {
fn prefix(&self) -> Vec<cw_storage_plus::Key> {
let mut res = self.0 .0 .0.prefix();
res.extend(self.0 .1 .0.prefix().into_iter());
res.extend(self.0 .2.prefix().into_iter());
res.extend(self.0 .1 .0.prefix());
res.extend(self.0 .2.prefix());
res
}
}
Expand Down
4 changes: 2 additions & 2 deletions framework/packages/abstract-core/src/objects/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl<'a> PrimaryKey<'a> for &ModuleInfo {
impl<'a> Prefixer<'a> for &ModuleInfo {
fn prefix(&self) -> Vec<Key> {
let mut res = self.namespace.prefix();
res.extend(self.name.prefix().into_iter());
res.extend(self.version.prefix().into_iter());
res.extend(self.name.prefix());
res.extend(self.version.prefix());
res
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl fmt::Display for PoolMetadata {
write!(
f,
"{}",
vec![self.dex.clone(), assets_str, pool_type_str].join(ATTTRIBUTE_SEPARATOR)
[self.dex.clone(), assets_str, pool_type_str].join(ATTTRIBUTE_SEPARATOR)
)
}
}
Expand Down
23 changes: 15 additions & 8 deletions framework/packages/abstract-interface/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<Chain: CwEnv> AbstractAccount<Chain> {
adapter: T,
custom_init_msg: &CustomInitMsg,
funds: Option<&[Coin]>,
) -> Result<(), crate::AbstractInterfaceError> {
) -> Result<Addr, crate::AbstractInterfaceError> {
// retrieve the deployment
let abstr = Abstract::load_from(self.manager.get_chain().to_owned())?;

Expand All @@ -143,8 +143,7 @@ impl<Chain: CwEnv> AbstractAccount<Chain> {
version_control_address: abstr.version_control.address()?.into(),
},
};
self.install_module(&adapter.id(), &init_msg, funds)?;
Ok(())
self.install_module_parse_addr(adapter, &init_msg, funds)
}

/// Installs an app from an app object
Expand All @@ -163,13 +162,21 @@ impl<Chain: CwEnv> AbstractAccount<Chain> {
ans_host_address: abstr.ans_host.address()?.into(),
},
};
let resp = self.install_module(&app.id(), &init_msg, funds)?;
self.install_module_parse_addr(app, &init_msg, funds)
}

let app_address = resp.event_attr_value(ABSTRACT_EVENT_TYPE, "new_module")?;
let app_address = Addr::unchecked(app_address);
fn install_module_parse_addr<InitMsg: Serialize, T: ContractInstance<Chain>>(
&self,
module: T,
init_msg: &InitMsg,
funds: Option<&[Coin]>,
) -> Result<Addr, crate::AbstractInterfaceError> {
let resp = self.install_module(&module.id(), &init_msg, funds)?;
let module_address = resp.event_attr_value(ABSTRACT_EVENT_TYPE, "new_module")?;
let module_address = Addr::unchecked(module_address);

app.set_address(&app_address);
Ok(app_address)
module.set_address(&module_address);
Ok(module_address)
}
}

Expand Down