From 9b503956a00276beb08e324542b47a0a677d2029 Mon Sep 17 00:00:00 2001 From: CJ Cobb Date: Thu, 14 Nov 2024 12:11:45 -0500 Subject: [PATCH 1/2] fix(minor-service-registry): remove old migration handler --- contracts/service-registry/src/contract.rs | 3 +- .../src/contract/migrations/mod.rs | 1 - .../src/contract/migrations/v0_4_1.rs | 117 ------------------ 3 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 contracts/service-registry/src/contract/migrations/v0_4_1.rs diff --git a/contracts/service-registry/src/contract.rs b/contracts/service-registry/src/contract.rs index 67cada62a..9731b2e35 100644 --- a/contracts/service-registry/src/contract.rs +++ b/contracts/service-registry/src/contract.rs @@ -18,6 +18,7 @@ mod query; const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); +const BASE_VERSION: &str = "1.0.0"; #[cfg_attr(not(feature = "library"), entry_point)] pub fn instantiate( @@ -191,7 +192,7 @@ pub fn migrate( _env: Env, _msg: Empty, ) -> Result { - migrations::v0_4_1::migrate(deps.storage)?; + cw2::assert_contract_version(deps.storage, CONTRACT_NAME, BASE_VERSION)?; cw2::set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; diff --git a/contracts/service-registry/src/contract/migrations/mod.rs b/contracts/service-registry/src/contract/migrations/mod.rs index 080e953e7..e69de29bb 100644 --- a/contracts/service-registry/src/contract/migrations/mod.rs +++ b/contracts/service-registry/src/contract/migrations/mod.rs @@ -1 +0,0 @@ -pub mod v0_4_1; diff --git a/contracts/service-registry/src/contract/migrations/v0_4_1.rs b/contracts/service-registry/src/contract/migrations/v0_4_1.rs deleted file mode 100644 index b06e781c8..000000000 --- a/contracts/service-registry/src/contract/migrations/v0_4_1.rs +++ /dev/null @@ -1,117 +0,0 @@ -#![allow(deprecated)] -use axelar_wasm_std::error::ContractError; -use axelar_wasm_std::permission_control; -use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, StdResult, Storage}; -use cw_storage_plus::Item; - -use crate::contract::CONTRACT_NAME; - -const BASE_VERSION: &str = "0.4.1"; -pub fn migrate(storage: &mut dyn Storage) -> Result<(), ContractError> { - cw2::assert_contract_version(storage, CONTRACT_NAME, BASE_VERSION)?; - - let config = CONFIG.load(storage)?; - delete_config(storage); - migrate_permission_control(storage, config)?; - - Ok(()) -} - -fn migrate_permission_control(storage: &mut dyn Storage, config: Config) -> StdResult<()> { - permission_control::set_governance(storage, &config.governance) -} - -fn delete_config(storage: &mut dyn Storage) { - CONFIG.remove(storage) -} - -#[cw_serde] -#[deprecated(since = "0.4.1", note = "Only used during migrations")] -pub struct Config { - pub governance: Addr, -} - -#[deprecated(since = "0.4.1", note = "Only used during migrations")] -pub const CONFIG: Item = Item::new("config"); - -#[cfg(test)] -mod tests { - use axelar_wasm_std::permission_control; - use axelar_wasm_std::permission_control::Permission; - use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{Addr, DepsMut, Env, MessageInfo, Response}; - - use crate::contract::migrations::v0_4_1; - use crate::contract::CONTRACT_NAME; - use crate::msg::InstantiateMsg; - - const GOVERNANCE: &str = "governance"; - - #[test] - fn migrate_checks_contract_version() { - let mut deps = mock_dependencies(); - instantiate_contract(deps.as_mut()); - - cw2::set_contract_version(deps.as_mut().storage, CONTRACT_NAME, "something wrong").unwrap(); - - assert!(v0_4_1::migrate(deps.as_mut().storage).is_err()); - - cw2::set_contract_version(deps.as_mut().storage, CONTRACT_NAME, v0_4_1::BASE_VERSION) - .unwrap(); - - assert!(v0_4_1::migrate(deps.as_mut().storage).is_ok()); - } - #[test] - fn migrate_to_permission_control() { - let mut deps = mock_dependencies(); - instantiate_contract(deps.as_mut()); - - assert!(v0_4_1::migrate(deps.as_mut().storage).is_ok()); - - assert!( - permission_control::sender_role(&deps.storage, &Addr::unchecked(GOVERNANCE)) - .unwrap() - .contains(Permission::Governance) - ); - } - - #[test] - fn migrate_deletes_config() { - let mut deps = mock_dependencies(); - instantiate_contract(deps.as_mut()); - - assert!(v0_4_1::migrate(deps.as_mut().storage).is_ok()); - - assert!(v0_4_1::CONFIG.load(&deps.storage).is_err()) - } - - fn instantiate_contract(deps: DepsMut) { - instantiate( - deps, - mock_env(), - mock_info("admin", &[]), - InstantiateMsg { - governance_account: GOVERNANCE.to_string(), - }, - ) - .unwrap(); - } - #[deprecated(since = "0.4.1", note = "Only used to test the migration")] - fn instantiate( - deps: DepsMut, - _env: Env, - _info: MessageInfo, - msg: InstantiateMsg, - ) -> Result { - cw2::set_contract_version(deps.storage, CONTRACT_NAME, v0_4_1::BASE_VERSION)?; - - v0_4_1::CONFIG.save( - deps.storage, - &v0_4_1::Config { - governance: deps.api.addr_validate(&msg.governance_account)?, - }, - )?; - Ok(Response::default()) - } -} From 1cb8028edfd73b9dde00d4b1327048b2a621da73 Mon Sep 17 00:00:00 2001 From: CJ Cobb Date: Thu, 14 Nov 2024 12:17:09 -0500 Subject: [PATCH 2/2] lint --- contracts/service-registry/src/contract/migrations/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/contracts/service-registry/src/contract/migrations/mod.rs b/contracts/service-registry/src/contract/migrations/mod.rs index e69de29bb..8b1378917 100644 --- a/contracts/service-registry/src/contract/migrations/mod.rs +++ b/contracts/service-registry/src/contract/migrations/mod.rs @@ -0,0 +1 @@ +