Skip to content

Commit

Permalink
integration test the migration
Browse files Browse the repository at this point in the history
  • Loading branch information
iboss-ptk committed Oct 7, 2024
1 parent 0aecd61 commit c7847db
Showing 1 changed file with 139 additions and 2 deletions.
141 changes: 139 additions & 2 deletions contracts/transmuter/src/test/cases/units/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{iter, path::PathBuf};
use std::{collections::BTreeMap, iter, path::PathBuf};

use crate::{
asset::AssetConfig,
contract::{
sv::{InstantiateMsg, QueryMsg},
GetModeratorResponse, ListAssetConfigsResponse,
GetModeratorResponse, ListAssetConfigsResponse, ListAssetGroupsResponse,
},
migrations::v4_0_0::MigrateMsg,
test::{modules::cosmwasm_pool::CosmwasmPool, test_env::TransmuterContract},
Expand Down Expand Up @@ -276,6 +276,143 @@ fn test_migrate_v3_2(#[case] from_version: &str) {
);
}

#[test]
fn test_migrate_v4_0_0() {
let from_version = "v3_2";
// --- setup account ---
let app = OsmosisTestApp::new();
let signer = app
.init_account(&[
Coin::new(100000, "denom1"),
Coin::new(100000, "denom2"),
Coin::new(10000000000000, "uosmo"),
])
.unwrap();

// --- create pool ----

let cp = CosmwasmPool::new(&app);
let gov = GovWithAppAccess::new(&app);
gov.propose_and_execute(
UploadCosmWasmPoolCodeAndWhiteListProposal::TYPE_URL.to_string(),
UploadCosmWasmPoolCodeAndWhiteListProposal {
title: String::from("store test cosmwasm pool code"),
description: String::from("test"),
wasm_byte_code: get_prev_version_of_wasm_byte_code(from_version),
},
signer.address(),
&signer,
)
.unwrap();

let instantiate_msg = InstantiateMsg {
pool_asset_configs: vec![
AssetConfig {
denom: "denom1".to_string(),
normalization_factor: Uint128::new(1),
},
AssetConfig {
denom: "denom2".to_string(),
normalization_factor: Uint128::new(10000),
},
],
alloyed_asset_subdenom: "denomx".to_string(),
alloyed_asset_normalization_factor: Uint128::new(10),
admin: Some(signer.address()),
moderator: signer.address(),
};

let code_id = 1;
let res = cp
.create_cosmwasm_pool(
MsgCreateCosmWasmPool {
code_id,
instantiate_msg: to_json_binary(&instantiate_msg).unwrap().to_vec(),
sender: signer.address(),
},
&signer,
)
.unwrap();

let pool_id = res.data.pool_id;

let ContractInfoByPoolIdResponse {
contract_address,
code_id: _,
} = cp
.contract_info_by_pool_id(&ContractInfoByPoolIdRequest { pool_id })
.unwrap();

let t = TransmuterContract::new(&app, code_id, pool_id, contract_address.clone());

// --- migrate pool ---
let migrate_msg = MigrateMsg {};

gov.propose_and_execute(
MigratePoolContractsProposal::TYPE_URL.to_string(),
MigratePoolContractsProposal {
title: "migrate cosmwasmpool".to_string(),
description: "test migration".to_string(),
pool_ids: vec![pool_id],
new_code_id: 0, // upload new code, so set this to 0
wasm_byte_code: TransmuterContract::get_wasm_byte_code(),
migrate_msg: to_json_binary(&migrate_msg).unwrap().to_vec(),
},
signer.address(),
&signer,
)
.unwrap();

let alloyed_denom = format!("factory/{contract_address}/alloyed/denomx");

let expected_asset_configs = instantiate_msg
.pool_asset_configs
.into_iter()
.chain(iter::once(AssetConfig {
denom: alloyed_denom,
normalization_factor: instantiate_msg.alloyed_asset_normalization_factor,
}))
.collect::<Vec<_>>();

// list asset configs
let ListAssetConfigsResponse { asset_configs } =
t.query(&QueryMsg::ListAssetConfigs {}).unwrap();

// expect no changes in asset config
assert_eq!(asset_configs, expected_asset_configs);

let res: QueryRawContractStateResponse = app
.query(
"/cosmwasm.wasm.v1.Query/RawContractState",
&QueryRawContractStateRequest {
address: t.contract_addr.clone(),
query_data: b"contract_info".to_vec(),
},
)
.unwrap();

let version: cw2::ContractVersion = from_json(res.data).unwrap();

assert_eq!(
version,
cw2::ContractVersion {
contract: "crates.io:transmuter".to_string(),
version: "4.0.0".to_string()
}
);

// asset configs should be the same
let ListAssetConfigsResponse { asset_configs } =
t.query(&QueryMsg::ListAssetConfigs {}).unwrap();

assert_eq!(asset_configs, expected_asset_configs);

// list asset groups
let ListAssetGroupsResponse { asset_groups } = t.query(&QueryMsg::ListAssetGroups {}).unwrap();

assert_eq!(asset_groups, BTreeMap::new());
}

fn get_prev_version_of_wasm_byte_code(version: &str) -> Vec<u8> {
let manifest_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let wasm_path = manifest_path
Expand Down

0 comments on commit c7847db

Please sign in to comment.