From 33c67f57d036fbd531cab3deb1a2281ac6cfdbc6 Mon Sep 17 00:00:00 2001 From: Buckram Date: Sun, 15 Sep 2024 17:46:11 +0300 Subject: [PATCH 01/12] fix testing packages --- framework/Cargo.lock | 1 + framework/Cargo.toml | 3 +- .../contracts/account/tests/subaccount.rs | 10 +- framework/packages/abstract-client/Cargo.toml | 1 + .../packages/abstract-client/src/account.rs | 17 +- .../abstract-client/tests/integration.rs | 310 +++++++++--------- .../abstract-interface/examples/deploy.rs | 11 +- .../abstract-interface/src/account.rs | 105 +++++- .../abstract-interface/src/interfaces.rs | 2 +- .../packages/abstract-std/src/objects/salt.rs | 4 +- .../abstract-testing/src/mock_querier.rs | 2 +- 11 files changed, 271 insertions(+), 195 deletions(-) diff --git a/framework/Cargo.lock b/framework/Cargo.lock index a838b6e34..89a3ce4da 100644 --- a/framework/Cargo.lock +++ b/framework/Cargo.lock @@ -125,6 +125,7 @@ dependencies = [ name = "abstract-client" version = "0.23.0" dependencies = [ + "abstract-account", "abstract-adapter", "abstract-app", "abstract-client", diff --git a/framework/Cargo.toml b/framework/Cargo.toml index 1d74489c8..3b94dcfd6 100644 --- a/framework/Cargo.toml +++ b/framework/Cargo.toml @@ -78,8 +78,7 @@ version-control = { package = "abstract-version-control", path = "contracts/nati ibc-client = { package = "abstract-ibc-client", path = "contracts/native/ibc-client" } ibc-host = { package = "abstract-ibc-host", path = "contracts/native/ibc-host" } -proxy = { package = "abstract-proxy", path = "contracts/account/proxy", default-features = false } -manager = { package = "abstract-manager", path = "contracts/account/manager", default-features = false } +abstract-account = { path = "contracts/account", default-features = false } abstract-ica = { path = "packages/abstract-ica" } abstract-sdk = { version = "0.23.0", path = "packages/abstract-sdk" } diff --git a/framework/contracts/account/tests/subaccount.rs b/framework/contracts/account/tests/subaccount.rs index 260968544..c1b5b733f 100644 --- a/framework/contracts/account/tests/subaccount.rs +++ b/framework/contracts/account/tests/subaccount.rs @@ -56,7 +56,7 @@ fn updating_on_subaccount_should_succeed() -> AResult { )?; // Subaccount should have id 2 in this test, we try to update the config of this module - let account_contracts = get_account_contracts(&deployment.version_control, AccountId::local(2)); + let account_contracts = get_account_contract(&deployment.version_control, AccountId::local(2)); let new_desc = "new desc"; account_contracts .0 @@ -88,7 +88,7 @@ fn proxy_updating_on_subaccount_should_succeed() -> AResult { )?; // Subaccount should have id 2 in this test, we try to update the config of this module - let (sub_manager, _) = get_account_contracts(&deployment.version_control, AccountId::local(2)); + let (sub_manager, _) = get_account_contract(&deployment.version_control, AccountId::local(2)); let new_desc = "new desc"; // We call as the proxy, it should also be possible @@ -122,7 +122,7 @@ fn recursive_updating_on_subaccount_should_succeed() -> AResult { )?; // Subaccount should have id 2 in this test, we try to update the config of this module - let account_contracts = get_account_contracts(&deployment.version_control, AccountId::local(2)); + let account_contracts = get_account_contract(&deployment.version_control, AccountId::local(2)); // We call as the manager, it should also be possible account_contracts.0.create_sub_account( @@ -134,7 +134,7 @@ fn recursive_updating_on_subaccount_should_succeed() -> AResult { None, &[], )?; - let account_contracts = get_account_contracts(&deployment.version_control, AccountId::local(3)); + let account_contracts = get_account_contract(&deployment.version_control, AccountId::local(3)); let new_desc = "new desc"; account_contracts @@ -175,7 +175,7 @@ fn installed_app_updating_on_subaccount_should_succeed() -> AResult { .add_modules(vec![mock_app.to_string()])?; let (sub_manager, _sub_proxy) = - get_account_contracts(&deployment.version_control, AccountId::local(2)); + get_account_contract(&deployment.version_control, AccountId::local(2)); let new_desc = "new desc"; // recover address on first proxy diff --git a/framework/packages/abstract-client/Cargo.toml b/framework/packages/abstract-client/Cargo.toml index 43fcbc018..bd697595b 100644 --- a/framework/packages/abstract-client/Cargo.toml +++ b/framework/packages/abstract-client/Cargo.toml @@ -51,6 +51,7 @@ workspace-hack = { version = "0.1", path = "../../workspace-hack" } [dev-dependencies] abstract-testing.workspace = true abstract-client = { path = ".", features = ["test-utils", "interchain"] } +abstract-account = { workspace = true } polytone = { workspace = true } cw-asset.workspace = true cw-controllers.workspace = true diff --git a/framework/packages/abstract-client/src/account.rs b/framework/packages/abstract-client/src/account.rs index d770ac179..52f8e4ae0 100644 --- a/framework/packages/abstract-client/src/account.rs +++ b/framework/packages/abstract-client/src/account.rs @@ -88,7 +88,6 @@ pub struct AccountBuilder<'a, Chain: CwEnv> { funds: AccountCreationFunds, fetch_if_namespace_claimed: bool, install_on_sub_account: bool, - expected_local_account_id: Option, } /// Creation funds @@ -113,7 +112,6 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { funds: AccountCreationFunds::Coins(Coins::default()), fetch_if_namespace_claimed: true, install_on_sub_account: false, - expected_local_account_id: None, } } @@ -282,14 +280,6 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { Ok(self) } - /// Assign expected local account_id on creation. - /// It's designed to be used in pair with [`crate::AbstractClient::random_account_id`]. - /// The tx will error if this account id already claimed or it's less than 2147483648. Useful for instantiate2 address prediction. - pub fn expected_account_id(&mut self, local_account_id: u32) -> &mut Self { - self.expected_local_account_id = Some(local_account_id); - self - } - /// Builds the [`Account`]. pub fn build(&self) -> AbstractClientResult> { let install_modules = self.install_modules(); @@ -343,10 +333,7 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { install_modules, }; let abstract_account = match self.owner_account { - None => { - // https://github.com/AbstractSDK/abstract/pull/446#discussion_r1756768435 - todo!() - } + None => AccountI::create(self.abstr, account_details, ownership, &funds)?, Some(owner_account) => owner_account .abstr_account .create_sub_account_helper(account_details, &funds)?, @@ -996,7 +983,7 @@ pub mod test { let abstr = AbstractClient::builder(mock.clone()).build()?; let my_namespace = "my-namespace"; - let new_account = abstr_builder().build()?; + let new_account = abstr.account_builder().build()?; new_account.claim_namespace(my_namespace)?; // Verify the namespace exists diff --git a/framework/packages/abstract-client/tests/integration.rs b/framework/packages/abstract-client/tests/integration.rs index fb8e92eb1..ab188212f 100644 --- a/framework/packages/abstract-client/tests/integration.rs +++ b/framework/packages/abstract-client/tests/integration.rs @@ -1,3 +1,4 @@ +use abstract_account::error::AccountError; use abstract_adapter::mock::{ interface::MockAdapterI, MockExecMsg as AdapterMockExecMsg, MockInitMsg as AdapterMockInitMsg, MockQueryMsg as AdapterMockQueryMsg, TEST_METADATA, @@ -20,11 +21,11 @@ use abstract_interface::{ ClientResolve, IbcClient, InstallConfig, RegisteredModule, VCExecFns, VCQueryFns, }; use abstract_std::{ + account::{ + state::AccountInfo, AccountModuleInfo, ModuleAddressesResponse, ModuleInfosResponse, + }, adapter::AuthorizedAddressesResponse, ans_host::QueryMsgFns, - manager::{ - state::AccountInfo, ManagerModuleInfo, ModuleAddressesResponse, ModuleInfosResponse, - }, objects::{ dependency::Dependency, fee::FixedFee, gov_type::GovernanceDetails, module_version::ModuleDataResponse, namespace::Namespace, version_control, AccountId, @@ -52,7 +53,6 @@ fn can_create_account_without_optional_parameters() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Default Abstract Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -94,7 +94,6 @@ fn can_create_account_with_optional_parameters() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from(name), - chain_id: String::from("cosmos-testnet-14002"), description: Some(String::from(description)), link: Some(String::from(link)), }, @@ -164,7 +163,6 @@ fn can_create_publisher_without_optional_parameters() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Default Abstract Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -203,7 +201,6 @@ fn can_create_publisher_with_optional_parameters() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from(name), - chain_id: String::from("cosmos-testnet-14002"), description: Some(String::from(description)), link: Some(String::from(link)), }, @@ -254,8 +251,7 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { .build()?; let publisher_account = publisher.account(); - let publisher_manager = publisher_account.address()?; - let publisher_proxy = publisher_account.address()?; + let publisher_account_address = publisher_account.address()?; publisher.publish_app::>()?; @@ -263,7 +259,7 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { let my_app: Application<_, MockAppI<_>> = publisher_account.install_app::>(&MockInitMsg {}, &[])?; - my_app.call_as(&publisher_manager).do_something()?; + my_app.call_as(&publisher_account_address).do_something()?; let something = my_app.get_something()?; @@ -278,7 +274,6 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Sub Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -288,8 +283,7 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { assert_eq!( sub_account_ownership.owner, GovernanceDetails::SubAccount { - manager: publisher_manager.to_string(), - proxy: publisher_proxy.to_string(), + account: publisher_account_address.to_string(), } ); @@ -305,7 +299,9 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { let my_adapter: Application<_, MockAppI<_>> = publisher.account().install_app(&MockInitMsg {}, &[])?; - my_adapter.call_as(&publisher_manager).do_something()?; + my_adapter + .call_as(&publisher_account_address) + .do_something()?; let mock_query: MockQueryResponse = my_adapter.get_something()?; assert_eq!(MockQueryResponse {}, mock_query); @@ -314,7 +310,6 @@ fn can_publish_and_install_app() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Default Abstract Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -341,8 +336,7 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { .install_on_sub_account(true) .build()?; - let publisher_manager = publisher.account().address()?; - let publisher_proxy = publisher.account().address()?; + let publisher_account_address = publisher.account().address()?; publisher.publish_adapter::>(AdapterMockInitMsg {})?; @@ -350,7 +344,7 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { let my_adapter: Application<_, MockAdapterI<_>> = publisher.account().install_adapter(&[])?; my_adapter - .call_as(&publisher_manager) + .call_as(&publisher_account_address) .execute(&AdapterMockExecMsg {}.into(), &[])?; let mock_query: String = my_adapter.query(&AdapterMockQueryMsg::GetSomething {}.into())?; @@ -360,7 +354,6 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Sub Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -370,8 +363,7 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { assert_eq!( sub_account_ownership.owner, GovernanceDetails::SubAccount { - manager: publisher_manager.to_string(), - proxy: publisher_proxy.to_string(), + account: publisher_account_address.to_string(), } ); @@ -383,7 +375,7 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { let my_adapter: Application<_, MockAdapterI<_>> = publisher.account().install_adapter(&[])?; my_adapter - .call_as(&publisher_manager) + .call_as(&publisher_account_address) .execute(&AdapterMockExecMsg {}.into(), &[])?; let mock_query: String = my_adapter.query(&AdapterMockQueryMsg::GetSomething {}.into())?; @@ -393,7 +385,6 @@ fn can_publish_and_install_adapter() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Default Abstract Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -505,7 +496,7 @@ fn can_install_module_with_dependencies() -> anyhow::Result<()> { assert!(module_infos_response .module_infos - .contains(&ManagerModuleInfo { + .contains(&AccountModuleInfo { id: TEST_MODULE_ID.to_owned(), version: cw2::ContractVersion { contract: TEST_MODULE_ID.to_owned(), @@ -516,7 +507,7 @@ fn can_install_module_with_dependencies() -> anyhow::Result<()> { assert!(module_infos_response .module_infos - .contains(&ManagerModuleInfo { + .contains(&AccountModuleInfo { id: TEST_MODULE_ID.to_owned(), version: cw2::ContractVersion { contract: TEST_MODULE_ID.to_owned(), @@ -839,7 +830,6 @@ fn doc_example_test() -> anyhow::Result<()> { assert_eq!( AccountInfo { name: String::from("Default Abstract Account"), - chain_id: String::from("cosmos-testnet-14002"), description: None, link: None, }, @@ -860,7 +850,7 @@ fn can_get_abstract_account_from_client_account() -> anyhow::Result<()> { let client: AbstractClient = AbstractClient::builder(chain).build()?; let account = client.account_builder().build()?; - let abstract_account: &abstract_interface::AbstractAccount = account.as_ref(); + let abstract_account: &abstract_interface::AccountI = account.as_ref(); assert_eq!(abstract_account.id()?, AccountId::local(1)); Ok(()) } @@ -943,8 +933,7 @@ fn cant_create_sub_accounts_for_another_user() -> anyhow::Result<()> { .account_builder() .name("foo-bar") .ownership(GovernanceDetails::SubAccount { - manager: account.address()?.into_string(), - proxy: account.address()?.into_string(), + account: account.address()?.into_string(), }) .build(); @@ -954,12 +943,12 @@ fn cant_create_sub_accounts_for_another_user() -> anyhow::Result<()> { else { panic!("Expected cw-orch error") }; - let err: account_factory::error::AccountFactoryError = err.downcast().unwrap(); + let err: AccountError = err.downcast().unwrap(); assert_eq!( err, - account_factory::error::AccountFactoryError::SubAccountCreatorNotAccount { + AccountError::SubAccountCreatorNotAccount { caller: client.sender().into_string(), - manager: account.address()?.into_string() + account: account.address()?.into_string() } ); Ok(()) @@ -988,7 +977,7 @@ fn install_adapter_on_account_builder() -> anyhow::Result<()> { assert_eq!( *adapter_info, - ManagerModuleInfo { + AccountModuleInfo { id: MockAdapterI::::module_id().to_owned(), version: cw2::ContractVersion { contract: MockAdapterI::::module_id().to_owned(), @@ -1030,7 +1019,7 @@ fn install_application_on_account_builder() -> anyhow::Result<()> { assert_eq!( *app_info, - ManagerModuleInfo { + AccountModuleInfo { id: MockAppI::::module_id().to_owned(), version: cw2::ContractVersion { contract: MockAppI::::module_id().to_owned(), @@ -1128,7 +1117,7 @@ fn install_application_with_deps_on_account_builder() -> anyhow::Result<()> { assert_eq!( *app_info, - ManagerModuleInfo { + AccountModuleInfo { id: MockAppI::::module_id().to_owned(), version: cw2::ContractVersion { contract: MockAppI::::module_id().to_owned(), @@ -1156,7 +1145,7 @@ fn install_application_with_deps_on_account_builder() -> anyhow::Result<()> { assert_eq!( *app_info, - ManagerModuleInfo { + AccountModuleInfo { id: MockAppWithDepI::::module_id().to_owned(), version: cw2::ContractVersion { contract: MockAppWithDepI::::module_id().to_owned(), @@ -1205,109 +1194,127 @@ fn authorize_app_on_adapters() -> anyhow::Result<()> { Ok(()) } -#[test] -fn create_account_with_expected_account_id() -> anyhow::Result<()> { - let chain = MockBech32::new("mock"); - let client = AbstractClient::builder(chain).build()?; - - // Check it fails on wrong account_id - let next_id = client.random_account_id()?; - let err = client - .account_builder() - .expected_account_id(10) - .build() - .unwrap_err(); - let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err - else { - panic!("Expected cw-orch error") - }; - let err: account_factory::error::AccountFactoryError = err.downcast().unwrap(); - assert_eq!( - err, - account_factory::error::AccountFactoryError::PredictableAccountIdFailed {} - ); - - // Can create if right id - let account = client - .account_builder() - .expected_account_id(next_id) - .build()?; - - // Check it fails on wrong account_id for sub-accounts - let next_id = client.random_account_id()?; - let err = client - .account_builder() - .sub_account(&account) - .expected_account_id(0) - .build() - .unwrap_err(); - let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err - else { - panic!("Expected cw-orch error") - }; - let err: account_factory::error::AccountFactoryError = err.downcast().unwrap(); - assert_eq!( - err, - account_factory::error::AccountFactoryError::PredictableAccountIdFailed {} - ); - - // Can create sub-account if right id - let sub_account = client - .account_builder() - .sub_account(&account) - .expected_account_id(next_id) - .build()?; - let sub_accounts = account.sub_accounts()?; - assert_eq!(sub_accounts[0].id()?, sub_account.id()?); - Ok(()) -} - -#[test] -fn instantiate2_addr() -> anyhow::Result<()> { - let chain = MockBech32::new("mock"); - let client = AbstractClient::builder(chain).build()?; - - let publisher: Publisher = client - .publisher_builder(Namespace::new(TEST_NAMESPACE)?) - .build()?; - - publisher.publish_app::>()?; - - let account_id = AccountId::local(client.random_account_id()?); - let expected_addr = client.module_instantiate2_address::>(&account_id)?; - - let sub_account = client - .account_builder() - .sub_account(publisher.account()) - .expected_account_id(account_id.seq()) - .install_app::>(&MockInitMsg {})? - .build()?; - let application = sub_account.application::>()?; - - assert_eq!(application.address()?, expected_addr); - Ok(()) -} - -#[test] -fn instantiate2_raw_addr() -> anyhow::Result<()> { - let chain = MockBech32::new("mock"); - let client = AbstractClient::builder(chain).build()?; - - let next_seq = client.random_account_id()?; - let account_id = AccountId::local(next_seq); - - let proxy_addr = client.module_instantiate2_address_raw( - &account_id, - ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, - )?; - let account = client - .account_builder() - .expected_account_id(next_seq) - .build()?; - - assert_eq!(account.address()?, proxy_addr); - Ok(()) -} +// #[test] +// fn create_account_with_expected_account_id() -> anyhow::Result<()> { +// let chain = MockBech32::new("mock"); +// let client = AbstractClient::builder(chain).build()?; + +// // Check it fails on wrong account_id +// let next_id = client.random_account_id()?; +// let err = client +// .account_builder() +// .expected_account_id(10) +// .build() +// .unwrap_err(); +// let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err +// else { +// panic!("Expected cw-orch error") +// }; +// let err: AccountError = err.downcast().unwrap(); +// assert_eq!(err, AccountError::PredictableAccountIdFailed {}); + +// // Can create if right id +// let account = client +// .account_builder() +// .expected_account_id(next_id) +// .build()?; + +// // Check it fails on wrong account_id for sub-accounts +// let next_id = client.random_account_id()?; +// let err = client +// .account_builder() +// .sub_account(&account) +// .expected_account_id(0) +// .build() +// .unwrap_err(); +// let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err +// else { +// panic!("Expected cw-orch error") +// }; +// let err: account_factory::error::AccountFactoryError = err.downcast().unwrap(); +// assert_eq!( +// err, +// account_factory::error::AccountFactoryError::PredictableAccountIdFailed {} +// ); + +// // Can create sub-account if right id +// let sub_account = client +// .account_builder() +// .sub_account(&account) +// .expected_account_id(next_id) +// .build()?; +// let sub_accounts = account.sub_accounts()?; +// assert_eq!(sub_accounts[0].id()?, sub_account.id()?); +// Ok(()) +// } + +// #[test] +// fn instantiate2_addr() -> anyhow::Result<()> { +// let chain = MockBech32::new("mock"); +// let client = AbstractClient::builder(chain).build()?; + +// let publisher: Publisher = client +// .publisher_builder(Namespace::new(TEST_NAMESPACE)?) +// .build()?; + +// publisher.publish_app::>()?; + +// let account_id = AccountId::local(client.random_account_id()?); +// let expected_addr = client.module_instantiate2_address::>(&account_id)?; + +// let sub_account = client +// .account_builder() +// .sub_account(publisher.account()) +// .expected_account_id(account_id.seq()) +// .install_app::>(&MockInitMsg {})? +// .build()?; +// let application = sub_account.application::>()?; + +// assert_eq!(application.address()?, expected_addr); +// Ok(()) +// } + +// #[test] +// fn instantiate2_raw_addr() -> anyhow::Result<()> { +// let chain = MockBech32::new("mock"); +// let client = AbstractClient::builder(chain).build()?; + +// let next_seq = client.random_account_id()?; +// let account_id = AccountId::local(next_seq); + +// let proxy_addr = client.module_instantiate2_address_raw( +// &account_id, +// ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, +// )?; +// let account = client +// .account_builder() +// .expected_account_id(next_seq) +// .build()?; + +// assert_eq!(account.address()?, proxy_addr); +// Ok(()) +// } + +// #[test] +// fn instantiate2_random_seq() -> anyhow::Result<()> { +// let chain = MockBech32::new("mock"); +// let client = AbstractClient::builder(chain).build()?; + +// let next_seq = client.random_account_id()?; +// let account_id = AccountId::local(next_seq); + +// let proxy_addr = client.module_instantiate2_address_raw( +// &account_id, +// ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, +// )?; +// let account = client +// .account_builder() +// .expected_account_id(next_seq) +// .build()?; + +// assert_eq!(account.address()?, proxy_addr); +// Ok(()) +// } #[test] fn install_same_app_on_different_accounts() -> anyhow::Result<()> { @@ -1347,27 +1354,6 @@ fn install_same_app_on_different_accounts() -> anyhow::Result<()> { Ok(()) } -#[test] -fn instantiate2_random_seq() -> anyhow::Result<()> { - let chain = MockBech32::new("mock"); - let client = AbstractClient::builder(chain).build()?; - - let next_seq = client.random_account_id()?; - let account_id = AccountId::local(next_seq); - - let proxy_addr = client.module_instantiate2_address_raw( - &account_id, - ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, - )?; - let account = client - .account_builder() - .expected_account_id(next_seq) - .build()?; - - assert_eq!(account.address()?, proxy_addr); - Ok(()) -} - #[test] fn install_ibc_client_on_creation() -> anyhow::Result<()> { let chain = MockBech32::new("mock"); @@ -1453,9 +1439,7 @@ fn retrieve_account_builder_install_missing_modules() -> anyhow::Result<()> { fn module_status() -> anyhow::Result<()> { let chain = MockBech32::new("mock"); let client = AbstractClient::builder(chain).build()?; - client - .version_control() - .update_config(None, None, Some(false))?; + client.version_control().update_config(None, Some(false))?; let app_publisher: Publisher = client .publisher_builder(Namespace::new(TEST_NAMESPACE)?) diff --git a/framework/packages/abstract-interface/examples/deploy.rs b/framework/packages/abstract-interface/examples/deploy.rs index f7b2b6af4..2a814c6b3 100644 --- a/framework/packages/abstract-interface/examples/deploy.rs +++ b/framework/packages/abstract-interface/examples/deploy.rs @@ -1,4 +1,4 @@ -use abstract_interface::Abstract; +use abstract_interface::{Abstract, AccountI}; use abstract_std::objects::gov_type::GovernanceDetails; use cw_orch::{ daemon::networks::LOCAL_JUNO, @@ -13,9 +13,12 @@ fn full_deploy(networks: Vec) -> cw_orch::anyhow::Result<()> { let deployment = Abstract::deploy_on(chain, sender.to_string())?; // Create the Abstract Account because it's needed for the fees for the dex module - deployment.create_default_account(GovernanceDetails::Monarchy { - monarch: sender.to_string(), - })?; + AccountI::create_default_account( + &deployment, + GovernanceDetails::Monarchy { + monarch: sender.to_string(), + }, + )?; } Ok(()) diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index b0ecc8b46..104827ebe 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -12,7 +12,7 @@ //! - upgrade module use crate::{ - get_account_contracts, Abstract, AbstractInterfaceError, AdapterDeployer, VersionControl, + get_account_contract, Abstract, AbstractInterfaceError, AdapterDeployer, VersionControl, }; pub use abstract_std::account::{ExecuteMsgFns as ManagerExecFns, QueryMsgFns as ManagerQueryFns}; use abstract_std::{ @@ -21,6 +21,7 @@ use abstract_std::{ ibc_host::{HelperAction, HostAction}, module_factory::SimulateInstallModulesResponse, objects::{ + gov_type::GovernanceDetails, module::{ModuleInfo, ModuleStatus, ModuleVersion}, AccountId, TruncatedChainId, }, @@ -51,13 +52,113 @@ pub struct AccountI; impl AccountI { pub fn load_from(abstract_deployment: &Abstract, account_id: AccountId) -> Self { - get_account_contracts(&abstract_deployment.version_control, account_id) + get_account_contract(&abstract_deployment.version_control, account_id) } pub(crate) fn new_from_id(account_id: &AccountId, chain: Chain) -> Self { let account_id = format!("{ACCOUNT}-{account_id}"); Self::new(account_id, chain) } + + /// Create account, `b"abstract_account"` used as a salt + pub fn create( + abstract_deployment: &Abstract, + details: AccountDetails, + governance_details: GovernanceDetails, + funds: &[cosmwasm_std::Coin], + ) -> Result { + let salt = Binary::from(b"abstract_account"); + + Self::_create_account( + abstract_deployment, + details, + governance_details, + salt, + funds, + ) + } + + pub fn create_default_account( + abstract_deployment: &Abstract, + governance_details: GovernanceDetails, + ) -> Result { + let details = AccountDetails { + name: "Default Abstract Account".into(), + ..Default::default() + }; + Self::create(abstract_deployment, details, governance_details, &[]) + } + + fn _create_account( + abstract_deployment: &Abstract, + details: AccountDetails, + governance_details: GovernanceDetails, + salt: Binary, + funds: &[Coin], + ) -> Result { + let chain = abstract_deployment.version_control.environment().clone(); + let code_id = abstract_deployment.account.code_id().unwrap(); + + let account_addr = chain + .wasm_querier() + .instantiate2_addr(code_id, &chain.sender_addr(), salt.clone()) + .map_err(Into::into)?; + let account_addr = Addr::unchecked(account_addr); + + chain + .instantiate2( + code_id, + &InstantiateMsg { + account_id: None, + owner: governance_details, + namespace: details.namespace, + install_modules: details.install_modules, + name: details.name, + description: details.description, + link: details.link, + module_factory_address: abstract_deployment.module_factory.addr_str()?, + version_control_address: abstract_deployment.version_control.addr_str()?, + }, + Some("Abstract Account"), + Some(&account_addr), + funds, + salt, + ) + .map_err(Into::into)?; + + let account_id = chain + .wasm_querier() + .item_query(&account_addr, state::ACCOUNT_ID)?; + let contract_id = format!("{ACCOUNT}_{account_id}"); + + let account = Self::new(contract_id, chain); + account.set_address(&account_addr); + Ok(account) + } +} + +#[cfg(feature = "daemon")] +impl AccountI { + /// Create account, account sequence used as a salt + pub fn create_sequenced( + abstract_deployment: &Abstract, + details: AccountDetails, + governance_details: GovernanceDetails, + funds: &[cosmwasm_std::Coin], + ) -> Result { + let chain = abstract_deployment.version_control.environment(); + + let base = chain.rt_handle.block_on(chain.sender().base_account())?; + let salt = cosmwasm_std::Binary::from(base.sequence.to_be_bytes()); + + Self::_create_account( + abstract_deployment, + details, + governance_details, + salt, + funds, + ) + } } impl Uploadable for AccountI { diff --git a/framework/packages/abstract-interface/src/interfaces.rs b/framework/packages/abstract-interface/src/interfaces.rs index a3ad35fc4..0fd2a44a3 100644 --- a/framework/packages/abstract-interface/src/interfaces.rs +++ b/framework/packages/abstract-interface/src/interfaces.rs @@ -18,7 +18,7 @@ where (ans_host, version_control, module_factory) } -pub fn get_account_contracts( +pub fn get_account_contract( version_control: &VersionControl, account_id: AccountId, ) -> AccountI diff --git a/framework/packages/abstract-std/src/objects/salt.rs b/framework/packages/abstract-std/src/objects/salt.rs index 0adcbbc71..455aa4f87 100644 --- a/framework/packages/abstract-std/src/objects/salt.rs +++ b/framework/packages/abstract-std/src/objects/salt.rs @@ -2,12 +2,12 @@ use super::AccountId; use cosmwasm_std::Binary; -pub const SALT_POSTFIX: &[u8] = b"abstract"; +pub const ABSTRACT_SALT: &[u8] = b"abstract"; /// Generate salt helper pub fn generate_instantiate_salt(account_id: &AccountId) -> Binary { let account_id_hash = ::digest(account_id.to_string()); let mut hash = account_id_hash.to_vec(); - hash.extend(SALT_POSTFIX); + hash.extend(ABSTRACT_SALT); Binary::new(hash) } diff --git a/framework/packages/abstract-testing/src/mock_querier.rs b/framework/packages/abstract-testing/src/mock_querier.rs index 6d22129cd..1ae139970 100644 --- a/framework/packages/abstract-testing/src/mock_querier.rs +++ b/framework/packages/abstract-testing/src/mock_querier.rs @@ -409,7 +409,7 @@ pub fn wrap_querier(querier: &MockQuerier) -> QuerierWrapper<'_, Empty> { #[cfg(test)] mod tests { use abstract_std::{ - manager::state::ACCOUNT_MODULES, proxy::state::ACCOUNT_ID, + account::state::ACCOUNT_ID, account::state::ACCOUNT_MODULES, version_control::state::ACCOUNT_ADDRESSES, }; use cosmwasm_std::testing; From 1d7da0432210c62bc5b2f29b333e5bedce5fca65 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 12:16:36 +0300 Subject: [PATCH 02/12] update account creation --- framework/contracts/account/src/contract.rs | 2 + .../contracts/account/src/sub_account.rs | 7 +- .../packages/abstract-client/src/account.rs | 12 +++ .../abstract-interface/src/account.rs | 84 +++++++------------ .../packages/abstract-std/src/account/mod.rs | 5 ++ 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/framework/contracts/account/src/contract.rs b/framework/contracts/account/src/contract.rs index d48b3b72d..030f42635 100644 --- a/framework/contracts/account/src/contract.rs +++ b/framework/contracts/account/src/contract.rs @@ -232,6 +232,7 @@ pub fn execute(mut deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) link, namespace, install_modules, + account_id, } => create_sub_account( deps, info, @@ -241,6 +242,7 @@ pub fn execute(mut deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) link, namespace, install_modules, + account_id, ) .map_err(AccountError::from), ExecuteMsg::Upgrade { modules } => { diff --git a/framework/contracts/account/src/sub_account.rs b/framework/contracts/account/src/sub_account.rs index a817d4c25..e4ce6e861 100644 --- a/framework/contracts/account/src/sub_account.rs +++ b/framework/contracts/account/src/sub_account.rs @@ -29,12 +29,15 @@ pub fn create_sub_account( link: Option, namespace: Option, install_modules: Vec, + account_id: Option, ) -> AccountResult { // only owner can create a subaccount ownership::assert_nested_owner(deps.storage, &deps.querier, &info.sender)?; let config = CONFIG.load(deps.storage)?; - let seq = abstract_std::version_control::state::LOCAL_ACCOUNT_SEQUENCE - .query(&deps.querier, config.version_control_address.clone())?; + let seq = account_id.unwrap_or( + abstract_std::version_control::state::LOCAL_ACCOUNT_SEQUENCE + .query(&deps.querier, config.version_control_address.clone())?, + ); let account_id = AccountId::local(seq); let salt = cosmwasm_std::to_json_binary(&seq)?; diff --git a/framework/packages/abstract-client/src/account.rs b/framework/packages/abstract-client/src/account.rs index 52f8e4ae0..b9e86d412 100644 --- a/framework/packages/abstract-client/src/account.rs +++ b/framework/packages/abstract-client/src/account.rs @@ -88,6 +88,7 @@ pub struct AccountBuilder<'a, Chain: CwEnv> { funds: AccountCreationFunds, fetch_if_namespace_claimed: bool, install_on_sub_account: bool, + expected_local_account_id: Option, } /// Creation funds @@ -112,6 +113,7 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { funds: AccountCreationFunds::Coins(Coins::default()), fetch_if_namespace_claimed: true, install_on_sub_account: false, + expected_local_account_id: None, } } @@ -280,6 +282,14 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { Ok(self) } + /// Assign expected local account_id on creation. + /// It's designed to be used in pair with [`crate::AbstractClient::random_account_id`]. + /// The tx will error if this account id already claimed or it's less than 2147483648. Useful for instantiate2 address prediction. + pub fn expected_account_id(&mut self, local_account_id: u32) -> &mut Self { + self.expected_local_account_id = Some(local_account_id); + self + } + /// Builds the [`Account`]. pub fn build(&self) -> AbstractClientResult> { let install_modules = self.install_modules(); @@ -331,6 +341,7 @@ impl<'a, Chain: CwEnv> AccountBuilder<'a, Chain> { link: self.link.clone(), namespace: self.namespace.as_ref().map(ToString::to_string), install_modules, + account_id: self.expected_local_account_id, }; let abstract_account = match self.owner_account { None => AccountI::create(self.abstr, account_details, ownership, &funds)?, @@ -825,6 +836,7 @@ impl Account { None, None, None, + None, funds, )?; diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index 104827ebe..7e6b8accf 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -23,9 +23,10 @@ use abstract_std::{ objects::{ gov_type::GovernanceDetails, module::{ModuleInfo, ModuleStatus, ModuleVersion}, + salt::generate_instantiate_salt, AccountId, TruncatedChainId, }, - version_control::{ExecuteMsgFns, ModuleFilter, QueryMsgFns}, + version_control::{state::LOCAL_ACCOUNT_SEQUENCE, ExecuteMsgFns, ModuleFilter, QueryMsgFns}, ABSTRACT_EVENT_TYPE, ACCOUNT, IBC_CLIENT, }; use cosmwasm_std::{from_json, to_json_binary}; @@ -45,6 +46,7 @@ pub struct AccountDetails { pub link: Option, pub namespace: Option, pub install_modules: Vec, + pub account_id: Option, } #[interface(InstantiateMsg, ExecuteMsg, QueryMsg, MigrateMsg)] @@ -66,37 +68,16 @@ impl AccountI { details: AccountDetails, governance_details: GovernanceDetails, funds: &[cosmwasm_std::Coin], - ) -> Result { - let salt = Binary::from(b"abstract_account"); - - Self::_create_account( - abstract_deployment, - details, - governance_details, - salt, - funds, - ) - } - - pub fn create_default_account( - abstract_deployment: &Abstract, - governance_details: GovernanceDetails, - ) -> Result { - let details = AccountDetails { - name: "Default Abstract Account".into(), - ..Default::default() - }; - Self::create(abstract_deployment, details, governance_details, &[]) - } - - fn _create_account( - abstract_deployment: &Abstract, - details: AccountDetails, - governance_details: GovernanceDetails, - salt: Binary, - funds: &[Coin], ) -> Result { let chain = abstract_deployment.version_control.environment().clone(); + + // Generate salt from account id(or) + let salt = generate_instantiate_salt(&AccountId::local(details.account_id.unwrap_or( + chain.wasm_querier().item_query( + &abstract_deployment.version_control.address()?, + LOCAL_ACCOUNT_SEQUENCE, + )?, + ))); let code_id = abstract_deployment.account.code_id().unwrap(); let account_addr = chain @@ -109,7 +90,7 @@ impl AccountI { .instantiate2( code_id, &InstantiateMsg { - account_id: None, + account_id: details.account_id.map(AccountId::local), owner: governance_details, namespace: details.namespace, install_modules: details.install_modules, @@ -135,29 +116,16 @@ impl AccountI { account.set_address(&account_addr); Ok(account) } -} -#[cfg(feature = "daemon")] -impl AccountI { - /// Create account, account sequence used as a salt - pub fn create_sequenced( - abstract_deployment: &Abstract, - details: AccountDetails, + pub fn create_default_account( + abstract_deployment: &Abstract, governance_details: GovernanceDetails, - funds: &[cosmwasm_std::Coin], ) -> Result { - let chain = abstract_deployment.version_control.environment(); - - let base = chain.rt_handle.block_on(chain.sender().base_account())?; - let salt = cosmwasm_std::Binary::from(base.sequence.to_be_bytes()); - - Self::_create_account( - abstract_deployment, - details, - governance_details, - salt, - funds, - ) + let details = AccountDetails { + name: "Default Abstract Account".into(), + ..Default::default() + }; + Self::create(abstract_deployment, details, governance_details, &[]) } } @@ -423,6 +391,7 @@ impl AccountI { ModuleInfo::from_id_latest(IBC_CLIENT)?, None, )], + account_id: None, }, host_chain, ) @@ -441,6 +410,7 @@ impl AccountI { name: _, description: _, link: _, + account_id: _, } = account_details; self.execute_on_module( @@ -549,10 +519,18 @@ impl AccountI { link, namespace, install_modules, + account_id, } = account_details; - let result = - self.create_sub_account(install_modules, name, description, link, namespace, funds)?; + let result = self.create_sub_account( + install_modules, + name, + account_id, + description, + link, + namespace, + funds, + )?; Self::from_tx_response(self.environment(), result) } diff --git a/framework/packages/abstract-std/src/account/mod.rs b/framework/packages/abstract-std/src/account/mod.rs index 86af95790..eaaecc4d5 100644 --- a/framework/packages/abstract-std/src/account/mod.rs +++ b/framework/packages/abstract-std/src/account/mod.rs @@ -167,6 +167,11 @@ pub enum ExecuteMsg { namespace: Option, // Provide list of module to install after sub-account creation install_modules: Vec, + /// If `None`, will create a new local account without asserting account-id. + /// + /// When provided sequence in 0..2147483648 range: The tx will error + /// When provided sequence in 2147483648..u32::MAX range: Signals use of unclaimed Account Id in this range. The tx will error if this account-id already claimed. Useful for instantiate2 address prediction. + account_id: Option, }, /// Update info UpdateInfo { From f6975e2cdf23d9c0bac5fbb3c66a6e98aaf581d1 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 12:54:49 +0300 Subject: [PATCH 03/12] Remove AbstractMockQuerierBuilder in favor of Trait --- .../src/abstract_mock_querier.rs | 97 ++++++------------- .../packages/abstract-testing/src/lib.rs | 22 ++--- .../abstract-testing/src/mock_querier.rs | 79 +++++++++++---- 3 files changed, 101 insertions(+), 97 deletions(-) diff --git a/framework/packages/abstract-testing/src/abstract_mock_querier.rs b/framework/packages/abstract-testing/src/abstract_mock_querier.rs index 457ba5fd1..04cd2111e 100644 --- a/framework/packages/abstract-testing/src/abstract_mock_querier.rs +++ b/framework/packages/abstract-testing/src/abstract_mock_querier.rs @@ -6,103 +6,68 @@ use abstract_std::{ }, version_control::{state::ACCOUNT_ADDRESSES, Account}, }; -use cosmwasm_std::{testing::MockApi, Addr}; +use cosmwasm_std::Addr; use cw_asset::AssetInfo; use cw_storage_plus::Item; use crate::prelude::*; -pub struct AbstractMockQuerierBuilder { - builder: MockQuerierBuilder, - abstract_addrs: AbstractMockAddrs, -} +pub trait AbstractMockQuerier { + /// Mock the existence of an Account by setting the Account id for the proxy and manager along with registering the account to version control. + fn account(self, account_base: &Account, account_id: AccountId) -> Self; -// ANCHOR: account -impl AbstractMockQuerierBuilder { - pub fn new(mock_api: MockApi) -> AbstractMockQuerierBuilder { - AbstractMockQuerierBuilder { - builder: MockQuerierBuilder::default(), - abstract_addrs: AbstractMockAddrs::new(mock_api), - } - } + /// Add mock assets into ANS + fn assets(self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self; + + fn contracts(self, contracts: Vec<(&ContractEntry, Addr)>) -> Self; + fn channels(self, channels: Vec<(&ChannelEntry, String)>) -> Self; + + fn addrs(&self) -> AbstractMockAddrs; +} + +impl AbstractMockQuerier for MockQuerierBuilder { /// Mock the existence of an Account by setting the Account id for the proxy and manager along with registering the account to version control. - pub fn account(mut self, account_base: &Account, account_id: AccountId) -> Self { - self.builder = self - .builder - .with_contract_item(account_base.addr(), ACCOUNT_ID, &account_id) + fn account(self, account_base: &Account, account_id: AccountId) -> Self { + let abstract_addrs = self.addrs(); + self.with_contract_item(account_base.addr(), ACCOUNT_ID, &account_id) // Setup the account owner as the test owner .with_contract_item( account_base.addr(), Item::new(OWNERSHIP_STORAGE_KEY), &Some(Ownership { owner: GovernanceDetails::Monarchy { - monarch: self.abstract_addrs.owner.clone(), + monarch: abstract_addrs.owner.clone(), }, pending_owner: None, pending_expiry: None, }), ) .with_contract_map_entry( - &self.abstract_addrs.version_control, + &abstract_addrs.version_control, ACCOUNT_ADDRESSES, (&account_id, account_base.clone()), - ); - - self - } - // ANCHOR_END: account - - /// Add mock assets into ANS - pub fn assets(mut self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self { - self.builder = self.builder.with_contract_map_entries( - &self.abstract_addrs.ans_host, - ASSET_ADDRESSES, - assets, - ); - - self - } - - pub fn contracts(mut self, contracts: Vec<(&ContractEntry, Addr)>) -> Self { - self.builder = self.builder.with_contract_map_entries( - &self.abstract_addrs.ans_host, - CONTRACT_ADDRESSES, - contracts, - ); - - self + ) } - pub fn channels(mut self, channels: Vec<(&ChannelEntry, String)>) -> Self { - self.builder = self.builder.with_contract_map_entries( - &self.abstract_addrs.ans_host, - CHANNELS, - channels, - ); - - self + fn assets(self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self { + let abstract_addrs = self.addrs(); + self.with_contract_map_entries(&abstract_addrs.ans_host, ASSET_ADDRESSES, assets) } - /// Change the version control address. Any account added after this will be registered to this address. - pub fn set_version_control(mut self, version_control: Addr) -> Self { - self.abstract_addrs.version_control = version_control; - self - } + fn contracts(self, contracts: Vec<(&ContractEntry, Addr)>) -> Self { + let abstract_addrs = self.addrs(); - pub fn ans(self, _ans: MockAnsHost) -> Self { - self + self.with_contract_map_entries(&abstract_addrs.ans_host, CONTRACT_ADDRESSES, contracts) } - pub fn builder(self) -> MockQuerierBuilder { - self.builder - } + fn channels(self, channels: Vec<(&ChannelEntry, String)>) -> Self { + let abstract_addrs = self.addrs(); - pub fn addrs(&self) -> &AbstractMockAddrs { - &self.abstract_addrs + self.with_contract_map_entries(&abstract_addrs.ans_host, CHANNELS, channels) } - pub fn build(self) -> MockQuerier { - self.builder.build() + fn addrs(&self) -> AbstractMockAddrs { + AbstractMockAddrs::new(self.api) } } diff --git a/framework/packages/abstract-testing/src/lib.rs b/framework/packages/abstract-testing/src/lib.rs index a741279e3..cb11c05e7 100644 --- a/framework/packages/abstract-testing/src/lib.rs +++ b/framework/packages/abstract-testing/src/lib.rs @@ -9,7 +9,6 @@ use abstract_std::{ account::state::ACCOUNT_ID, account::state::ACCOUNT_MODULES, objects::{ - account::TEST_ACCOUNT_ID, module::{ModuleInfo, ModuleVersion}, module_reference::ModuleReference, ownership, @@ -17,7 +16,6 @@ use abstract_std::{ version_control::state::{ACCOUNT_ADDRESSES, REGISTERED_MODULES}, ACCOUNT, }; -use cosmwasm_std::testing::MOCK_CONTRACT_ADDR; use cosmwasm_std::{ from_json, testing::{MockApi, MockQuerier, MockStorage}, @@ -28,7 +26,7 @@ pub use mock_querier::{ map_key, raw_map_key, wrap_querier, MockQuerierBuilder, MockQuerierOwnership, }; use module::{TEST_MODULE_ID, TEST_MODULE_RESPONSE}; -use prelude::{AbstractMockAddrs, AbstractMockQuerierBuilder}; +use prelude::AbstractMockAddrs; pub type MockDeps = OwnedDeps; pub fn mock_querier_builder(mock_api: MockApi) -> MockQuerierBuilder { @@ -52,7 +50,7 @@ pub fn mock_querier_builder(mock_api: MockApi) -> MockQuerierBuilder { }; let abstr = AbstractMockAddrs::new(mock_api); - MockQuerierBuilder::default() + MockQuerierBuilder::new(mock_api) .with_fallback_raw_handler(raw_handler) .with_contract_map_entry( &abstr.version_control, @@ -85,7 +83,7 @@ pub fn mock_querier_builder(mock_api: MockApi) -> MockQuerierBuilder { let resp = AccountConfigResponse { version_control_address: abstr.version_control, module_factory_address: abstr.module_factory, - account_id: TEST_ACCOUNT_ID, // mock value, not used + account_id: ABSTRACT_ACCOUNT_ID, // mock value, not used is_suspended: false, modules: vec![], }; @@ -142,17 +140,19 @@ pub mod addresses { // Test addr makers const OWNER: &str = "owner"; + const ROOT_ACCOUNT: &str = "root_account_address"; const TEST_ACCOUNT: &str = "account_address"; const TEST_ANS_HOST: &str = "test_ans_host_address"; const TEST_VERSION_CONTROL: &str = "version_control_address"; - const TEST_ACCOUNT_FACTORY: &str = "account_factory_address"; const TEST_MODULE_FACTORY: &str = "module_factory_address"; const TEST_MODULE_ADDRESS: &str = "test_module_address"; - // set in cosmwasm_std::MockApi - const ENV_CONTRACT_ADDRESS: &str = "cosmos2address"; + + pub fn root_account_base(mock_api: MockApi) -> Account { + Account::new(mock_api.addr_make(ROOT_ACCOUNT)) + } pub fn test_account_base(mock_api: MockApi) -> Account { - Account::new(mock_api.addr_make(ENV_CONTRACT_ADDRESS)) + Account::new(mock_api.addr_make(TEST_ACCOUNT)) } impl AbstractMockAddrs { @@ -163,7 +163,7 @@ pub mod addresses { version_control: mock_api.addr_make(TEST_VERSION_CONTROL), module_factory: mock_api.addr_make(TEST_MODULE_FACTORY), module_address: mock_api.addr_make(TEST_MODULE_ADDRESS), - account: test_account_base(mock_api), + account: root_account_base(mock_api), } } } @@ -207,7 +207,7 @@ pub mod module { pub mod prelude { pub use super::{mock_dependencies, mock_querier}; - pub use abstract_mock_querier::AbstractMockQuerierBuilder; + pub use abstract_mock_querier::AbstractMockQuerier; pub use abstract_std::objects::account::TEST_ACCOUNT_ID; pub use addresses::*; pub use ans::*; diff --git a/framework/packages/abstract-testing/src/mock_querier.rs b/framework/packages/abstract-testing/src/mock_querier.rs index 1ae139970..3c034c3c4 100644 --- a/framework/packages/abstract-testing/src/mock_querier.rs +++ b/framework/packages/abstract-testing/src/mock_querier.rs @@ -1,11 +1,7 @@ use std::{collections::HashMap, ops::Deref}; -use abstract_std::{ - account::state::{ACCOUNT_ID, ACCOUNT_MODULES}, - objects::{ - common_namespace::OWNERSHIP_STORAGE_KEY, gov_type::GovernanceDetails, ownership::Ownership, - }, - version_control::state::ACCOUNT_ADDRESSES, +use abstract_std::objects::{ + common_namespace::OWNERSHIP_STORAGE_KEY, gov_type::GovernanceDetails, ownership::Ownership, }; use cosmwasm_std::{ testing::MockApi, Addr, Binary, ContractInfoResponse, ContractResult, Empty, QuerierWrapper, @@ -51,11 +47,19 @@ pub struct MockQuerierBuilder { raw_handlers: HashMap>, raw_mappings: HashMap>, contract_admin: HashMap, + // Used for Address generation + pub api: MockApi, } impl Default for MockQuerierBuilder { /// Create a default fn default() -> Self { + Self::new(MockApi::default()) + } +} + +impl MockQuerierBuilder { + pub fn new(api: MockApi) -> Self { let raw_fallback: fn(&Addr, &Binary) -> BinaryQueryResult = |addr, key| { let str_key = std::str::from_utf8(key.as_slice()).unwrap(); Err(format!( @@ -77,6 +81,7 @@ impl Default for MockQuerierBuilder { raw_handlers: HashMap::default(), raw_mappings: HashMap::default(), contract_admin: HashMap::default(), + api, } } } @@ -409,19 +414,23 @@ pub fn wrap_querier(querier: &MockQuerier) -> QuerierWrapper<'_, Empty> { #[cfg(test)] mod tests { use abstract_std::{ - account::state::ACCOUNT_ID, account::state::ACCOUNT_MODULES, + account::state::{ACCOUNT_ID, ACCOUNT_MODULES}, + objects::ABSTRACT_ACCOUNT_ID, version_control::state::ACCOUNT_ADDRESSES, }; - use cosmwasm_std::testing; - use speculoos::prelude::*; use super::*; mod account { + + use abstract_std::version_control::Account; + + use crate::mock_querier_builder; + use super::*; #[test] - fn should_return_account_address() { + fn should_return_base_account_address() { let mut deps = mock_dependencies(); deps.querier = mock_querier(deps.api); let abstr = AbstractMockAddrs::new(deps.api); @@ -429,12 +438,30 @@ mod tests { let actual = ACCOUNT_ADDRESSES.query( &wrap_querier(&deps.querier), abstr.version_control, - &TEST_ACCOUNT_ID, + &ABSTRACT_ACCOUNT_ID, ); let expected = abstr.account; - assert_that!(actual).is_ok().is_some().is_equal_to(expected) + assert_eq!(actual, Ok(Some(expected))); + } + + #[test] + fn should_return_account_address() { + let mut deps = mock_dependencies(); + let account_base = Account::new(deps.api.addr_make("my_account")); + deps.querier = mock_querier_builder(deps.api) + .account(&account_base, TEST_ACCOUNT_ID) + .build(); + let abstr = AbstractMockAddrs::new(deps.api); + + let actual = ACCOUNT_ADDRESSES.query( + &wrap_querier(&deps.querier), + abstr.version_control, + &TEST_ACCOUNT_ID, + ); + + assert_eq!(actual, Ok(Some(account_base))); } } @@ -467,7 +494,7 @@ mod tests { .unwrap(); let resp: MockModuleQueryResponse = from_json(resp_bin).unwrap(); - assert_that!(resp).is_equal_to(MockModuleQueryResponse {}) + assert_eq!(resp, MockModuleQueryResponse {}); } #[test] @@ -495,22 +522,37 @@ mod tests { .unwrap(); let resp: String = from_json(resp_bin).unwrap(); - assert_that!(resp).is_equal_to("the_value".to_string()) + assert_eq!(resp, "the_value"); } } mod account_id { + use crate::mock_querier_builder; + use super::*; #[test] - fn should_return_test_acct_id_with_test_manager() { + fn should_return_root_acct_id_with_test_manager() { let mut deps = mock_dependencies(); deps.querier = mock_querier(deps.api); + let root_base = root_account_base(deps.api); + + let actual = ACCOUNT_ID.query(&wrap_querier(&deps.querier), root_base.addr().clone()); + + assert_eq!(actual, Ok(ABSTRACT_ACCOUNT_ID)); + } + + #[test] + fn should_return_test_acct_id_with_test_manager() { + let mut deps = mock_dependencies(); let test_base = test_account_base(deps.api); + deps.querier = mock_querier_builder(deps.api) + .account(&test_base, TEST_ACCOUNT_ID) + .build(); let actual = ACCOUNT_ID.query(&wrap_querier(&deps.querier), test_base.addr().clone()); - assert_that!(actual).is_ok().is_equal_to(TEST_ACCOUNT_ID); + assert_eq!(actual, Ok(TEST_ACCOUNT_ID)); } } @@ -529,10 +571,7 @@ mod tests { TEST_MODULE_ID, ); - assert_that!(actual) - .is_ok() - .is_some() - .is_equal_to(abstr.module_address); + assert_eq!(actual, Ok(Some(abstr.module_address))); } // #[test] From 6c674a49355275db2101a653c04fdf69ab266d2f Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 12:58:00 +0300 Subject: [PATCH 04/12] fix doctests --- framework/packages/abstract-testing/src/mock_querier.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/packages/abstract-testing/src/mock_querier.rs b/framework/packages/abstract-testing/src/mock_querier.rs index 3c034c3c4..64274c855 100644 --- a/framework/packages/abstract-testing/src/mock_querier.rs +++ b/framework/packages/abstract-testing/src/mock_querier.rs @@ -129,7 +129,7 @@ impl MockQuerierBuilder { /// use abstract_sdk::mock_module::{MockModuleQueryMsg, MockModuleQueryResponse}; /// /// let api = MockApi::default(); - /// let contract_address = deps.api.addr_make("contract_address"); + /// let contract_address = api.addr_make("contract_address"); /// let querier = MockQuerierBuilder::default().with_smart_handler(&contract_address, |msg| { /// // handle the message /// let res = match from_json::(msg).unwrap() { @@ -302,7 +302,7 @@ impl MockQuerierBuilder { /// let contract_address = api.addr_make("contract1"); /// /// MockQuerierBuilder::default() - /// .with_contract_version(&contract_address, "v1.0.0"); + /// .with_contract_version(&contract_address, "contract1", "v1.0.0"); /// ``` pub fn with_contract_version( self, From b353302b9386304292a95b6d9f57f80ebc424ac2 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 13:32:49 +0300 Subject: [PATCH 05/12] fix interface tests --- framework/packages/abstract-interface/Cargo.toml | 8 ++++++++ framework/packages/abstract-interface/src/deployment.rs | 1 + 2 files changed, 9 insertions(+) diff --git a/framework/packages/abstract-interface/Cargo.toml b/framework/packages/abstract-interface/Cargo.toml index 3c3a8b160..f9a763937 100644 --- a/framework/packages/abstract-interface/Cargo.toml +++ b/framework/packages/abstract-interface/Cargo.toml @@ -6,6 +6,14 @@ license = { workspace = true } description = "Abstract deployment helpers with cw-orchestrator" repository = "https://github.com/AbstractSDK/abstract" +[[example]] +name = "mock-ibc-deploy" +required-features = ["interchain"] + +[[example]] +name = "starship-ibc-deploy" +required-features = ["interchain"] + [features] default = ["integration"] daemon = ["cw-orch/daemon"] diff --git a/framework/packages/abstract-interface/src/deployment.rs b/framework/packages/abstract-interface/src/deployment.rs index 9af074601..11d4593e4 100644 --- a/framework/packages/abstract-interface/src/deployment.rs +++ b/framework/packages/abstract-interface/src/deployment.rs @@ -264,6 +264,7 @@ mod test { fn have_some_state() { State::get("state.json").unwrap(); let state = State::load_state(); + // TODO: remove ["juno"] after updating state, we only need chain_id now let vc_juno = &state["juno"]["juno-1"]["code_ids"].get(VERSION_CONTROL); assert!(vc_juno.is_some()); } From cc0ffb6ec802d735d512a72ae4fe0035263d7b3d Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 14:36:13 +0300 Subject: [PATCH 06/12] remove get_last_account from abstract client --- .../packages/abstract-client/src/client.rs | 95 ------------------- .../abstract-interface/src/account.rs | 2 +- .../abstract-interface/src/deployment.rs | 44 +++------ 3 files changed, 16 insertions(+), 125 deletions(-) diff --git a/framework/packages/abstract-client/src/client.rs b/framework/packages/abstract-client/src/client.rs index c73ce84bc..a096ceb20 100644 --- a/framework/packages/abstract-client/src/client.rs +++ b/framework/packages/abstract-client/src/client.rs @@ -267,35 +267,6 @@ impl AbstractClient { .map_err(Into::into) } - // Retrieve the last account created by the client. - /// Returns `None` if no account has been created yet. - /// **Note**: This only returns accounts that were created with the Client. Any accounts created through the web-app will not be returned. - pub fn get_last_account(&self) -> AbstractClientResult>> { - let addresses = self.environment().state().get_all_addresses()?; - // Now search for all the keys that start with "abstract:manager-x" and return the one which has the highest x. - let mut last_account: Option<(u32, Account)> = None; - for id in addresses.keys() { - let Some(account_id) = is_local_manager(id.as_str())? else { - continue; - }; - - // only take accounts that the current sender owns - let account = AccountI::load_from(&self.abstr, account_id.clone()); - if account.top_level_owner()?.address != self.environment().sender_addr() { - continue; - } - - if let Some((last_account_id, _)) = last_account { - if account_id.seq() > last_account_id { - last_account = Some((account_id.seq(), Account::new(account, true))); - } - } else { - last_account = Some((account_id.seq(), Account::new(account, true))); - } - } - Ok(last_account.map(|(_, account)| account)) - } - /// Get random local account id sequence(unclaimed) in 2147483648..u32::MAX range pub fn random_account_id(&self) -> AbstractClientResult { let mut rng = rand::thread_rng(); @@ -388,69 +359,3 @@ impl AbstractClient { Ok(()) } } - -pub(crate) fn is_local_manager(id: &str) -> AbstractClientResult> { - if !id.starts_with(abstract_std::ACCOUNT) { - return Ok(None); - } - - let (_, account_id_str) = id.split_once('-').unwrap(); - let account_id = AccountId::try_from(account_id_str)?; - - // Only take local accounts into account. - if account_id.is_remote() { - return Ok(None); - } - - Ok(Some(account_id)) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn local_account() { - let result = is_local_manager("abstract:manager-local-9"); - assert!(result.unwrap().is_some()); - } - - #[test] - fn remote_account() { - let result = is_local_manager("abstract:manager-eth>btc-9"); - assert!(result.unwrap().is_none()); - } - - #[test] - fn not_manager() { - let result = is_local_manager("abstract:proxy-local-9"); - assert!(result.unwrap().is_none()); - } - - #[test] - fn last_owned_abstract_account() { - let chain = MockBech32::new("mock"); - let sender = chain.sender_addr(); - Abstract::deploy_on(chain.clone(), sender.to_string()).unwrap(); - - let client = AbstractClient::new(chain.clone()).unwrap(); - let _acc = client.account_builder().build().unwrap(); - let acc_2 = client.account_builder().build().unwrap(); - - let other_owner = chain.addr_make("other_owner"); - // create account with sender as sender but other owner - client - .account_builder() - .ownership( - abstract_std::objects::gov_type::GovernanceDetails::Monarchy { - monarch: other_owner.to_string(), - }, - ) - .build() - .unwrap(); - - let last_account = client.get_last_account().unwrap().unwrap(); - - assert_eq!(acc_2.id().unwrap(), last_account.id().unwrap()); - } -} diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index 7e6b8accf..389abc65f 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -110,7 +110,7 @@ impl AccountI { let account_id = chain .wasm_querier() .item_query(&account_addr, state::ACCOUNT_ID)?; - let contract_id = format!("{ACCOUNT}_{account_id}"); + let contract_id = format!("{ACCOUNT}-{account_id}"); let account = Self::new(contract_id, chain); account.set_address(&account_addr); diff --git a/framework/packages/abstract-interface/src/deployment.rs b/framework/packages/abstract-interface/src/deployment.rs index 11d4593e4..1ccab76bc 100644 --- a/framework/packages/abstract-interface/src/deployment.rs +++ b/framework/packages/abstract-interface/src/deployment.rs @@ -8,7 +8,9 @@ use crate::{ get_ibc_contracts, get_native_contracts, AbstractIbc, AbstractInterfaceError, AccountI, AnsHost, ModuleFactory, VersionControl, }; -use abstract_std::{ACCOUNT, ANS_HOST, MODULE_FACTORY, VERSION_CONTROL}; +use abstract_std::{ + objects::ABSTRACT_ACCOUNT_ID, ACCOUNT, ANS_HOST, MODULE_FACTORY, VERSION_CONTROL, +}; use rust_embed::RustEmbed; @@ -85,38 +87,22 @@ impl Deploy for Abstract { // Approve abstract contracts if needed deployment.version_control.approve_any_abstract_modules()?; - let salt = Binary::from("abstract".as_bytes()); - let abstr_acc_addr = chain - .wasm_querier() - .instantiate2_addr( - deployment.account.code_id()?, - &chain.sender_addr(), - salt.clone(), - ) - .map_err(Into::::into)?; - // Create the first abstract account in integration environments #[cfg(feature = "integration")] - use abstract_std::objects::gov_type::GovernanceDetails; - #[cfg(feature = "integration")] - deployment.account.instantiate2( - &abstract_std::account::InstantiateMsg { - account_id: None, - owner: GovernanceDetails::Monarchy { + { + use abstract_std::objects::gov_type::GovernanceDetails; + AccountI::create( + &deployment, + crate::AccountDetails { + name: "Abstract".to_string(), + ..Default::default() + }, + GovernanceDetails::Monarchy { monarch: chain.sender_addr().to_string(), }, - namespace: None, - install_modules: vec![], - name: "Abstract".to_string(), - description: None, - link: None, - module_factory_address: deployment.module_factory.address()?.into_string(), - version_control_address: deployment.version_control.address()?.into_string(), - }, - Some(&Addr::unchecked(abstr_acc_addr)), - &[], - salt, - )?; + &[], + )?; + } Ok(deployment) } From 6b0a0149884b909328d6f72de3d9928eddbfdf64 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 14:36:31 +0300 Subject: [PATCH 07/12] add local_account_sequence in vc config response --- framework/contracts/native/version-control/src/contract.rs | 2 ++ framework/packages/abstract-std/src/native/version_control.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/framework/contracts/native/version-control/src/contract.rs b/framework/contracts/native/version-control/src/contract.rs index af4cb8628..646abb3cd 100644 --- a/framework/contracts/native/version-control/src/contract.rs +++ b/framework/contracts/native/version-control/src/contract.rs @@ -106,10 +106,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> VCResult { } QueryMsg::Config {} => { let config = CONFIG.load(deps.storage)?; + let local_account_sequence = LOCAL_ACCOUNT_SEQUENCE.load(deps.storage)?; to_json_binary(&ConfigResponse { account_factory_address: config.account_factory_address, security_disabled: config.security_disabled, namespace_registration_fee: config.namespace_registration_fee, + local_account_sequence, }) } QueryMsg::ModuleList { diff --git a/framework/packages/abstract-std/src/native/version_control.rs b/framework/packages/abstract-std/src/native/version_control.rs index 685f34e8b..45a2b221e 100644 --- a/framework/packages/abstract-std/src/native/version_control.rs +++ b/framework/packages/abstract-std/src/native/version_control.rs @@ -362,6 +362,7 @@ pub struct ConfigResponse { pub account_factory_address: Option, pub security_disabled: bool, pub namespace_registration_fee: Option, + pub local_account_sequence: u32, } #[cosmwasm_schema::cw_serde] From 589f648fd834f0eacbc0a42502d83a6a35f8a867 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 15:22:36 +0300 Subject: [PATCH 08/12] account and sub-account creation updated --- framework/Cargo.lock | 1 + framework/contracts/account/src/contract.rs | 44 ++-- .../contracts/account/src/sub_account.rs | 6 +- .../native/version-control/src/commands.rs | 2 +- .../native/version-control/src/error.rs | 3 - framework/packages/abstract-client/Cargo.toml | 1 + .../abstract-client/tests/integration.rs | 246 +++++++++--------- .../abstract-interface/src/account.rs | 8 +- .../src/objects/account/account_id.rs | 8 +- 9 files changed, 159 insertions(+), 160 deletions(-) diff --git a/framework/Cargo.lock b/framework/Cargo.lock index 89a3ce4da..b1470c8da 100644 --- a/framework/Cargo.lock +++ b/framework/Cargo.lock @@ -134,6 +134,7 @@ dependencies = [ "abstract-polytone", "abstract-std", "abstract-testing", + "abstract-version-control", "anyhow", "cosmwasm-schema 2.1.3", "cosmwasm-std 2.1.3", diff --git a/framework/contracts/account/src/contract.rs b/framework/contracts/account/src/contract.rs index 030f42635..a5b33c329 100644 --- a/framework/contracts/account/src/contract.rs +++ b/framework/contracts/account/src/contract.rs @@ -63,7 +63,7 @@ pub const REGISTER_MODULES_DEPENDENCIES_REPLY_ID: u64 = 2; #[cfg_attr(feature = "export", cosmwasm_std::entry_point)] pub fn instantiate( mut deps: DepsMut, - env: Env, + _env: Env, info: MessageInfo, InstantiateMsg { account_id, @@ -161,6 +161,27 @@ pub fn instantiate( ], ); + response = response.add_message(wasm_execute( + version_control_address, + &abstract_std::version_control::ExecuteMsg::AddAccount { + namespace, + creator: info.sender.to_string(), + }, + vec![], + )?); + + // Register on account if it's sub-account + // TODO: Update sub-account creation logic + if let GovernanceDetails::SubAccount { account } = cw_gov_owner.owner { + response = response.add_message(wasm_execute( + account, + &ExecuteMsg::UpdateSubAccount(UpdateSubAccountAction::RegisterSubAccount { + id: ACCOUNT_ID.load(deps.storage)?.seq(), + }), + vec![], + )?); + } + if !install_modules.is_empty() { // Install modules let (install_msgs, install_attribute) = _install_modules( @@ -175,27 +196,6 @@ pub fn instantiate( .add_attribute(install_attribute.key, install_attribute.value); } - // Register on manager if it's sub-account - // TODO: Update sub-account creation logic - // if let GovernanceDetails::SubAccount { account } = cw_gov_owner.owner { - // response = response.add_message(wasm_execute( - // account, - // &ExecuteMsg::UpdateSubAccount(UpdateSubAccountAction::RegisterSubAccount { - // id: ACCOUNT_ID.load(deps.storage)?.seq(), - // }), - // vec![], - // )?); - // } - - let response = response.add_message(wasm_execute( - version_control_address, - &abstract_std::version_control::ExecuteMsg::AddAccount { - namespace, - creator: info.sender.to_string(), - }, - vec![], - )?); - Ok(response) } diff --git a/framework/contracts/account/src/sub_account.rs b/framework/contracts/account/src/sub_account.rs index e4ce6e861..b54180bc5 100644 --- a/framework/contracts/account/src/sub_account.rs +++ b/framework/contracts/account/src/sub_account.rs @@ -6,7 +6,7 @@ use abstract_std::{ objects::{ gov_type::GovernanceDetails, ownership::{self, GovOwnershipError}, - AccountId, + salt, AccountId, }, }; use cosmwasm_std::{ @@ -39,7 +39,7 @@ pub fn create_sub_account( .query(&deps.querier, config.version_control_address.clone())?, ); let account_id = AccountId::local(seq); - let salt = cosmwasm_std::to_json_binary(&seq)?; + let salt = salt::generate_instantiate_salt(&account_id); let self_code_id = deps .querier @@ -49,7 +49,7 @@ pub fn create_sub_account( let self_canon_addr = deps.api.addr_canonicalize(env.contract.address.as_str())?; let create_account_msg = abstract_std::account::InstantiateMsg { - account_id: None, + account_id: Some(account_id.clone()), owner: GovernanceDetails::SubAccount { account: env.contract.address.into_string(), }, diff --git a/framework/contracts/native/version-control/src/commands.rs b/framework/contracts/native/version-control/src/commands.rs index 2d728ed72..0c2b8e78e 100644 --- a/framework/contracts/native/version-control/src/commands.rs +++ b/framework/contracts/native/version-control/src/commands.rs @@ -139,7 +139,7 @@ pub fn add_account( "add_account", vec![ ("account_id", account_id.to_string().as_str()), - ("account", account.addr().as_str()), + ("account_address", account.addr().as_str()), ("namespace", &format!("{namespace:?}")), ], ); diff --git a/framework/contracts/native/version-control/src/error.rs b/framework/contracts/native/version-control/src/error.rs index 4bd744be6..5768598fe 100644 --- a/framework/contracts/native/version-control/src/error.rs +++ b/framework/contracts/native/version-control/src/error.rs @@ -93,9 +93,6 @@ pub enum VCError { #[error("Initialization funds can only be specified for apps and standalone modules")] RedundantInitFunds {}, - #[error("Predictable local account id sequence can't be lower than 2147483648")] - PredictableAccountIdFailed {}, - #[error("Sender {0} is not the IBC host {1}")] SenderNotIbcHost(String, String), diff --git a/framework/packages/abstract-client/Cargo.toml b/framework/packages/abstract-client/Cargo.toml index bd697595b..6b97c5112 100644 --- a/framework/packages/abstract-client/Cargo.toml +++ b/framework/packages/abstract-client/Cargo.toml @@ -52,6 +52,7 @@ workspace-hack = { version = "0.1", path = "../../workspace-hack" } abstract-testing.workspace = true abstract-client = { path = ".", features = ["test-utils", "interchain"] } abstract-account = { workspace = true } +version-control = { workspace = true } polytone = { workspace = true } cw-asset.workspace = true cw-controllers.workspace = true diff --git a/framework/packages/abstract-client/tests/integration.rs b/framework/packages/abstract-client/tests/integration.rs index ab188212f..10fe3742a 100644 --- a/framework/packages/abstract-client/tests/integration.rs +++ b/framework/packages/abstract-client/tests/integration.rs @@ -1,3 +1,4 @@ +use ::version_control::error::VCError; use abstract_account::error::AccountError; use abstract_adapter::mock::{ interface::MockAdapterI, MockExecMsg as AdapterMockExecMsg, MockInitMsg as AdapterMockInitMsg, @@ -1194,127 +1195,130 @@ fn authorize_app_on_adapters() -> anyhow::Result<()> { Ok(()) } -// #[test] -// fn create_account_with_expected_account_id() -> anyhow::Result<()> { -// let chain = MockBech32::new("mock"); -// let client = AbstractClient::builder(chain).build()?; - -// // Check it fails on wrong account_id -// let next_id = client.random_account_id()?; -// let err = client -// .account_builder() -// .expected_account_id(10) -// .build() -// .unwrap_err(); -// let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err -// else { -// panic!("Expected cw-orch error") -// }; -// let err: AccountError = err.downcast().unwrap(); -// assert_eq!(err, AccountError::PredictableAccountIdFailed {}); - -// // Can create if right id -// let account = client -// .account_builder() -// .expected_account_id(next_id) -// .build()?; - -// // Check it fails on wrong account_id for sub-accounts -// let next_id = client.random_account_id()?; -// let err = client -// .account_builder() -// .sub_account(&account) -// .expected_account_id(0) -// .build() -// .unwrap_err(); -// let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err -// else { -// panic!("Expected cw-orch error") -// }; -// let err: account_factory::error::AccountFactoryError = err.downcast().unwrap(); -// assert_eq!( -// err, -// account_factory::error::AccountFactoryError::PredictableAccountIdFailed {} -// ); - -// // Can create sub-account if right id -// let sub_account = client -// .account_builder() -// .sub_account(&account) -// .expected_account_id(next_id) -// .build()?; -// let sub_accounts = account.sub_accounts()?; -// assert_eq!(sub_accounts[0].id()?, sub_account.id()?); -// Ok(()) -// } - -// #[test] -// fn instantiate2_addr() -> anyhow::Result<()> { -// let chain = MockBech32::new("mock"); -// let client = AbstractClient::builder(chain).build()?; - -// let publisher: Publisher = client -// .publisher_builder(Namespace::new(TEST_NAMESPACE)?) -// .build()?; - -// publisher.publish_app::>()?; - -// let account_id = AccountId::local(client.random_account_id()?); -// let expected_addr = client.module_instantiate2_address::>(&account_id)?; - -// let sub_account = client -// .account_builder() -// .sub_account(publisher.account()) -// .expected_account_id(account_id.seq()) -// .install_app::>(&MockInitMsg {})? -// .build()?; -// let application = sub_account.application::>()?; - -// assert_eq!(application.address()?, expected_addr); -// Ok(()) -// } - -// #[test] -// fn instantiate2_raw_addr() -> anyhow::Result<()> { -// let chain = MockBech32::new("mock"); -// let client = AbstractClient::builder(chain).build()?; - -// let next_seq = client.random_account_id()?; -// let account_id = AccountId::local(next_seq); - -// let proxy_addr = client.module_instantiate2_address_raw( -// &account_id, -// ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, -// )?; -// let account = client -// .account_builder() -// .expected_account_id(next_seq) -// .build()?; - -// assert_eq!(account.address()?, proxy_addr); -// Ok(()) -// } - -// #[test] -// fn instantiate2_random_seq() -> anyhow::Result<()> { -// let chain = MockBech32::new("mock"); -// let client = AbstractClient::builder(chain).build()?; - -// let next_seq = client.random_account_id()?; -// let account_id = AccountId::local(next_seq); - -// let proxy_addr = client.module_instantiate2_address_raw( -// &account_id, -// ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, -// )?; -// let account = client -// .account_builder() -// .expected_account_id(next_seq) -// .build()?; - -// assert_eq!(account.address()?, proxy_addr); -// Ok(()) -// } +#[test] +fn create_account_with_expected_account_id() -> anyhow::Result<()> { + let chain = MockBech32::new("mock"); + let client = AbstractClient::builder(chain).build()?; + + // Check it fails on wrong account_id + let next_id = client.random_account_id()?; + let err = client + .account_builder() + .expected_account_id(10) + .build() + .unwrap_err(); + let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err + else { + panic!("Expected cw-orch error") + }; + let err: VCError = err.downcast().unwrap(); + assert_eq!( + err, + VCError::InvalidAccountSequence { + expected: 1, + actual: 10, + } + ); + + // Can create if right id + let account = client + .account_builder() + .expected_account_id(next_id) + .build()?; + + // Check it fails on wrong account_id for sub-accounts + let next_id = client.random_account_id()?; + let err = client + .account_builder() + .sub_account(&account) + .expected_account_id(0) + .build() + .unwrap_err(); + let AbstractClientError::Interface(abstract_interface::AbstractInterfaceError::Orch(err)) = err + else { + panic!("Expected cw-orch error") + }; + let err: VCError = err.downcast().unwrap(); + assert_eq!(err, VCError::AccountAlreadyExists(AccountId::local(0))); + + // Can create sub-account if right id + let sub_account = client + .account_builder() + .sub_account(&account) + .expected_account_id(next_id) + .build()?; + let sub_accounts = account.sub_accounts()?; + assert_eq!(sub_accounts[0].id()?, sub_account.id()?); + Ok(()) +} + +#[test] +fn instantiate2_addr() -> anyhow::Result<()> { + let chain = MockBech32::new("mock"); + let client = AbstractClient::builder(chain).build()?; + + let publisher: Publisher = client + .publisher_builder(Namespace::new(TEST_NAMESPACE)?) + .build()?; + + publisher.publish_app::>()?; + + let account_id = AccountId::local(client.random_account_id()?); + let expected_addr = client.module_instantiate2_address::>(&account_id)?; + + let sub_account = client + .account_builder() + .sub_account(publisher.account()) + .expected_account_id(account_id.seq()) + .install_app::>(&MockInitMsg {})? + .build()?; + let application = sub_account.application::>()?; + + assert_eq!(application.address()?, expected_addr); + Ok(()) +} + +#[test] +fn instantiate2_raw_addr() -> anyhow::Result<()> { + let chain = MockBech32::new("mock"); + let client = AbstractClient::builder(chain).build()?; + + let next_seq = client.random_account_id()?; + let account_id = AccountId::local(next_seq); + + let proxy_addr = client.module_instantiate2_address_raw( + &account_id, + ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, + )?; + let account = client + .account_builder() + .expected_account_id(next_seq) + .build()?; + + assert_eq!(account.address()?, proxy_addr); + Ok(()) +} + +#[test] +fn instantiate2_random_seq() -> anyhow::Result<()> { + let chain = MockBech32::new("mock"); + let client = AbstractClient::builder(chain).build()?; + + let next_seq = client.random_account_id()?; + let account_id = AccountId::local(next_seq); + + let proxy_addr = client.module_instantiate2_address_raw( + &account_id, + ModuleInfo::from_id_latest(abstract_std::ACCOUNT)?, + )?; + let account = client + .account_builder() + .expected_account_id(next_seq) + .build()?; + + assert_eq!(account.address()?, proxy_addr); + Ok(()) +} #[test] fn install_same_app_on_different_accounts() -> anyhow::Result<()> { diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index 389abc65f..b23624e21 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -542,12 +542,8 @@ impl AccountI { result: ::Response, ) -> Result, crate::AbstractInterfaceError> { // Parse data from events - let acc_seq = &result.event_attr_value(ABSTRACT_EVENT_TYPE, "account_sequence")?; - let trace = &result.event_attr_value(ABSTRACT_EVENT_TYPE, "trace")?; - let id = AccountId::new( - acc_seq.parse().unwrap(), - abstract_std::objects::account::AccountTrace::try_from((*trace).as_str())?, - )?; + let acc_id = &result.event_attr_value(ABSTRACT_EVENT_TYPE, "account_id")?; + let id: AccountId = acc_id.parse()?; // construct manager and proxy ids let account = Self::new_from_id(&id, chain.clone()); diff --git a/framework/packages/abstract-std/src/objects/account/account_id.rs b/framework/packages/abstract-std/src/objects/account/account_id.rs index 396ff163e..ee6954157 100644 --- a/framework/packages/abstract-std/src/objects/account/account_id.rs +++ b/framework/packages/abstract-std/src/objects/account/account_id.rs @@ -1,4 +1,4 @@ -use std::fmt::Display; +use std::{fmt::Display, str::FromStr}; use cosmwasm_std::{StdError, StdResult}; use cw_storage_plus::{Key, KeyDeserialize, Prefixer, PrimaryKey}; @@ -110,10 +110,10 @@ impl AccountId { } } -impl TryFrom<&str> for AccountId { - type Error = AbstractError; +impl FromStr for AccountId { + type Err = AbstractError; - fn try_from(value: &str) -> Result { + fn from_str(value: &str) -> Result { let (trace_str, seq_str) = value .split_once('-') .ok_or(AbstractError::FormattingError { From 5f617f7288294413b853acb110abd408a0076c68 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 15:58:52 +0300 Subject: [PATCH 09/12] execute_on fixed --- framework/contracts/account/src/actions.rs | 56 +++++++++---------- framework/contracts/account/src/contract.rs | 1 - .../packages/abstract-client/src/account.rs | 6 +- .../src/interchain/remote_account.rs | 2 +- .../abstract-client/tests/integration.rs | 2 +- .../abstract-interface/src/account.rs | 14 ++--- .../packages/abstract-std/src/account/mod.rs | 1 - 7 files changed, 37 insertions(+), 45 deletions(-) diff --git a/framework/contracts/account/src/actions.rs b/framework/contracts/account/src/actions.rs index 83074a990..f6beb1731 100644 --- a/framework/contracts/account/src/actions.rs +++ b/framework/contracts/account/src/actions.rs @@ -1,11 +1,10 @@ use abstract_sdk::std::{ - account::state::{ADMIN, WHITELISTED_MODULES}, - ibc_client::ExecuteMsg as IbcClientMsg, - IBC_CLIENT, + account::state::WHITELISTED_MODULES, ibc_client::ExecuteMsg as IbcClientMsg, IBC_CLIENT, }; -use abstract_std::ICA_CLIENT; +use abstract_std::{account::state::ACCOUNT_MODULES, objects::ownership, ICA_CLIENT}; use cosmwasm_std::{ - wasm_execute, Binary, CosmosMsg, DepsMut, Empty, MessageInfo, StdError, SubMsg, WasmQuery, + wasm_execute, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, MessageInfo, StdError, SubMsg, + WasmQuery, }; use crate::{ @@ -13,6 +12,18 @@ use crate::{ error::AccountError, }; +/// Check that sender either whitelisted or governance +pub(crate) fn assert_whitelisted(deps: Deps, sender: &Addr) -> AccountResult<()> { + let whitelisted_modules = WHITELISTED_MODULES.load(deps.storage)?; + if whitelisted_modules.0.contains(sender) + || ownership::is_owner(deps.storage, &deps.querier, sender)? + { + Ok(()) + } else { + Err(AccountError::SenderNotWhitelisted {}) + } +} + /// Executes `Vec` on the proxy. /// Permission: Module pub fn execute_module_action( @@ -20,10 +31,7 @@ pub fn execute_module_action( msg_info: MessageInfo, msgs: Vec>, ) -> AccountResult { - let whitelisted_modules = WHITELISTED_MODULES.load(deps.storage)?; - if !whitelisted_modules.0.contains(&msg_info.sender) { - return Err(AccountError::SenderNotWhitelisted {}); - } + assert_whitelisted(deps.as_ref(), &msg_info.sender)?; Ok(AccountResponse::action("execute_module_action").add_messages(msgs)) } @@ -35,10 +43,7 @@ pub fn execute_module_action_response( msg_info: MessageInfo, msg: CosmosMsg, ) -> AccountResult { - let whitelisted_modules = WHITELISTED_MODULES.load(deps.storage)?; - if !whitelisted_modules.0.contains(&msg_info.sender) { - return Err(AccountError::SenderNotWhitelisted {}); - } + assert_whitelisted(deps.as_ref(), &msg_info.sender)?; let submsg = SubMsg::reply_on_success(msg, RESPONSE_REPLY_ID); @@ -52,16 +57,13 @@ pub fn execute_ibc_action( msg_info: MessageInfo, msg: IbcClientMsg, ) -> AccountResult { - let whitelisted_modules = WHITELISTED_MODULES.load(deps.storage)?; - if !whitelisted_modules.0.contains(&msg_info.sender) { - return Err(AccountError::SenderNotWhitelisted {}); - } - let manager_address = ADMIN.get(deps.as_ref())?.unwrap(); - let ibc_client_address = abstract_sdk::std::account::state::ACCOUNT_MODULES - .query(&deps.querier, manager_address, IBC_CLIENT)? + assert_whitelisted(deps.as_ref(), &msg_info.sender)?; + + let ibc_client_address = ACCOUNT_MODULES + .may_load(deps.storage, IBC_CLIENT)? .ok_or_else(|| { StdError::generic_err(format!( - "ibc_client not found on manager. Add it under the {IBC_CLIENT} name." + "ibc_client not found on account. Add it under the {IBC_CLIENT} name." )) })?; @@ -83,17 +85,13 @@ pub fn execute_ibc_action( /// /// The resulting `Vec` are then executed on the proxy contract. pub fn ica_action(deps: DepsMut, msg_info: MessageInfo, action_query: Binary) -> AccountResult { - let whitelisted_modules = WHITELISTED_MODULES.load(deps.storage)?; - if !whitelisted_modules.0.contains(&msg_info.sender) { - return Err(AccountError::SenderNotWhitelisted {}); - } + assert_whitelisted(deps.as_ref(), &msg_info.sender)?; - let manager_address = ADMIN.get(deps.as_ref())?.unwrap(); - let ica_client_address = abstract_sdk::std::account::state::ACCOUNT_MODULES - .query(&deps.querier, manager_address, ICA_CLIENT)? + let ica_client_address = ACCOUNT_MODULES + .may_load(deps.storage, ICA_CLIENT)? .ok_or_else(|| { StdError::generic_err(format!( - "ica_client not found on manager. Add it under the {ICA_CLIENT} name." + "ica_client not found on account. Add it under the {ICA_CLIENT} name." )) })?; diff --git a/framework/contracts/account/src/contract.rs b/framework/contracts/account/src/contract.rs index a5b33c329..ea56efb9b 100644 --- a/framework/contracts/account/src/contract.rs +++ b/framework/contracts/account/src/contract.rs @@ -171,7 +171,6 @@ pub fn instantiate( )?); // Register on account if it's sub-account - // TODO: Update sub-account creation logic if let GovernanceDetails::SubAccount { account } = cw_gov_owner.owner { response = response.add_message(wasm_execute( account, diff --git a/framework/packages/abstract-client/src/account.rs b/framework/packages/abstract-client/src/account.rs index b9e86d412..20eb660c3 100644 --- a/framework/packages/abstract-client/src/account.rs +++ b/framework/packages/abstract-client/src/account.rs @@ -631,11 +631,7 @@ impl Account { ) -> AbstractClientResult { let msgs = execute_msgs.into_iter().map(Into::into).collect(); self.configure( - &account::ExecuteMsg::ExecOnModule { - module_id: ACCOUNT.to_owned(), - exec_msg: to_json_binary(&abstract_std::account::ExecuteMsg::ModuleAction { msgs }) - .map_err(AbstractInterfaceError::from)?, - }, + &abstract_std::account::ExecuteMsg::ModuleAction { msgs }, funds, ) } diff --git a/framework/packages/abstract-client/src/interchain/remote_account.rs b/framework/packages/abstract-client/src/interchain/remote_account.rs index 1cea00164..ab1f2a015 100644 --- a/framework/packages/abstract-client/src/interchain/remote_account.rs +++ b/framework/packages/abstract-client/src/interchain/remote_account.rs @@ -532,7 +532,7 @@ impl<'a, Chain: IbcQueryHandler, IBC: InterchainEnv> RemoteAccount<'a, Ch ) -> AbstractClientResult> { let msg = account::ExecuteMsg::IbcAction { msg: exec_msg }; - let tx_response = self.abstr_owner_account.execute_on_module(ACCOUNT, msg)?; + let tx_response = self.abstr_owner_account.execute(&msg, &[])?; let packets = self .ibc_env .await_packets(&self.origin_chain().chain_id(), tx_response) diff --git a/framework/packages/abstract-client/tests/integration.rs b/framework/packages/abstract-client/tests/integration.rs index 10fe3742a..e92ffcb25 100644 --- a/framework/packages/abstract-client/tests/integration.rs +++ b/framework/packages/abstract-client/tests/integration.rs @@ -719,7 +719,7 @@ fn cannot_get_nonexisting_module_dependency() -> anyhow::Result<()> { /// ANCHOR: mock_integration_test #[test] -fn can_execute_on_proxy() -> anyhow::Result<()> { +fn can_execute_on_account() -> anyhow::Result<()> { let denom = "denom"; let chain = MockBech32::new("mock"); let client = AbstractClient::builder(chain.clone()).build()?; diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index b23624e21..bb1d16198 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -413,16 +413,17 @@ impl AccountI { account_id: _, } = account_details; - self.execute_on_module( - abstract_std::ACCOUNT, - abstract_std::account::ExecuteMsg::IbcAction { + self.execute( + &abstract_std::account::ExecuteMsg::IbcAction { msg: abstract_std::ibc_client::ExecuteMsg::Register { host_chain, namespace, install_modules, }, }, + &[], ) + .map_err(Into::into) } pub fn set_ibc_status( @@ -453,7 +454,7 @@ impl AccountI { }, }; - self.execute_on_module(ACCOUNT, msg) + self.execute(&msg, &[]).map_err(Into::into) } pub fn execute_on_remote_module( @@ -475,7 +476,7 @@ impl AccountI { }, }; - self.execute_on_module(ACCOUNT, msg) + self.execute(&msg, &[]).map_err(Into::into) } pub fn send_all_funds_back( @@ -490,7 +491,7 @@ impl AccountI { }, }; - self.execute_on_module(ACCOUNT, msg) + self.execute(&msg, &[]).map_err(Into::into) } } @@ -598,7 +599,6 @@ impl AccountI { } sub_account_ids.extend(sub_account_ids_page); } - dbg!(&sub_account_ids); for sub_account_id in sub_account_ids { let abstract_account = AccountI::load_from(abstract_deployment, AccountId::local(sub_account_id)); diff --git a/framework/packages/abstract-std/src/account/mod.rs b/framework/packages/abstract-std/src/account/mod.rs index eaaecc4d5..d3e1cc87c 100644 --- a/framework/packages/abstract-std/src/account/mod.rs +++ b/framework/packages/abstract-std/src/account/mod.rs @@ -71,7 +71,6 @@ pub mod state { pub const WHITELISTED_MODULES: Item = Item::new(namespace::WHITELISTED_MODULES); - pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE); /// Suspension status // TODO: Pull it inside Config as `suspended: Option`, with reason of suspension inside a string? From fd9e4a9f5458c45b8328df5e4e9217adacaf08ff Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 16:05:07 +0300 Subject: [PATCH 10/12] manager to account rename in interface --- framework/packages/abstract-client/src/account.rs | 6 +++--- framework/packages/abstract-client/src/application.rs | 2 +- framework/packages/abstract-client/src/client.rs | 3 +-- .../abstract-client/src/interchain/remote_account.rs | 6 +++--- framework/packages/abstract-client/tests/integration.rs | 3 +-- framework/packages/abstract-interface/src/account.rs | 2 +- framework/packages/abstract-interface/src/deployment.rs | 5 +---- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/framework/packages/abstract-client/src/account.rs b/framework/packages/abstract-client/src/account.rs index 20eb660c3..20fd424bc 100644 --- a/framework/packages/abstract-client/src/account.rs +++ b/framework/packages/abstract-client/src/account.rs @@ -22,8 +22,8 @@ use std::fmt::{Debug, Display}; use abstract_interface::{ - Abstract, AbstractInterfaceError, AccountDetails, AccountI, DependencyCreation, IbcClient, - InstallConfig, MFactoryQueryFns, ManagerExecFns, ManagerQueryFns, RegisteredModule, VCQueryFns, + Abstract, AbstractInterfaceError, AccountDetails, AccountExecFns, AccountI, AccountQueryFns, + DependencyCreation, IbcClient, InstallConfig, MFactoryQueryFns, RegisteredModule, VCQueryFns, }; use abstract_std::{ account, @@ -40,7 +40,7 @@ use abstract_std::{ AccountId, }, version_control::{self, NamespaceResponse}, - ACCOUNT, IBC_CLIENT, + IBC_CLIENT, }; use cosmwasm_std::{to_json_binary, Attribute, Coins, CosmosMsg, Uint128}; use cw_orch::{ diff --git a/framework/packages/abstract-client/src/application.rs b/framework/packages/abstract-client/src/application.rs index 939258b56..66382bcfe 100644 --- a/framework/packages/abstract-client/src/application.rs +++ b/framework/packages/abstract-client/src/application.rs @@ -2,7 +2,7 @@ //! //! [`Application`] represents a module installed on a (sub-)account -use abstract_interface::{ManagerExecFns, RegisteredModule}; +use abstract_interface::{AccountExecFns, RegisteredModule}; use abstract_std::objects::module::ModuleInfo; use cosmwasm_std::to_json_binary; use cw_orch::{contract::Contract, prelude::*}; diff --git a/framework/packages/abstract-client/src/client.rs b/framework/packages/abstract-client/src/client.rs index a096ceb20..5c6b541c2 100644 --- a/framework/packages/abstract-client/src/client.rs +++ b/framework/packages/abstract-client/src/client.rs @@ -29,8 +29,7 @@ //! ``` use abstract_interface::{ - Abstract, AccountI, AnsHost, IbcClient, ManagerQueryFns, RegisteredModule, VCQueryFns, - VersionControl, + Abstract, AccountI, AnsHost, IbcClient, RegisteredModule, VCQueryFns, VersionControl, }; use abstract_std::objects::{ module::{ModuleInfo, ModuleStatus, ModuleVersion}, diff --git a/framework/packages/abstract-client/src/interchain/remote_account.rs b/framework/packages/abstract-client/src/interchain/remote_account.rs index ab1f2a015..183de3ab5 100644 --- a/framework/packages/abstract-client/src/interchain/remote_account.rs +++ b/framework/packages/abstract-client/src/interchain/remote_account.rs @@ -4,8 +4,8 @@ //! use abstract_interface::{ - Abstract, AccountDetails, AccountI, DependencyCreation, IbcClient, InstallConfig, - ManagerQueryFns as _, RegisteredModule, VCQueryFns as _, + Abstract, AccountDetails, AccountI, AccountQueryFns as _, DependencyCreation, IbcClient, + InstallConfig, RegisteredModule, VCQueryFns as _, }; use abstract_std::{ account::{ @@ -19,7 +19,7 @@ use abstract_std::{ namespace::Namespace, ownership, AccountId, TruncatedChainId, }, - ACCOUNT, IBC_CLIENT, + IBC_CLIENT, }; use cosmwasm_std::{to_json_binary, CosmosMsg, Uint128}; use cw_orch::{ diff --git a/framework/packages/abstract-client/tests/integration.rs b/framework/packages/abstract-client/tests/integration.rs index e92ffcb25..c3e13df53 100644 --- a/framework/packages/abstract-client/tests/integration.rs +++ b/framework/packages/abstract-client/tests/integration.rs @@ -29,8 +29,7 @@ use abstract_std::{ ans_host::QueryMsgFns, objects::{ dependency::Dependency, fee::FixedFee, gov_type::GovernanceDetails, - module_version::ModuleDataResponse, namespace::Namespace, version_control, AccountId, - AssetEntry, + module_version::ModuleDataResponse, namespace::Namespace, AccountId, AssetEntry, }, IBC_CLIENT, }; diff --git a/framework/packages/abstract-interface/src/account.rs b/framework/packages/abstract-interface/src/account.rs index bb1d16198..082cbedad 100644 --- a/framework/packages/abstract-interface/src/account.rs +++ b/framework/packages/abstract-interface/src/account.rs @@ -14,7 +14,7 @@ use crate::{ get_account_contract, Abstract, AbstractInterfaceError, AdapterDeployer, VersionControl, }; -pub use abstract_std::account::{ExecuteMsgFns as ManagerExecFns, QueryMsgFns as ManagerQueryFns}; +pub use abstract_std::account::{ExecuteMsgFns as AccountExecFns, QueryMsgFns as AccountQueryFns}; use abstract_std::{ account::{AccountModuleInfo, ModuleInstallConfig, *}, adapter::{self, AdapterBaseMsg}, diff --git a/framework/packages/abstract-interface/src/deployment.rs b/framework/packages/abstract-interface/src/deployment.rs index 1ccab76bc..6231f9e4e 100644 --- a/framework/packages/abstract-interface/src/deployment.rs +++ b/framework/packages/abstract-interface/src/deployment.rs @@ -1,4 +1,3 @@ -use cosmwasm_std::Binary; #[cfg(feature = "daemon")] use cw_orch::daemon::DeployedChains; @@ -8,9 +7,7 @@ use crate::{ get_ibc_contracts, get_native_contracts, AbstractIbc, AbstractInterfaceError, AccountI, AnsHost, ModuleFactory, VersionControl, }; -use abstract_std::{ - objects::ABSTRACT_ACCOUNT_ID, ACCOUNT, ANS_HOST, MODULE_FACTORY, VERSION_CONTROL, -}; +use abstract_std::{ACCOUNT, ANS_HOST, MODULE_FACTORY, VERSION_CONTROL}; use rust_embed::RustEmbed; From 1ae3f3925629c2ceb9e42da9697353fda8028b71 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 16:37:59 +0300 Subject: [PATCH 11/12] nits Co-authored-by: cyberhoward --- .../abstract-testing/src/abstract_mock_querier.rs | 14 +++++++------- framework/packages/abstract-testing/src/lib.rs | 4 ++-- .../packages/abstract-testing/src/mock_querier.rs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/framework/packages/abstract-testing/src/abstract_mock_querier.rs b/framework/packages/abstract-testing/src/abstract_mock_querier.rs index 1bf0d445d..9ff994319 100644 --- a/framework/packages/abstract-testing/src/abstract_mock_querier.rs +++ b/framework/packages/abstract-testing/src/abstract_mock_querier.rs @@ -14,8 +14,8 @@ use cw_storage_plus::Item; use crate::prelude::*; pub trait AbstractMockQuerier { - /// Mock the existence of an Account by setting the Account id for the proxy and manager along with registering the account to version control. - fn account(self, account_base: &Account, account_id: AccountId) -> Self; + /// Mock the existence of an Account by setting the Account id for the account along with registering the account to version control. + fn account(self, account: &Account, account_id: AccountId) -> Self; /// Add mock assets into ANS fn assets(self, assets: Vec<(&AssetEntry, AssetInfo)>) -> Self; @@ -28,13 +28,13 @@ pub trait AbstractMockQuerier { } impl AbstractMockQuerier for MockQuerierBuilder { - /// Mock the existence of an Account by setting the Account id for the proxy and manager along with registering the account to version control. - fn account(self, account_base: &Account, account_id: AccountId) -> Self { + /// Mock the existence of an Account by setting the Account id for the account along with registering the account to version control. + fn account(self, account: &Account, account_id: AccountId) -> Self { let abstract_addrs = self.addrs(); - self.with_contract_item(account_base.addr(), ACCOUNT_ID, &account_id) + self.with_contract_item(account.addr(), ACCOUNT_ID, &account_id) // Setup the account owner as the test owner .with_contract_item( - account_base.addr(), + account.addr(), Item::new(OWNERSHIP_STORAGE_KEY), &Some(Ownership { owner: GovernanceDetails::Monarchy { @@ -47,7 +47,7 @@ impl AbstractMockQuerier for MockQuerierBuilder { .with_contract_map_entry( &abstract_addrs.version_control, ACCOUNT_ADDRESSES, - (&account_id, account_base.clone()), + (&account_id, account.clone()), ) } diff --git a/framework/packages/abstract-testing/src/lib.rs b/framework/packages/abstract-testing/src/lib.rs index 12e5eda94..a6798dbd8 100644 --- a/framework/packages/abstract-testing/src/lib.rs +++ b/framework/packages/abstract-testing/src/lib.rs @@ -147,7 +147,7 @@ pub mod addresses { const TEST_MODULE_FACTORY: &str = "module_factory_address"; const TEST_MODULE_ADDRESS: &str = "test_module_address"; - pub fn root_account_base(mock_api: MockApi) -> Account { + pub fn admin_account_base(mock_api: MockApi) -> Account { Account::new(mock_api.addr_make(ROOT_ACCOUNT)) } @@ -163,7 +163,7 @@ pub mod addresses { version_control: mock_api.addr_make(TEST_VERSION_CONTROL), module_factory: mock_api.addr_make(TEST_MODULE_FACTORY), module_address: mock_api.addr_make(TEST_MODULE_ADDRESS), - account: root_account_base(mock_api), + account: admin_account_base(mock_api), } } } diff --git a/framework/packages/abstract-testing/src/mock_querier.rs b/framework/packages/abstract-testing/src/mock_querier.rs index 64274c855..558c8d530 100644 --- a/framework/packages/abstract-testing/src/mock_querier.rs +++ b/framework/packages/abstract-testing/src/mock_querier.rs @@ -430,7 +430,7 @@ mod tests { use super::*; #[test] - fn should_return_base_account_address() { + fn should_return_admin_account_address() { let mut deps = mock_dependencies(); deps.querier = mock_querier(deps.api); let abstr = AbstractMockAddrs::new(deps.api); @@ -532,10 +532,10 @@ mod tests { use super::*; #[test] - fn should_return_root_acct_id_with_test_manager() { + fn should_return_admin_acct_id() { let mut deps = mock_dependencies(); deps.querier = mock_querier(deps.api); - let root_base = root_account_base(deps.api); + let root_base = admin_account_base(deps.api); let actual = ACCOUNT_ID.query(&wrap_querier(&deps.querier), root_base.addr().clone()); @@ -543,7 +543,7 @@ mod tests { } #[test] - fn should_return_test_acct_id_with_test_manager() { + fn should_return_test_acct_id() { let mut deps = mock_dependencies(); let test_base = test_account_base(deps.api); deps.querier = mock_querier_builder(deps.api) From d3950e62387eef39bc8488ddbb9a853de94e5756 Mon Sep 17 00:00:00 2001 From: Buckram Date: Mon, 16 Sep 2024 16:42:01 +0300 Subject: [PATCH 12/12] remove "_base" --- framework/packages/abstract-testing/src/lib.rs | 9 +++++---- framework/packages/abstract-testing/src/mock_querier.rs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/framework/packages/abstract-testing/src/lib.rs b/framework/packages/abstract-testing/src/lib.rs index a6798dbd8..a7a5e2954 100644 --- a/framework/packages/abstract-testing/src/lib.rs +++ b/framework/packages/abstract-testing/src/lib.rs @@ -140,17 +140,18 @@ pub mod addresses { // Test addr makers const OWNER: &str = "owner"; - const ROOT_ACCOUNT: &str = "root_account_address"; + const ADMIN_ACCOUNT: &str = "admin_account_address"; const TEST_ACCOUNT: &str = "account_address"; const TEST_ANS_HOST: &str = "test_ans_host_address"; const TEST_VERSION_CONTROL: &str = "version_control_address"; const TEST_MODULE_FACTORY: &str = "module_factory_address"; const TEST_MODULE_ADDRESS: &str = "test_module_address"; - pub fn admin_account_base(mock_api: MockApi) -> Account { - Account::new(mock_api.addr_make(ROOT_ACCOUNT)) + pub fn admin_account(mock_api: MockApi) -> Account { + Account::new(mock_api.addr_make(ADMIN_ACCOUNT)) } + // TODO: remove it pub fn test_account_base(mock_api: MockApi) -> Account { Account::new(mock_api.addr_make(TEST_ACCOUNT)) } @@ -163,7 +164,7 @@ pub mod addresses { version_control: mock_api.addr_make(TEST_VERSION_CONTROL), module_factory: mock_api.addr_make(TEST_MODULE_FACTORY), module_address: mock_api.addr_make(TEST_MODULE_ADDRESS), - account: admin_account_base(mock_api), + account: admin_account(mock_api), } } } diff --git a/framework/packages/abstract-testing/src/mock_querier.rs b/framework/packages/abstract-testing/src/mock_querier.rs index 558c8d530..553f6ad07 100644 --- a/framework/packages/abstract-testing/src/mock_querier.rs +++ b/framework/packages/abstract-testing/src/mock_querier.rs @@ -535,7 +535,7 @@ mod tests { fn should_return_admin_acct_id() { let mut deps = mock_dependencies(); deps.querier = mock_querier(deps.api); - let root_base = admin_account_base(deps.api); + let root_base = admin_account(deps.api); let actual = ACCOUNT_ID.query(&wrap_querier(&deps.querier), root_base.addr().clone());