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 migrate from version #29

Merged
merged 4 commits into from
Oct 16, 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
4 changes: 2 additions & 2 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = ["contracts/*"]

[workspace.package]
version = "1.3.0"
authors = ["Larry Engineer <[email protected]>"]
edition = "2021"
rust-version = "1.69"
Expand Down
2 changes: 1 addition & 1 deletion contracts/delegator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mars-delegator"
description = "Smart contract managing community fund delegation to genesis validators on Mars Hub"
version = { workspace = true }
version = "1.2.0"
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion contracts/vesting/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "mars-vesting"
description = "Smart contract managing token vesting for Mars protocol contributors"
version = { workspace = true }
version = "1.1.0"
authors = { workspace = true }
edition = { workspace = true }
rust-version = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions contracts/vesting/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cw_utils::must_pay;
use crate::{
error::{Error, Result},
helpers::{compute_position_response, compute_withdrawable},
migrations::v1_3_0,
migrations::v1_1_0,
msg::{
Config, ExecuteMsg, Position, PositionResponse, QueryMsg, Schedule, VotingPowerResponse,
},
Expand Down Expand Up @@ -307,5 +307,5 @@ pub fn query_positions(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn migrate(deps: DepsMut, _: Env, _: Empty) -> Result<Response> {
v1_3_0::migrate(deps)
v1_1_0::migrate(deps)
}
2 changes: 1 addition & 1 deletion contracts/vesting/src/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod v1_3_0;
pub mod v1_1_0;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use crate::{
state::CONFIG,
};

const FROM_VERSION: &str = "1.2.0";
const FROM_VERSION: &str = "1.0.0";

pub mod v1_2_0_state {
pub mod v1_0_0_state {
use cosmwasm_std::Addr;
use cw_storage_plus::Item;

Expand All @@ -27,9 +27,9 @@ pub fn migrate(deps: DepsMut) -> Result<Response> {

// CONFIG updated, re-initializing
let cfg = Config {
owner: v1_2_0_state::OWNER.load(deps.storage)?,
denom: v1_2_0_state::VEST_DENOM.into(),
unlock_schedule: v1_2_0_state::UNLOCK_SCHEDULE.load(deps.storage)?,
owner: v1_0_0_state::OWNER.load(deps.storage)?,
denom: v1_0_0_state::VEST_DENOM.into(),
unlock_schedule: v1_0_0_state::UNLOCK_SCHEDULE.load(deps.storage)?,
};

CONFIG.save(deps.storage, &cfg)?;
Expand Down
18 changes: 9 additions & 9 deletions contracts/vesting/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use cw_utils::PaymentError;
use mars_vesting::{
contract::{execute, instantiate, migrate, query},
error::Error,
migrations::v1_3_0::v1_2_0_state,
migrations::v1_1_0::v1_0_0_state,
msg::{
Config, ExecuteMsg, Position, PositionResponse, QueryMsg, Schedule, VotingPowerResponse,
},
Expand Down Expand Up @@ -592,7 +592,7 @@ fn invalid_contract_version() {

let old_contract_version = ContractVersion {
contract: "crates.io:mars-vesting".to_string(),
version: "1.0.0".to_string(),
version: "0.9.0".to_string(),
};

set_contract_version(
Expand All @@ -605,8 +605,8 @@ fn invalid_contract_version() {
let err = migrate(deps.as_mut(), env, Empty {}).unwrap_err();
assert_eq!(
Error::Version(VersionError::WrongVersion {
expected: "1.2.0".to_string(),
found: "1.0.0".to_string()
expected: "1.0.0".to_string(),
found: "0.9.0".to_string()
}),
err
);
Expand All @@ -615,29 +615,29 @@ fn invalid_contract_version() {
#[test]
fn proper_migration() {
let mut deps = mock_dependencies();
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-vesting", "1.2.0").unwrap();
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-vesting", "1.0.0").unwrap();

let old_owner = "spiderman_246";
v1_2_0_state::OWNER.save(deps.as_mut().storage, &Addr::unchecked(old_owner)).unwrap();
v1_0_0_state::OWNER.save(deps.as_mut().storage, &Addr::unchecked(old_owner)).unwrap();

let old_schedule = Schedule {
start_time: 1614600000,
cliff: 31536000,
duration: 126144000,
};
v1_2_0_state::UNLOCK_SCHEDULE.save(deps.as_mut().storage, &old_schedule).unwrap();
v1_0_0_state::UNLOCK_SCHEDULE.save(deps.as_mut().storage, &old_schedule).unwrap();

let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();

assert_eq!(res.messages, vec![]);
assert!(res.data.is_none());
assert_eq!(
res.attributes,
vec![attr("action", "migrate"), attr("from_version", "1.2.0"), attr("to_version", "1.3.0"),]
vec![attr("action", "migrate"), attr("from_version", "1.0.0"), attr("to_version", "1.1.0"),]
);

let config = CONFIG.load(deps.as_ref().storage).unwrap();
assert_eq!(config.denom, v1_2_0_state::VEST_DENOM.to_string());
assert_eq!(config.denom, v1_0_0_state::VEST_DENOM.to_string());
assert_eq!(config.owner.to_string(), old_owner.to_string());
assert_eq!(config.unlock_schedule, old_schedule);
}
2 changes: 1 addition & 1 deletion schemas/mars-delegator/mars-delegator.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "mars-delegator",
"contract_version": "1.3.0",
"contract_version": "1.2.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down
2 changes: 1 addition & 1 deletion schemas/mars-vesting/mars-vesting.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"contract_name": "mars-vesting",
"contract_version": "1.3.0",
"contract_version": "1.1.0",
"idl_version": "1.0.0",
"instantiate": {
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down