diff --git a/contracts/account/manager/tests/adapters.rs b/contracts/account/manager/tests/adapters.rs index 45361605a..1ab6871be 100644 --- a/contracts/account/manager/tests/adapters.rs +++ b/contracts/account/manager/tests/adapters.rs @@ -219,7 +219,7 @@ fn reinstalling_new_version_should_install_latest() -> AResult { let account = create_default_account(&deployment.account_factory)?; deployment .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec!["tester".to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, "tester".to_string())?; let adapter1 = BootMockAdapter1V1::new_test(chain.clone()); adapter1.deploy(V1.parse().unwrap(), MockInitMsg).unwrap(); @@ -339,7 +339,7 @@ fn installing_specific_version_should_install_expected() -> AResult { let account = create_default_account(&deployment.account_factory)?; deployment .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec!["tester".to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, "tester".to_string())?; let adapter1 = BootMockAdapter1V1::new_test(chain.clone()); adapter1.deploy(V1.parse().unwrap(), MockInitMsg).unwrap(); diff --git a/contracts/account/manager/tests/common/mod.rs b/contracts/account/manager/tests/common/mod.rs index f0b555507..1d89d5047 100644 --- a/contracts/account/manager/tests/common/mod.rs +++ b/contracts/account/manager/tests/common/mod.rs @@ -43,7 +43,7 @@ pub(crate) fn init_mock_adapter( ) -> anyhow::Result> { deployment .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec!["tester".to_string()]); + .claim_namespace(TEST_ACCOUNT_ID, "tester".to_string()); let mut staking_adapter = BootMockAdapter::new(TEST_MODULE_ID, chain); let version: Version = version .unwrap_or_else(|| CONTRACT_VERSION.to_string()) diff --git a/contracts/account/manager/tests/upgrades.rs b/contracts/account/manager/tests/upgrades.rs index 347a9399c..844a259ac 100644 --- a/contracts/account/manager/tests/upgrades.rs +++ b/contracts/account/manager/tests/upgrades.rs @@ -48,7 +48,7 @@ fn install_app_successful() -> AResult { let AbstractAccount { manager, proxy: _ } = &account; abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); // dependency for mock_adapter1 not met @@ -87,7 +87,7 @@ fn install_app_versions_not_met() -> AResult { let AbstractAccount { manager, proxy: _ } = &account; abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); // install adapter 2 @@ -114,7 +114,7 @@ fn upgrade_app() -> AResult { let AbstractAccount { manager, proxy: _ } = &account; abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); // install adapter 1 @@ -284,7 +284,7 @@ fn uninstall_modules() -> AResult { let AbstractAccount { manager, proxy: _ } = &account; abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); let adapter1 = install_module_version(manager, &abstr, adapter_1::MOCK_ADAPTER_ID, V1)?; @@ -319,7 +319,7 @@ fn update_adapter_with_authorized_addrs() -> AResult { let AbstractAccount { manager, proxy } = &account; abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); // install adapter 1 @@ -369,7 +369,7 @@ fn upgrade_manager_last() -> AResult { abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; deploy_modules(&chain); // install adapter 1 @@ -431,7 +431,7 @@ fn no_duplicate_migrations() -> AResult { abstr .version_control - .claim_namespaces(TEST_ACCOUNT_ID, vec![TEST_NAMESPACE.to_string()])?; + .claim_namespace(TEST_ACCOUNT_ID, TEST_NAMESPACE.to_string())?; deploy_modules(&chain); // Install adapter 1 diff --git a/contracts/native/version-control/src/commands.rs b/contracts/native/version-control/src/commands.rs index 6c0d0196b..9f33727e4 100644 --- a/contracts/native/version-control/src/commands.rs +++ b/contracts/native/version-control/src/commands.rs @@ -252,11 +252,11 @@ pub fn set_module_monetization( /// Claim namespaces /// Only the Account Owner can do this -pub fn claim_namespaces( +pub fn claim_namespace( deps: DepsMut, msg_info: MessageInfo, account_id: AccountId, - namespaces_to_claim: Vec, + namespace_to_claim: String, ) -> VCResult { // verify account owner let account_base = ACCOUNT_ADDRESSES.load(deps.storage, account_id)?; @@ -268,60 +268,55 @@ pub fn claim_namespaces( }); } - let Config { - namespace_limit: namespaces_limit, - namespace_registration_fee: fee, - .. - } = CONFIG.load(deps.storage)?; - let limit = namespaces_limit as usize; - let existing_namespace_count = namespaces_info() + // check if the account already has a namespace + let has_namespace = namespaces_info() .idx .account_id .prefix(account_id) .range(deps.storage, None, None, Order::Ascending) - .count(); - if existing_namespace_count + namespaces_to_claim.len() > limit { + .take(1) + .count() + == 1; + if has_namespace { return Err(VCError::ExceedsNamespaceLimit { - limit, - current: existing_namespace_count, + limit: 1, + current: 1, }); } - if namespaces_to_claim.is_empty() { - // Nothing to do if there is no namespace to claim - return Err(VCError::NoAction); - } - let nb_namespaces: u128 = namespaces_to_claim.len().try_into().unwrap(); - let fee_to_charge = FixedFee::new(&fee) - .quantity(nb_namespaces) - .assert_payment(&msg_info)?; + let Config { + namespace_registration_fee: fee, + .. + } = CONFIG.load(deps.storage)?; let mut fee_messages = vec![]; - if !fee_to_charge.amount.is_zero() { + + if !fee.amount.is_zero() { + // assert it is paid + FixedFee::new(&fee).assert_payment(&msg_info)?; + // We transfer the namespace fee if necessary let admin_account = ACCOUNT_ADDRESSES.load(deps.storage, 0)?; fee_messages.push(CosmosMsg::Bank(BankMsg::Send { to_address: admin_account.proxy.to_string(), - amount: msg_info.funds, // No funds should be left on the contract. We ensure that here + amount: msg_info.funds, // })); } - for namespace in namespaces_to_claim.iter() { - let namespace = Namespace::try_from(namespace)?; - if let Some(id) = namespaces_info().may_load(deps.storage, &namespace)? { - return Err(VCError::NamespaceOccupied { - namespace: namespace.to_string(), - id, - }); - } - namespaces_info().save(deps.storage, &namespace, &account_id)?; + let namespace = Namespace::try_from(&namespace_to_claim)?; + if let Some(id) = namespaces_info().may_load(deps.storage, &namespace)? { + return Err(VCError::NamespaceOccupied { + namespace: namespace.to_string(), + id, + }); } + namespaces_info().save(deps.storage, &namespace, &account_id)?; Ok(VcResponse::new( - "claim_namespaces", + "claim_namespace", vec![ ("account_id", &account_id.to_string()), - ("namespaces", &namespaces_to_claim.join(",")), + ("namespaces", &namespace_to_claim), ], ) .add_messages(fee_messages)) @@ -379,7 +374,6 @@ pub fn update_config( deps: DepsMut, info: MessageInfo, allow_direct_module_registration_and_updates: Option, - namespace_limit: Option, namespace_registration_fee: Option, ) -> VCResult { cw_ownable::assert_owner(deps.storage, &info.sender)?; @@ -387,22 +381,6 @@ pub fn update_config( let mut attributes = vec![]; - if let Some(new_limit) = namespace_limit { - let previous_limit = config.namespace_limit; - ensure!( - new_limit > previous_limit, - VCError::DecreaseNamespaceLimit { - limit: new_limit, - current: previous_limit, - } - ); - config.namespace_limit = new_limit; - attributes.extend(vec![ - ("previous_namespace_limit", previous_limit.to_string()), - ("namespace_limit", new_limit.to_string()), - ]) - } - if let Some(allow) = allow_direct_module_registration_and_updates { let previous_allow = config.allow_direct_module_registration_and_updates; config.allow_direct_module_registration_and_updates = allow; @@ -544,7 +522,6 @@ mod test { info, InstantiateMsg { allow_direct_module_registration_and_updates: Some(true), - namespace_limit: 10, namespace_registration_fee: None, }, )?; @@ -565,7 +542,6 @@ mod test { admin_info, InstantiateMsg { allow_direct_module_registration_and_updates: Some(direct_registration_and_update), - namespace_limit: 10, namespace_registration_fee: None, }, )?; @@ -588,6 +564,22 @@ mod test { ) } + fn create_second_account(deps: DepsMut<'_>) { + // create second account + execute_as( + deps, + TEST_ACCOUNT_FACTORY, + ExecuteMsg::AddAccount { + account_id: 2, + account_base: AccountBase { + manager: Addr::unchecked(TEST_MANAGER), + proxy: Addr::unchecked(TEST_PROXY), + }, + }, + ) + .unwrap(); + } + fn execute_as(deps: DepsMut, sender: &str, msg: ExecuteMsg) -> VCResult { contract::execute(deps, mock_env(), mock_info(sender, &[]), msg) } @@ -687,10 +679,10 @@ mod test { } } - mod claim_namespaces { + mod claim_namespace { use super::*; use abstract_core::{objects, AbstractError}; - use cosmwasm_std::{coins, BankMsg, CosmosMsg, SubMsg, Uint128}; + use cosmwasm_std::{coins, BankMsg, CosmosMsg, SubMsg}; use objects::ABSTRACT_ACCOUNT_ID; @@ -700,17 +692,27 @@ mod test { deps.querier = mock_manager_querier().build(); mock_init_with_account(deps.as_mut(), true)?; let new_namespace1 = Namespace::new("namespace1").unwrap(); - let new_namespace2 = Namespace::new("namespace2").unwrap(); - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; let res = execute_as(deps.as_mut(), TEST_OWNER, msg); assert_that!(&res).is_ok(); + + create_second_account(deps.as_mut()); + + let new_namespace2 = Namespace::new("namespace2").unwrap(); + let msg = ExecuteMsg::ClaimNamespace { + account_id: 2, + namespace: new_namespace2.to_string(), + }; + let res = execute_as(deps.as_mut(), TEST_OWNER, msg); + assert_that!(&res).is_ok(); + let account_id = namespaces_info().load(&deps.storage, &new_namespace1)?; assert_that!(account_id).is_equal_to(TEST_ACCOUNT_ID); let account_id = namespaces_info().load(&deps.storage, &new_namespace2)?; - assert_that!(account_id).is_equal_to(TEST_ACCOUNT_ID); + assert_that!(account_id).is_equal_to(2); Ok(()) } @@ -730,7 +732,6 @@ mod test { deps.as_mut(), ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates: None, - namespace_limit: None, namespace_registration_fee: Some(one_namespace_fee.clone()), }, ) @@ -752,10 +753,9 @@ mod test { .unwrap(); let new_namespace1 = Namespace::new("namespace1").unwrap(); - let new_namespace2 = Namespace::new("namespace2").unwrap(); - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; // Fail, no fee at all let res = execute_as(deps.as_mut(), TEST_OWNER, msg.clone()); @@ -765,7 +765,7 @@ mod test { "Invalid fee payment sent. Expected {}, sent {:?}", Coin { denom: one_namespace_fee.denom.clone(), - amount: one_namespace_fee.amount * Uint128::from(2u128), + amount: one_namespace_fee.amount, }, Vec::::new() )))); @@ -779,13 +779,13 @@ mod test { "Invalid fee payment sent. Expected {}, sent {:?}", Coin { denom: one_namespace_fee.denom.clone(), - amount: one_namespace_fee.amount * Uint128::from(2u128), + amount: one_namespace_fee.amount, }, sent_coins )))); // Success - let sent_coins = coins(12, "ujunox"); + let sent_coins = coins(6, "ujunox"); let res = execute_as_with_funds(deps.as_mut(), TEST_OWNER, msg, &sent_coins); assert_that!(&res) .is_ok() @@ -804,10 +804,9 @@ mod test { deps.querier = mock_manager_querier().build(); mock_init_with_account(deps.as_mut(), true)?; let new_namespace1 = Namespace::new("namespace1").unwrap(); - let new_namespace2 = Namespace::new("namespace2").unwrap(); - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; let res = execute_as(deps.as_mut(), TEST_OTHER, msg); assert_that!(&res) @@ -824,17 +823,28 @@ mod test { let mut deps = mock_dependencies(); deps.querier = mock_manager_querier().build(); mock_init_with_account(deps.as_mut(), true)?; + // create second account + execute_as( + deps.as_mut(), + TEST_ACCOUNT_FACTORY, + ExecuteMsg::AddAccount { + account_id: 2, + account_base: AccountBase { + manager: Addr::unchecked(TEST_MANAGER), + proxy: Addr::unchecked(TEST_PROXY), + }, + }, + )?; let new_namespace1 = Namespace::new("namespace1")?; - let new_namespace2 = Namespace::new("namespace2")?; - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; - let msg = ExecuteMsg::ClaimNamespaces { - account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string()], + let msg = ExecuteMsg::ClaimNamespace { + account_id: 2, + namespace: new_namespace1.to_string(), }; let res = execute_as(deps.as_mut(), TEST_OWNER, msg); assert_that!(&res) @@ -890,9 +900,9 @@ mod test { )?; // Attempt to claim the abstract namespace with account 1 - let claim_abstract_msg = ExecuteMsg::ClaimNamespaces { + let claim_abstract_msg = ExecuteMsg::ClaimNamespace { account_id: 1, - namespaces: vec![Namespace::try_from(ABSTRACT_NAMESPACE)?.to_string()], + namespace: ABSTRACT_NAMESPACE.to_string(), }; let res = execute_as(deps.as_mut(), TEST_OWNER, claim_abstract_msg); assert_that!(&res) @@ -905,70 +915,6 @@ mod test { } } - mod update_namespace_limit { - use super::*; - - #[test] - fn only_admin() -> VersionControlTestResult { - let mut deps = mock_dependencies(); - mock_init(deps.as_mut())?; - - let msg = ExecuteMsg::UpdateConfig { - allow_direct_module_registration_and_updates: None, - namespace_limit: Some(100), - namespace_registration_fee: None, - }; - - let res = execute_as(deps.as_mut(), TEST_OTHER, msg); - assert_that!(&res) - .is_err() - .is_equal_to(&VCError::Ownership(OwnershipError::NotOwner)); - - Ok(()) - } - - #[test] - fn updates_limit() -> VersionControlTestResult { - let mut deps = mock_dependencies(); - mock_init(deps.as_mut())?; - - let msg = ExecuteMsg::UpdateConfig { - allow_direct_module_registration_and_updates: None, - namespace_limit: Some(100), - namespace_registration_fee: None, - }; - - let res = execute_as_admin(deps.as_mut(), msg); - assert_that!(&res).is_ok(); - - assert_that!(CONFIG.load(&deps.storage).unwrap().namespace_limit).is_equal_to(100); - - Ok(()) - } - - #[test] - fn no_decrease() -> VersionControlTestResult { - let mut deps = mock_dependencies(); - mock_init(deps.as_mut())?; - - let msg = ExecuteMsg::UpdateConfig { - allow_direct_module_registration_and_updates: None, - namespace_limit: Some(0), - namespace_registration_fee: None, - }; - - let res = execute_as_admin(deps.as_mut(), msg); - assert_that!(&res) - .is_err() - .is_equal_to(VCError::DecreaseNamespaceLimit { - current: 10, - limit: 0, - }); - - Ok(()) - } - } - mod update_direct_registration { use super::*; @@ -979,7 +925,6 @@ mod test { let msg = ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates: Some(false), - namespace_limit: None, namespace_registration_fee: None, }; @@ -992,20 +937,25 @@ mod test { } #[test] - fn updates_limit() -> VersionControlTestResult { + fn direct_registration() -> VersionControlTestResult { let mut deps = mock_dependencies(); mock_init(deps.as_mut())?; let msg = ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates: Some(false), - namespace_limit: None, namespace_registration_fee: None, }; let res = execute_as_admin(deps.as_mut(), msg); assert_that!(&res).is_ok(); - assert_that!(CONFIG.load(&deps.storage).unwrap().namespace_limit).is_equal_to(10); + assert_that!( + CONFIG + .load(&deps.storage) + .unwrap() + .allow_direct_module_registration_and_updates + ) + .is_equal_to(false); assert_that!( CONFIG .load(&deps.storage) @@ -1029,7 +979,6 @@ mod test { let msg = ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates: None, - namespace_limit: None, namespace_registration_fee: Some(Coin { denom: "ujunox".to_string(), amount: Uint128::one(), @@ -1045,7 +994,7 @@ mod test { } #[test] - fn updates_limit() -> VersionControlTestResult { + fn updates_fee() -> VersionControlTestResult { let mut deps = mock_dependencies(); mock_init(deps.as_mut())?; @@ -1056,14 +1005,12 @@ mod test { let msg = ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates: None, - namespace_limit: None, namespace_registration_fee: Some(new_fee.clone()), }; let res = execute_as_admin(deps.as_mut(), msg); assert_that!(&res).is_ok(); - assert_that!(CONFIG.load(&deps.storage).unwrap().namespace_limit).is_equal_to(10); assert_that!( CONFIG .load(&deps.storage) @@ -1095,16 +1042,11 @@ mod test { mock_init_with_account(deps.as_mut(), true)?; let new_namespace1 = Namespace::new("namespace1").unwrap(); let new_namespace2 = Namespace::new("namespace2").unwrap(); - let new_namespace3 = Namespace::new("namespace3").unwrap(); // add namespaces - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![ - new_namespace1.to_string(), - new_namespace2.to_string(), - new_namespace3.to_string(), - ], + namespace: new_namespace1.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1117,24 +1059,25 @@ mod test { let exists = namespaces_info().has(&deps.storage, &new_namespace1); assert_that!(exists).is_equal_to(false); + let msg = ExecuteMsg::ClaimNamespace { + account_id: TEST_ACCOUNT_ID, + namespace: new_namespace2.to_string(), + }; + execute_as(deps.as_mut(), TEST_OWNER, msg)?; + // remove as owner let msg = ExecuteMsg::RemoveNamespaces { - namespaces: vec![new_namespace2.to_string(), new_namespace3.to_string()], + namespaces: vec![new_namespace2.to_string()], }; let res = execute_as(deps.as_mut(), TEST_OWNER, msg); assert_that!(&res).is_ok(); let exists = namespaces_info().has(&deps.storage, &new_namespace2); assert_that!(exists).is_equal_to(false); - let exists = namespaces_info().has(&deps.storage, &new_namespace3); - assert_that!(exists).is_equal_to(false); assert_eq!( res.unwrap().events[0].attributes[2], attr( "namespaces", - format!( - "({}, {}),({}, {})", - new_namespace2, TEST_ACCOUNT_ID, new_namespace3, TEST_ACCOUNT_ID - ), + format!("({}, {})", new_namespace2, TEST_ACCOUNT_ID,), ) ); @@ -1147,12 +1090,11 @@ mod test { deps.querier = mock_manager_querier().build(); mock_init_with_account(deps.as_mut(), true)?; let new_namespace1 = Namespace::new("namespace1")?; - let new_namespace2 = Namespace::new("namespace2")?; // add namespaces - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1207,10 +1149,9 @@ mod test { // add namespaces let new_namespace1 = Namespace::new("namespace1")?; - let new_namespace2 = Namespace::new("namespace2")?; - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_namespace1.to_string(), new_namespace2.to_string()], + namespace: new_namespace1.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1237,6 +1178,7 @@ mod test { } mod propose_modules { + use abstract_core::objects::fee::FixedFee; use abstract_core::objects::module_reference::ModuleReference; use abstract_core::AbstractError; use abstract_testing::prelude::TEST_MODULE_ID; @@ -1293,9 +1235,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; @@ -1322,9 +1264,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; @@ -1362,9 +1304,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; @@ -1428,9 +1370,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; @@ -1466,9 +1408,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; @@ -1491,9 +1433,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; // add modules @@ -1538,9 +1480,9 @@ mod test { execute_as( deps.as_mut(), TEST_OWNER, - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![new_module.namespace.to_string()], + namespace: new_module.namespace.to_string(), }, )?; // add modules @@ -1582,9 +1524,9 @@ mod test { let rm_module = test_module(); // add namespaces - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![rm_module.namespace.to_string()], + namespace: rm_module.namespace.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1622,9 +1564,9 @@ mod test { let rm_module = test_module(); // add namespaces as the account owner - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![rm_module.namespace.to_string()], + namespace: rm_module.namespace.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1658,9 +1600,9 @@ mod test { let rm_module = test_module(); // add namespaces as the owner - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![rm_module.namespace.to_string()], + namespace: rm_module.namespace.to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1693,9 +1635,9 @@ mod test { mock_init_with_account(deps.as_mut(), true)?; // add namespaces - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec!["namespace".to_string()], + namespace: "namespace".to_string(), }; execute_as(deps.as_mut(), TEST_OWNER, msg)?; @@ -1840,9 +1782,9 @@ mod test { } fn claim_test_namespace_as_owner(deps: DepsMut) -> VersionControlTestResult { - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![TEST_NAMESPACE.to_string()], + namespace: TEST_NAMESPACE.to_string(), }; execute_as(deps, TEST_OWNER, msg)?; Ok(()) diff --git a/contracts/native/version-control/src/contract.rs b/contracts/native/version-control/src/contract.rs index 55a4840d0..081c1c0df 100644 --- a/contracts/native/version-control/src/contract.rs +++ b/contracts/native/version-control/src/contract.rs @@ -44,7 +44,6 @@ pub fn instantiate(deps: DepsMut, _env: Env, info: MessageInfo, msg: Instantiate let InstantiateMsg { allow_direct_module_registration_and_updates, - namespace_limit, namespace_registration_fee, } = msg; @@ -53,7 +52,6 @@ pub fn instantiate(deps: DepsMut, _env: Env, info: MessageInfo, msg: Instantiate &Config { allow_direct_module_registration_and_updates: allow_direct_module_registration_and_updates.unwrap_or(false), - namespace_limit, namespace_registration_fee: namespace_registration_fee.unwrap_or(Coin { denom: "none".to_string(), amount: Uint128::zero(), @@ -90,10 +88,10 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> V namespace, monetization, } => set_module_monetization(deps, info, module_name, namespace, monetization), - ExecuteMsg::ClaimNamespaces { + ExecuteMsg::ClaimNamespace { + namespace, account_id, - namespaces, - } => claim_namespaces(deps, info, account_id, namespaces), + } => claim_namespace(deps, info, account_id, namespace), ExecuteMsg::RemoveNamespaces { namespaces } => remove_namespaces(deps, info, namespaces), ExecuteMsg::AddAccount { account_id, @@ -101,13 +99,11 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> V } => add_account(deps, info, account_id, base), ExecuteMsg::UpdateConfig { allow_direct_module_registration_and_updates, - namespace_limit, namespace_registration_fee, } => update_config( deps, info, allow_direct_module_registration_and_updates, - namespace_limit, namespace_registration_fee, ), ExecuteMsg::SetFactory { new_factory } => set_factory(deps, info, new_factory), @@ -144,17 +140,12 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> VCResult { limit, filter, )?), - QueryMsg::NamespaceList { - filter, - start_after, - limit, - } => { + QueryMsg::NamespaceList { start_after, limit } => { let start_after = start_after.map(Namespace::try_from).transpose()?; to_binary(&queries::handle_namespace_list_query( deps, start_after, limit, - filter, )?) } QueryMsg::Ownership {} => to_binary(&query_ownership!(deps)?), diff --git a/contracts/native/version-control/src/lib.rs b/contracts/native/version-control/src/lib.rs index 2dc8a85c0..ec6b43fbc 100644 --- a/contracts/native/version-control/src/lib.rs +++ b/contracts/native/version-control/src/lib.rs @@ -21,7 +21,6 @@ mod testing { info, version_control::InstantiateMsg { allow_direct_module_registration_and_updates: Some(true), - namespace_limit: 10, namespace_registration_fee: None, }, ) diff --git a/contracts/native/version-control/src/queries.rs b/contracts/native/version-control/src/queries.rs index c9f711b7a..848b67082 100644 --- a/contracts/native/version-control/src/queries.rs +++ b/contracts/native/version-control/src/queries.rs @@ -4,7 +4,7 @@ use abstract_core::{ objects::module::{ModuleStatus, Monetization}, version_control::{ state::{MODULE_MONETIZATION, PENDING_MODULES}, - ModuleConfiguration, NamespaceFilter, NamespaceResponse, + ModuleConfiguration, NamespaceResponse, }, }; use abstract_sdk::core::{ @@ -195,27 +195,14 @@ pub fn handle_namespace_list_query( deps: Deps, start_after: Option, limit: Option, - filter: Option, ) -> StdResult { let start_bound = start_after.as_ref().map(Bound::exclusive); let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize; - let NamespaceFilter { account_id } = filter.unwrap_or_default(); - - let namespaces = if let Some(account_id) = account_id { - namespaces_info() - .idx - .account_id - .prefix(account_id) - .range(deps.storage, start_bound, None, Order::Ascending) - .take(limit) - .collect::>>()? - } else { - namespaces_info() - .range(deps.storage, start_bound, None, Order::Ascending) - .take(limit) - .collect::>>()? - }; + let namespaces = namespaces_info() + .range(deps.storage, start_bound, None, Order::Ascending) + .take(limit) + .collect::>>()?; Ok(NamespaceListResponse { namespaces }) } @@ -350,7 +337,6 @@ mod test { info, InstantiateMsg { allow_direct_module_registration_and_updates: Some(true), - namespace_limit: 10, namespace_registration_fee: None, }, )?; @@ -407,9 +393,9 @@ mod test { use cosmwasm_std::from_binary; fn add_namespace(deps: DepsMut, namespace: &str) { - let msg = ExecuteMsg::ClaimNamespaces { + let msg = ExecuteMsg::ClaimNamespace { account_id: TEST_ACCOUNT_ID, - namespaces: vec![namespace.to_string()], + namespace: namespace.to_string(), }; let res = execute_as_admin(deps, msg); @@ -523,24 +509,26 @@ mod test { use cosmwasm_std::from_binary; /// Add namespaces - fn add_namespaces(deps: DepsMut, namespaces: Vec, account_id: u32, sender: &str) { - let msg = ExecuteMsg::ClaimNamespaces { - account_id, - namespaces, - }; + fn add_namespaces(mut deps: DepsMut, acc_and_namespace: Vec<(u32, &str)>, sender: &str) { + for (account_id, namespace) in acc_and_namespace { + let msg = ExecuteMsg::ClaimNamespace { + account_id, + namespace: namespace.to_string(), + }; - let res = execute_as(deps, sender, msg); - assert_that!(&res).is_ok(); + let res = execute_as(deps.branch(), sender, msg); + assert_that!(&res).is_ok(); + } } /// Add the provided modules to the version control - fn propose_modules(deps: DepsMut, new_module_infos: Vec) { + fn propose_modules(deps: DepsMut, new_module_infos: Vec, sender: &str) { let modules = new_module_infos .into_iter() .map(|info| (info, ModuleReference::App(0))) .collect(); let add_msg = ExecuteMsg::ProposeModules { modules }; - let res = execute_as_admin(deps, add_msg); + let res = execute_as(deps, sender, add_msg); assert_that!(&res).is_ok(); } @@ -557,22 +545,26 @@ mod test { fn init_with_mods(mut deps: DepsMut) { mock_init_with_account(deps.branch()).unwrap(); - let namespaces = vec!["cw-plus".to_string(), "4t2".to_string()]; - add_namespaces(deps.branch(), namespaces, TEST_ACCOUNT_ID, TEST_ADMIN); + add_namespaces( + deps.branch(), + vec![(TEST_ACCOUNT_ID, "cw-plus")], + TEST_ADMIN, + ); + add_namespaces(deps.branch(), vec![(2, "4t2")], TEST_OTHER); let cw_mods = vec![ ModuleInfo::from_id("cw-plus:module1", ModuleVersion::Version("0.1.2".into())).unwrap(), ModuleInfo::from_id("cw-plus:module2", ModuleVersion::Version("0.1.2".into())).unwrap(), ModuleInfo::from_id("cw-plus:module3", ModuleVersion::Version("0.1.2".into())).unwrap(), ]; - propose_modules(deps.branch(), cw_mods); + propose_modules(deps.branch(), cw_mods, TEST_ADMIN); let fortytwo_mods = vec![ ModuleInfo::from_id("4t2:module1", ModuleVersion::Version("0.1.2".into())).unwrap(), ModuleInfo::from_id("4t2:module2", ModuleVersion::Version("0.1.2".into())).unwrap(), ModuleInfo::from_id("4t2:module3", ModuleVersion::Version("0.1.2".into())).unwrap(), ]; - propose_modules(deps, fortytwo_mods); + propose_modules(deps, fortytwo_mods, TEST_OTHER); } mod modules { @@ -690,7 +682,7 @@ mod test { ModuleInfo::from_id("cw-plus:module5", ModuleVersion::Version("0.1.2".into())) .unwrap(), ]; - propose_modules(deps.as_mut(), cw_mods); + propose_modules(deps.as_mut(), cw_mods, TEST_ADMIN); yank_module( deps.as_mut(), ModuleInfo::from_id("cw-plus:module4", ModuleVersion::Version("0.1.2".into())) @@ -739,7 +731,7 @@ mod test { ModuleInfo::from_id("cw-plus:module5", ModuleVersion::Version("0.1.2".into())) .unwrap(), ]; - propose_modules(deps.as_mut(), cw_mods); + propose_modules(deps.as_mut(), cw_mods, TEST_ADMIN); yank_module( deps.as_mut(), ModuleInfo::from_id("cw-plus:module4", ModuleVersion::Version("0.1.2".into())) @@ -786,25 +778,17 @@ mod test { mock_init_with_account(deps.as_mut()).unwrap(); add_namespaces( deps.as_mut(), - vec![ - "cw-plus".to_string(), - "aoeu".to_string(), - "snth".to_string(), - ], - TEST_ACCOUNT_ID, + vec![(TEST_ACCOUNT_ID, "cw-plus")], TEST_ADMIN, ); - let cw_mods = vec![ - ModuleInfo::from_id("cw-plus:module1", ModuleVersion::Version("0.1.2".into())) - .unwrap(), - ModuleInfo::from_id("aoeu:module2", ModuleVersion::Version("0.1.2".into())) - .unwrap(), - ModuleInfo::from_id("snth:module3", ModuleVersion::Version("0.1.2".into())) - .unwrap(), - ]; - propose_modules(deps.as_mut(), cw_mods); + let cw_mods = vec![ModuleInfo::from_id( + "cw-plus:module1", + ModuleVersion::Version("0.1.2".into()), + ) + .unwrap()]; + propose_modules(deps.as_mut(), cw_mods, TEST_ADMIN); - let filtered_namespace = "dne".to_string(); + let filtered_namespace = "cw-plus".to_string(); let filter = ModuleFilter { namespace: Some(filtered_namespace), @@ -817,7 +801,7 @@ mod test { assert_that!(res).is_ok().map(|res| { let ModulesListResponse { modules } = from_binary(res).unwrap(); - assert_that!(modules).is_empty(); + assert_that!(modules).has_length(1); res }); @@ -870,6 +854,7 @@ mod test { ModuleVersion::Version("0.1.3".into()), ) .unwrap()], + TEST_ADMIN, ); let filter = ModuleFilter { @@ -1017,77 +1002,25 @@ mod test { } } - mod list_namespaces { + mod query_namespaces { use super::*; - fn filtered_list_msg(filter: NamespaceFilter) -> QueryMsg { - QueryMsg::NamespaceList { - filter: Some(filter), - start_after: None, - limit: None, - } - } - #[test] - fn filter_namespaces() { + fn namespaces() { let mut deps = mock_dependencies(); deps.querier = mock_manager_querier().build(); init_with_mods(deps.as_mut()); - // add namespaces as others - let namespaces = vec![ - "other1".to_string(), - "other2".to_string(), - "other3".to_string(), - ]; - add_namespaces( - deps.as_mut(), - namespaces.clone(), - TEST_OTHER_ACCOUNT_ID, - TEST_OTHER, + // get for test other account + let res = query_helper( + deps.as_ref(), + QueryMsg::Namespaces { + accounts: vec![TEST_OTHER_ACCOUNT_ID], + }, ); - - // get all - let list_msg = filtered_list_msg(NamespaceFilter { account_id: None }); - let res = query_helper(deps.as_ref(), list_msg); - - assert_that!(res).is_ok().map(|res| { - let NamespaceListResponse { namespaces: resp } = from_binary(res).unwrap(); - println!("{:?}", resp); - assert_that!(resp).has_length(6); - res - }); - - // get by another id - let list_msg = filtered_list_msg(NamespaceFilter { - account_id: Some(TEST_OTHER_ACCOUNT_ID), - }); - let res = query_helper(deps.as_ref(), list_msg); assert_that!(res).is_ok().map(|res| { - let NamespaceListResponse { namespaces: resp } = from_binary(res).unwrap(); - assert_that!(resp).has_length(3); - - for entry in resp { - assert_that!(namespaces.contains(&entry.0.to_string())).is_equal_to(true); - assert_that!(entry.1).is_equal_to(TEST_OTHER_ACCOUNT_ID); - } - - res - }); - - // get by admin id - let list_msg = filtered_list_msg(NamespaceFilter { - account_id: Some(TEST_ACCOUNT_ID), - }); - let res = query_helper(deps.as_ref(), list_msg); - assert_that!(res).is_ok().map(|res| { - let NamespaceListResponse { namespaces: resp } = from_binary(res).unwrap(); - assert_that!(resp).has_length(2); - - for entry in resp { - assert_that!(entry.1).is_equal_to(TEST_ACCOUNT_ID); - } - + let NamespacesResponse { namespaces } = from_binary(res).unwrap(); + assert_that!(namespaces[0].0.to_string()).is_equal_to("4t2".to_string()); res }); } diff --git a/docs/src/1_intro.md b/docs/src/1_intro.md index 22b591115..e4a151f1c 100644 --- a/docs/src/1_intro.md +++ b/docs/src/1_intro.md @@ -73,7 +73,7 @@ let account = // Claim the namespace so app can be deployed abstr_deployment .version_control - .claim_namespaces(1, vec!["my-namespace".to_string()])?; + .claim_namespace(1, "my-namespace".to_string())?; // Deploy the app! contract.deploy(APP_VERSION.parse()?)?; diff --git a/packages/abstract-core/src/native/version_control.rs b/packages/abstract-core/src/native/version_control.rs index c8d1a8090..b09ee1e12 100644 --- a/packages/abstract-core/src/native/version_control.rs +++ b/packages/abstract-core/src/native/version_control.rs @@ -14,7 +14,6 @@ pub type ModuleMapEntry = (ModuleInfo, ModuleReference); #[cosmwasm_schema::cw_serde] pub struct Config { pub allow_direct_module_registration_and_updates: bool, - pub namespace_limit: u32, pub namespace_registration_fee: cosmwasm_std::Coin, } @@ -96,7 +95,6 @@ pub struct InstantiateMsg { /// Also allows them to change the module reference of an existing module /// SHOULD ONLY BE `true` FOR TESTING pub allow_direct_module_registration_and_updates: Option, - pub namespace_limit: u32, pub namespace_registration_fee: Option, } @@ -130,9 +128,9 @@ pub enum ExecuteMsg { rejects: Vec, }, /// Claim namespaces - ClaimNamespaces { + ClaimNamespace { account_id: AccountId, - namespaces: Vec, + namespace: String, }, /// Remove namespace claims /// Only admin or root user can call this @@ -148,7 +146,6 @@ pub enum ExecuteMsg { /// 2. the number of namespaces an Account can claim UpdateConfig { allow_direct_module_registration_and_updates: Option, - namespace_limit: Option, namespace_registration_fee: Option, }, /// Sets a new Factory @@ -165,13 +162,6 @@ pub struct ModuleFilter { pub status: Option, } -/// A NamespaceFilter for [`Namespaces`]. -#[derive(Default)] -#[cosmwasm_schema::cw_serde] -pub struct NamespaceFilter { - pub account_id: Option, -} - /// Version Control Query Msg #[cw_ownable::cw_ownable_query] #[cosmwasm_schema::cw_serde] @@ -208,7 +198,6 @@ pub enum QueryMsg { /// Returns [`NamespaceListResponse`] #[returns(NamespaceListResponse)] NamespaceList { - filter: Option, start_after: Option, limit: Option, }, diff --git a/packages/abstract-interface/src/deployment.rs b/packages/abstract-interface/src/deployment.rs index 6311cbd22..10c0cb8ca 100644 --- a/packages/abstract-interface/src/deployment.rs +++ b/packages/abstract-interface/src/deployment.rs @@ -141,7 +141,6 @@ impl Abstract { self.version_control.instantiate( &abstract_core::version_control::InstantiateMsg { allow_direct_module_registration_and_updates: Some(true), - namespace_limit: 1, namespace_registration_fee: None, }, Some(sender),