Skip to content

Commit 18e617a

Browse files
authored
MP-2780. Perps migration (#188)
* Update address-provider migration. * Update migration for account-nft. * Update credit-manager migration. * Update health migration. * Update incentives migration. * Update oracle migration. * Update red-bank migration. * Update rewards-collector migration. * Update swapper migration. * Update zapper migration. * Prepare params migration. * Update incentives state migration. * Update how we handle withdraw_enabled for RB.
1 parent b7863cb commit 18e617a

File tree

72 files changed

+818
-1270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+818
-1270
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/account-nft/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ cw-multi-test = { workspace = true }
3535
mars-mock-credit-manager = { workspace = true }
3636
mars-mock-rover-health = { workspace = true }
3737
mars-owner = { workspace = true }
38+
mars-testing = { workspace = true }
3839
serde_json = { workspace = true }

contracts/account-nft/src/contract.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use mars_types::account_nft::{ExecuteMsg, InstantiateMsg, NftConfig, QueryMsg};
1010
use crate::{
1111
error::ContractError,
1212
execute::{burn, mint, update_config},
13+
migrations,
1314
query::{query_config, query_next_id},
1415
state::{CONFIG, NEXT_ID},
1516
};
@@ -79,3 +80,8 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
7980
_ => Parent::default().query(deps, env, msg.try_into()?),
8081
}
8182
}
83+
84+
#[cfg_attr(not(feature = "library"), entry_point)]
85+
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
86+
migrations::v2_2_0::migrate(deps)
87+
}

contracts/account-nft/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod contract;
22
pub mod error;
33
pub mod execute;
4+
pub mod migrations;
45
pub mod query;
56
pub mod state;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod v2_2_0;

contracts/address-provider/src/migrations/v2_0_0.rs renamed to contracts/account-nft/src/migrations/v2_2_0.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
error::ContractError,
77
};
88

9-
const FROM_VERSION: &str = "1.2.0";
9+
const FROM_VERSION: &str = "2.1.0";
1010

1111
pub fn migrate(deps: DepsMut) -> Result<Response, ContractError> {
1212
// make sure we're migrating the correct contract and from the correct version

contracts/account-nft/tests/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ mod helpers;
22

33
mod test_burn_allowance;
44
mod test_instantiate;
5+
mod test_migration_v2;
56
mod test_mint;
67
mod test_proposed_minter;
78
mod test_update_config;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use cosmwasm_std::{attr, testing::mock_env, Empty, Event};
2+
use cw2::{ContractVersion, VersionError};
3+
use mars_account_nft::{contract::migrate, error::ContractError};
4+
use mars_testing::mock_dependencies;
5+
6+
#[test]
7+
fn wrong_contract_name() {
8+
let mut deps = mock_dependencies(&[]);
9+
cw2::set_contract_version(deps.as_mut().storage, "contract_xyz", "2.1.0").unwrap();
10+
11+
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();
12+
13+
assert_eq!(
14+
err,
15+
ContractError::Version(VersionError::WrongContract {
16+
expected: "crates.io:mars-account-nft".to_string(),
17+
found: "contract_xyz".to_string()
18+
})
19+
);
20+
}
21+
22+
#[test]
23+
fn wrong_contract_version() {
24+
let mut deps = mock_dependencies(&[]);
25+
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-account-nft", "4.1.0")
26+
.unwrap();
27+
28+
let err = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap_err();
29+
30+
assert_eq!(
31+
err,
32+
ContractError::Version(VersionError::WrongVersion {
33+
expected: "2.1.0".to_string(),
34+
found: "4.1.0".to_string()
35+
})
36+
);
37+
}
38+
39+
#[test]
40+
fn successful_migration() {
41+
let mut deps = mock_dependencies(&[]);
42+
cw2::set_contract_version(deps.as_mut().storage, "crates.io:mars-account-nft", "2.1.0")
43+
.unwrap();
44+
45+
let res = migrate(deps.as_mut(), mock_env(), Empty {}).unwrap();
46+
47+
assert_eq!(res.messages, vec![]);
48+
assert_eq!(res.events, vec![] as Vec<Event>);
49+
assert!(res.data.is_none());
50+
assert_eq!(
51+
res.attributes,
52+
vec![attr("action", "migrate"), attr("from_version", "2.1.0"), attr("to_version", "2.2.0")]
53+
);
54+
55+
let new_contract_version = ContractVersion {
56+
contract: "crates.io:mars-account-nft".to_string(),
57+
version: "2.2.0".to_string(),
58+
};
59+
assert_eq!(cw2::get_contract_version(deps.as_ref().storage).unwrap(), new_contract_version);
60+
}

contracts/address-provider/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,5 @@ fn query_all_addresses(
173173

174174
#[cfg_attr(not(feature = "library"), entry_point)]
175175
pub fn migrate(deps: DepsMut, _env: Env, _msg: Empty) -> Result<Response, ContractError> {
176-
migrations::v2_0_0::migrate(deps)
176+
migrations::v2_2_0::migrate(deps)
177177
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub mod v2_0_0;
1+
pub mod v2_2_0;

0 commit comments

Comments
 (0)