From 3cc352c96bd986951dc644ebe661fa2a170385dc Mon Sep 17 00:00:00 2001 From: sabinchitrakar Date: Thu, 3 Aug 2023 11:25:11 +0545 Subject: [PATCH 1/2] fix: update version on migrate --- Cargo.toml | 1 + contracts/cosmwasm-vm/cw-xcall/Cargo.toml | 3 ++- contracts/cosmwasm-vm/cw-xcall/src/contract.rs | 13 ++++++++++++- contracts/cosmwasm-vm/cw-xcall/src/lib.rs | 6 ++++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5ee67bff..dd35bc09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ [workspace.package] authors = ["Icon Foundation"] repository = "https://github.com/icon-project/ibc-integration.git" +version="0.1.0" [workspace.dependencies] cosmwasm-std = {version="1.2.2",default-features = false,features = ["iterator", "staking"]} diff --git a/contracts/cosmwasm-vm/cw-xcall/Cargo.toml b/contracts/cosmwasm-vm/cw-xcall/Cargo.toml index be504bca..1139d686 100644 --- a/contracts/cosmwasm-vm/cw-xcall/Cargo.toml +++ b/contracts/cosmwasm-vm/cw-xcall/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "cw-xcall" -version = "0.1.0" +version.workspace = true +authors.workspace = true edition = "2021" exclude = [ diff --git a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs index 0eeb60cd..884bd3d0 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs @@ -4,7 +4,7 @@ use crate::types::{config::Config, LOG_PREFIX}; use super::*; // version info for migration info -const CONTRACT_NAME: &str = "crates.io:cw-xcall-multi"; +const CONTRACT_NAME: &str = "crates.io:cw-xcall"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); impl<'a> CwCallService<'a> { @@ -197,6 +197,17 @@ impl<'a> CwCallService<'a> { }), } } + + pub fn migrate( + &self, + deps: DepsMut, + _env: Env, + _msg: MigrateMsg, + ) -> Result { + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION) + .map_err(ContractError::Std)?; + Ok(Response::default().add_attribute("migrate", "successful")) + } } impl<'a> CwCallService<'a> { diff --git a/contracts/cosmwasm-vm/cw-xcall/src/lib.rs b/contracts/cosmwasm-vm/cw-xcall/src/lib.rs index 4c5fd74d..b8aec24f 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/lib.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/lib.rs @@ -169,6 +169,8 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result Result { - Ok(Response::default().add_attribute("migrate", "successful")) +pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result { + let call_service = CwCallService::default(); + + call_service.migrate(deps, env, msg) } From e0d44928f5b5b26ba97a37dd36dff43cdafdc670 Mon Sep 17 00:00:00 2001 From: sabinchitrakar Date: Thu, 3 Aug 2023 12:02:13 +0545 Subject: [PATCH 2/2] fix: add test --- .../cosmwasm-vm/cw-xcall/src/contract.rs | 29 +++++++++++++++++++ .../cosmwasm-vm/cw-xcall/tests/test_admin.rs | 3 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs index 884bd3d0..09e7ef0f 100644 --- a/contracts/cosmwasm-vm/cw-xcall/src/contract.rs +++ b/contracts/cosmwasm-vm/cw-xcall/src/contract.rs @@ -248,3 +248,32 @@ impl<'a> CwCallService<'a> { Ok(na) } } + +#[cfg(test)] +mod tests { + use cosmwasm_std::testing::{mock_dependencies, mock_env}; + use cw2::{get_contract_version, ContractVersion}; + + use crate::{ + contract::{CONTRACT_NAME, CONTRACT_VERSION}, + state::CwCallService, + MigrateMsg, + }; + + #[test] + fn test_migrate() { + let mut mock_deps = mock_dependencies(); + let env = mock_env(); + + let contract = CwCallService::default(); + let result = contract.migrate(mock_deps.as_mut(), env, MigrateMsg {}); + assert!(result.is_ok()); + let expected = ContractVersion { + contract: CONTRACT_NAME.to_string(), + version: CONTRACT_VERSION.to_string(), + }; + let version = get_contract_version(&mock_deps.storage).unwrap(); + println!("{version:?}"); + assert_eq!(expected, version); + } +} diff --git a/contracts/cosmwasm-vm/cw-xcall/tests/test_admin.rs b/contracts/cosmwasm-vm/cw-xcall/tests/test_admin.rs index 270439d7..4a202ed9 100644 --- a/contracts/cosmwasm-vm/cw-xcall/tests/test_admin.rs +++ b/contracts/cosmwasm-vm/cw-xcall/tests/test_admin.rs @@ -3,7 +3,8 @@ mod setup; use account::*; use cosmwasm_std::{testing::mock_env, Addr}; -use cw_xcall::state::CwCallService; +use cw2::{get_contract_version, ContractVersion}; +use cw_xcall::{state::CwCallService, MigrateMsg}; use cw_xcall_lib::xcall_msg::ExecuteMsg; use setup::test::*;