Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/address-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mars-address-provider"
description = "A smart contract that holds addresses of Mars Red Bank contracts"
version = { workspace = true }
version = "2.1.1"
authors = { workspace = true }
edition = { workspace = true }
license = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/address-provider/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ fn query_all_addresses(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
migrations::v2_1_0::migrate(deps)
migrations::v2_1_1::migrate(deps)
}
1 change: 1 addition & 0 deletions contracts/address-provider/src/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod v2_1_0;
pub mod v2_1_1;
22 changes: 22 additions & 0 deletions contracts/address-provider/src/migrations/v2_1_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cosmwasm_std::{DepsMut, Response};
use cw2::{assert_contract_version, set_contract_version};

use crate::{
contract::{CONTRACT_NAME, CONTRACT_VERSION},
error::ContractError,
};

const FROM_VERSION: &str = "2.1.0";

pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
// 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)?;

// add new address
set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?;

Ok(Response::new()
.add_attribute("action", "migrate")
.add_attribute("from_version", FROM_VERSION)
.add_attribute("to_version", CONTRACT_VERSION))
}
10 changes: 5 additions & 5 deletions contracts/address-provider/tests/tests/test_migration_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use mars_testing::mock_dependencies;
#[test]
fn wrong_contract_name() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.0.0").unwrap();
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.1.0").unwrap();

let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();

Expand All @@ -30,7 +30,7 @@ fn wrong_contract_version() {
assert_eq!(
err,
ContractError::Version(VersionError::WrongVersion {
expected: "2.0.0".to_string(),
expected: "2.1.0".to_string(),
found: "4.1.0".to_string()
})
);
Expand All @@ -39,7 +39,7 @@ fn wrong_contract_version() {
#[test]
fn successful_migration() {
let mut deps = mock_dependencies(&[]);
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-address-provider", "2.0.0")
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-address-provider", "2.1.0")
.unwrap();

let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();
Expand All @@ -49,12 +49,12 @@ fn successful_migration() {
assert!(res.data.is_none());
assert_eq!(
res.attributes,
vec![attr("action", "migrate"), attr("from_version", "2.0.0"), attr("to_version", "2.1.0")]
vec![attr("action", "migrate"), attr("from_version", "2.1.0"), attr("to_version", "2.1.1")]
);

let new_contract_version = ContractVersion {
contract: "crates.io:mars-address-provider".to_string(),
version: "2.1.0".to_string(),
version: "2.1.1".to_string(),
};
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
}
Loading
Loading