Skip to content

Commit

Permalink
prepare migrator to v2.1 (#682)
Browse files Browse the repository at this point in the history
* prepare migrator to v2.1

* fix todo
  • Loading branch information
Art3miX authored Mar 27, 2023
1 parent b5d1524 commit b09db5a
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 4 deletions.
96 changes: 96 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ cw20-stake-v1 = { package = "cw20-stake", version = "0.2.6", git = "https://gith
cw20-staked-balance-voting-v1 = { package = "cw20-staked-balance-voting", version = "0.1.0", git = "https://github.com/DA0-DA0/dao-contracts.git", tag = "v1.0.0" }
cw4-voting-v1 = { package = "cw4-voting", version = "0.1.0", git = "https://github.com/DA0-DA0/dao-contracts.git", tag = "v1.0.0" }
voting-v1 = { package = "voting", version = "0.1.0", git = "https://github.com/DA0-DA0/dao-contracts.git", tag = "v1.0.0" }
stake-cw20-v03 = { package = "stake-cw20", version = "0.2.6", git = "https://github.com/DA0-DA0/dao-contracts.git", tag = "v0.3.0" }
2 changes: 0 additions & 2 deletions contracts/external/dao-migrator/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ pub fn reply(deps: DepsMut, env: Env, reply: Reply) -> Result<Response, Contract
}
}

// TODO: Refactor to match queries based on passed version? or leave it like that?
// We can pass the version we want to query to a single function and let the function handle the right call to make.
fn query_state_v1(deps: Deps, module_addrs: ModulesAddrs) -> Result<TestState, ContractError> {
let proposal_counts = query_proposal_count_v1(deps, module_addrs.proposals.clone())?;
let (proposals, sample_proposal_data) = query_proposal_v1(deps, module_addrs.proposals)?;
Expand Down
1 change: 1 addition & 0 deletions contracts/external/dao-migrator/src/testing/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct ModuleAddrs {
pub enum VotingType {
Cw4,
Cw20,
Cw20V03,
}

pub fn get_v1_code_ids(app: &mut App) -> (CodeIds, V1CodeIds) {
Expand Down
28 changes: 26 additions & 2 deletions contracts/external/dao-migrator/src/testing/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::borrow::BorrowMut;
use cosmwasm_std::{to_binary, Addr, WasmMsg};
use cw_multi_test::{next_block, App, AppResponse, Executor};
use dao_interface::{Admin, ModuleInstantiateInfo};
use dao_testing::contracts::stake_cw20_v03_contract;

use crate::{
testing::helpers::get_module_addrs,
Expand All @@ -15,7 +16,7 @@ use super::helpers::{
};

pub fn init_v1(app: &mut App, sender: Addr, voting_type: VotingType) -> (Addr, V1CodeIds) {
let (code_ids, v1_code_ids) = get_v1_code_ids(app);
let (mut code_ids, mut v1_code_ids) = get_v1_code_ids(app);

let (voting_code_id, msg) = match voting_type {
VotingType::Cw4 => (
Expand All @@ -26,6 +27,17 @@ pub fn init_v1(app: &mut App, sender: Addr, voting_type: VotingType) -> (Addr, V
code_ids.cw20_voting,
to_binary(&get_cw20_init_msg(code_ids.clone())).unwrap(),
),
VotingType::Cw20V03 => {
// The simple change we need to do is to swap the cw20_stake with the one in v0.3.0
let v03_cw20_stake = app.store_code(stake_cw20_v03_contract());
code_ids.cw20_stake = v03_cw20_stake;
v1_code_ids.cw20_stake = v03_cw20_stake;

(
code_ids.cw20_voting,
to_binary(&get_cw20_init_msg(code_ids.clone())).unwrap(),
)
}
};

let core_addr = app
Expand Down Expand Up @@ -92,7 +104,7 @@ pub fn init_v1_with_multiple_proposals(
sender: Addr,
voting_type: VotingType,
) -> (Addr, V1CodeIds) {
let (code_ids, v1_code_ids) = get_v1_code_ids(app);
let (mut code_ids, mut v1_code_ids) = get_v1_code_ids(app);

let (voting_code_id, msg) = match voting_type {
VotingType::Cw4 => (
Expand All @@ -103,6 +115,16 @@ pub fn init_v1_with_multiple_proposals(
code_ids.cw20_voting,
to_binary(&get_cw20_init_msg(code_ids.clone())).unwrap(),
),
VotingType::Cw20V03 => {
let v03_cw20_stake = app.store_code(stake_cw20_v03_contract());
code_ids.cw20_stake = v03_cw20_stake;
v1_code_ids.cw20_stake = v03_cw20_stake;

(
code_ids.cw20_voting,
to_binary(&get_cw20_init_msg(code_ids.clone())).unwrap(),
)
}
};

let core_addr = app
Expand Down Expand Up @@ -198,6 +220,8 @@ pub fn setup_dao_v1(voting_type: VotingType) -> (App, ModuleAddrs, V1CodeIds) {
module_addrs.proposals[0].clone(),
),
VotingType::Cw20 => set_cw20_to_dao(app.borrow_mut(), sender, module_addrs.clone()),
// Same as Cw20
VotingType::Cw20V03 => set_cw20_to_dao(app.borrow_mut(), sender, module_addrs.clone()),
};

(app, module_addrs, v1_code_ids)
Expand Down
12 changes: 12 additions & 0 deletions contracts/external/dao-migrator/src/testing/test_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ pub fn basic_test(voting_type: VotingType, from_core: bool) {
module_addrs.proposals[0].clone(),
module_addrs.voting.clone(),
),
VotingType::Cw20V03 => query_state_v1_cw20(
&mut app,
module_addrs.proposals[0].clone(),
module_addrs.voting.clone(),
),
};
//NOTE: We add 1 to count because we create a new proposal in execute_migration
test_state_v1.proposal_count += 1;
Expand All @@ -57,6 +62,11 @@ pub fn basic_test(voting_type: VotingType, from_core: bool) {
module_addrs.proposals[0].clone(),
module_addrs.voting,
),
VotingType::Cw20V03 => query_state_v2_cw20(
&mut app,
module_addrs.proposals[0].clone(),
module_addrs.voting,
),
};

assert_eq!(test_state_v1, test_state_v2);
Expand All @@ -81,10 +91,12 @@ fn test_execute_migration() {
// Test basic migrator (not called from core)
basic_test(VotingType::Cw20, false);
basic_test(VotingType::Cw4, false);
basic_test(VotingType::Cw20V03, false);

// Test basic migrator (called from core)
basic_test(VotingType::Cw20, true);
basic_test(VotingType::Cw4, true);
basic_test(VotingType::Cw20V03, true);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions packages/dao-testing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ dao-voting-cw4 = { workspace = true }
dao-voting-cw721-staked = { workspace = true }
dao-voting-native-staked = { workspace = true }
voting-v1 = { workspace = true }
stake-cw20-v03 = { workspace = true }
9 changes: 9 additions & 0 deletions packages/dao-testing/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,12 @@ pub fn cw_vesting_contract() -> Box<dyn Contract<Empty>> {
);
Box::new(contract)
}

pub fn stake_cw20_v03_contract() -> Box<dyn Contract<Empty>> {
let contract = ContractWrapper::new(
stake_cw20_v03::contract::execute,
stake_cw20_v03::contract::instantiate,
stake_cw20_v03::contract::query,
);
Box::new(contract)
}

0 comments on commit b09db5a

Please sign in to comment.