cosmwasm: comment terra2 migration so tests pass

This commit is contained in:
Evan Gray 2022-10-12 20:41:36 +00:00 committed by Evan Gray
parent 3a37db8b98
commit 346f2f4e0e
1 changed files with 39 additions and 39 deletions

View File

@ -135,50 +135,50 @@ pub enum TransferType<A> {
/// Ok(Response::default()) /// Ok(Response::default())
/// ``` /// ```
#[cfg_attr(not(feature = "library"), entry_point)] #[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> { pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
// This migration adds a new field to the [`ConfigInfo`] struct. The // // This migration adds a new field to the [`ConfigInfo`] struct. The
// state stored on chain has the old version, so we first parse it as // // state stored on chain has the old version, so we first parse it as
// [`ConfigInfoLegacy`], then add the new fields, and write it back as [`ConfigInfo`]. // // [`ConfigInfoLegacy`], then add the new fields, and write it back as [`ConfigInfo`].
// Since the only place the contract with the legacy state is deployed is // // Since the only place the contract with the legacy state is deployed is
// terra2, we just hardcode the new value here for that chain. // // terra2, we just hardcode the new value here for that chain.
// 1. make sure this contract doesn't already have the new ConfigInfo struct // // 1. make sure this contract doesn't already have the new ConfigInfo struct
// in storage. Note that this check is not strictly necessary, as the // // in storage. Note that this check is not strictly necessary, as the
// upgrade will only be issued for terra2, and no new chains. However, it is // // upgrade will only be issued for terra2, and no new chains. However, it is
// good practice to ensure that migration code cannot be run twice, which // // good practice to ensure that migration code cannot be run twice, which
// this check achieves. // // this check achieves.
if config_read(deps.storage).load().is_ok() { // if config_read(deps.storage).load().is_ok() {
return Err(StdError::generic_err( // return Err(StdError::generic_err(
"Can't migrate; this contract already has a new ConfigInfo struct", // "Can't migrate; this contract already has a new ConfigInfo struct",
)); // ));
} // }
// 2. parse old state // // 2. parse old state
let ConfigInfoLegacy { // let ConfigInfoLegacy {
gov_chain, // gov_chain,
gov_address, // gov_address,
wormhole_contract, // wormhole_contract,
wrapped_asset_code_id, // wrapped_asset_code_id,
} = config_read_legacy(deps.storage).load()?; // } = config_read_legacy(deps.storage).load()?;
// 3. store new state with terra2 values hardcoded // // 3. store new state with terra2 values hardcoded
let chain_id = 18; // let chain_id = 18;
let native_denom = "uluna".to_string(); // let native_denom = "uluna".to_string();
let native_symbol = "LUNA".to_string(); // let native_symbol = "LUNA".to_string();
let native_decimals = 6; // let native_decimals = 6;
let config_info = ConfigInfo { // let config_info = ConfigInfo {
gov_chain, // gov_chain,
gov_address, // gov_address,
wormhole_contract, // wormhole_contract,
wrapped_asset_code_id, // wrapped_asset_code_id,
chain_id, // chain_id,
native_denom, // native_denom,
native_symbol, // native_symbol,
native_decimals // native_decimals
}; // };
config(deps.storage).save(&config_info)?; // config(deps.storage).save(&config_info)?;
Ok(Response::default()) Ok(Response::default())
} }