diff --git a/contracts/incentives/src/migrations/v2_1_0.rs b/contracts/incentives/src/migrations/v2_1_0.rs index 2eb56b13..7e4a0d47 100644 --- a/contracts/incentives/src/migrations/v2_1_0.rs +++ b/contracts/incentives/src/migrations/v2_1_0.rs @@ -1,16 +1,28 @@ use cosmwasm_std::{DepsMut, Response}; use cw2::{assert_contract_version, set_contract_version}; +use mars_types::incentives::Config; use crate::{ contract::{CONTRACT_NAME, CONTRACT_VERSION}, error::ContractError, + state::CONFIG, }; const FROM_VERSION: &str = "2.0.0"; pub mod v1_state { + use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Decimal, DepsMut, Uint128}; - use cw_storage_plus::Map; + use cw_storage_plus::{Item, Map}; + + #[cw_serde] + pub struct Config { + pub address_provider: Addr, + pub max_whitelisted_denoms: u8, + pub mars_denom: String, + } + + pub const CONFIG: Item = Item::new("config"); /// Don't care about the actual types, just use some dummy types to clear the storage pub const ASSET_INCENTIVES: Map<&str, String> = Map::new("incentives"); @@ -31,6 +43,15 @@ pub fn migrate(mut deps: DepsMut) -> Result { // Make sure we're migrating the correct contract and from the correct version assert_contract_version(deps.storage, &format!("crates.io:{CONTRACT_NAME}"), FROM_VERSION)?; + // Migrate old config to new config + let old_config = v1_state::CONFIG.load(deps.storage)?; + let new_config = Config { + address_provider: old_config.address_provider, + max_whitelisted_denoms: old_config.max_whitelisted_denoms, + }; + v1_state::CONFIG.remove(deps.storage); + CONFIG.save(deps.storage, &new_config)?; + // Clear old state v1_state::clear_state(&mut deps); diff --git a/contracts/incentives/tests/tests/test_migration_v2.rs b/contracts/incentives/tests/tests/test_migration_v2.rs index b9533376..f67398e3 100644 --- a/contracts/incentives/tests/tests/test_migration_v2.rs +++ b/contracts/incentives/tests/tests/test_migration_v2.rs @@ -1,7 +1,10 @@ -use cosmwasm_std::{attr, testing::mock_env, Empty, Event}; +use cosmwasm_std::{attr, testing::mock_env, Addr, Empty, Event}; use cw2::{ContractVersion, VersionError}; -use mars_incentives::{contract::migrate, ContractError}; +use mars_incentives::{ + contract::migrate, migrations::v2_1_0::v1_state, state::CONFIG, ContractError, +}; use mars_testing::mock_dependencies; +use mars_types::incentives::Config; #[test] fn wrong_contract_name() { @@ -40,8 +43,28 @@ fn successful_migration() { let mut deps = mock_dependencies(&[]); cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-incentives", "2.0.0").unwrap(); + v1_state::CONFIG + .save( + deps.as_mut().storage, + &v1_state::Config { + address_provider: Addr::unchecked("addr_provider".to_string()), + max_whitelisted_denoms: 15, + mars_denom: "mars".to_string(), + }, + ) + .unwrap(); + let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap(); + let config = CONFIG.load(deps.as_ref().storage).unwrap(); + assert_eq!( + config, + Config { + address_provider: Addr::unchecked("addr_provider".to_string()), + max_whitelisted_denoms: 15, + } + ); + assert_eq!(res.messages, vec![]); assert_eq!(res.events, vec![] as Vec); assert!(res.data.is_none());