Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update version on migrate #15

Merged
merged 2 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
[workspace.package]
authors = ["Icon Foundation<[email protected]>"]
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"]}
Expand Down
3 changes: 2 additions & 1 deletion contracts/cosmwasm-vm/cw-xcall/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "cw-xcall"
version = "0.1.0"
version.workspace = true
authors.workspace = true
edition = "2021"

exclude = [
Expand Down
42 changes: 41 additions & 1 deletion contracts/cosmwasm-vm/cw-xcall/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -197,6 +197,17 @@ impl<'a> CwCallService<'a> {
}),
}
}

pub fn migrate(
&self,
deps: DepsMut,
_env: Env,
_msg: MigrateMsg,
) -> Result<Response, ContractError> {
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)
.map_err(ContractError::Std)?;
Ok(Response::default().add_attribute("migrate", "successful"))
}
}

impl<'a> CwCallService<'a> {
Expand Down Expand Up @@ -237,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);
}
}
6 changes: 4 additions & 2 deletions contracts/cosmwasm-vm/cw-xcall/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@
#[cw_serde]
pub struct MigrateMsg {}
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
Ok(Response::default().add_attribute("migrate", "successful"))
pub fn migrate(deps: DepsMut, env: Env, msg: MigrateMsg) -> Result<Response, ContractError> {
let call_service = CwCallService::default();

call_service.migrate(deps, env, msg)

Check warning on line 175 in contracts/cosmwasm-vm/cw-xcall/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

contracts/cosmwasm-vm/cw-xcall/src/lib.rs#L172-L175

Added lines #L172 - L175 were not covered by tests
}
3 changes: 2 additions & 1 deletion contracts/cosmwasm-vm/cw-xcall/tests/test_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
Loading