Skip to content

Commit

Permalink
Added native voting module proposal deposit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Dec 19, 2023
1 parent 537c2c6 commit 9314a7b
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub fn _instantiate_with_staked_cw721_governance(
core_addr
}

pub fn _instantiate_with_native_staked_balances_governance(
pub fn instantiate_with_native_staked_balances_governance(
app: &mut App,
proposal_module_instantiate: InstantiateMsg,
initial_balances: Option<Vec<Cw20Coin>>,
Expand Down Expand Up @@ -319,7 +319,8 @@ pub fn _instantiate_with_native_staked_balances_governance(
to_address: address.clone(),
amount: vec![Coin {
denom: "ujuno".to_string(),
amount,
// Double the amount so that we can stake half the balance.
amount: amount * Uint128::new(2),
}],
}))
.unwrap();
Expand Down
99 changes: 97 additions & 2 deletions contracts/proposal/dao-proposal-multiple/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use crate::{
do_votes::do_test_votes_cw20_balances,
execute::make_proposal,
instantiate::{
instantiate_with_cw20_balances_governance, instantiate_with_staked_balances_governance,
instantiate_with_staking_active_threshold,
instantiate_with_cw20_balances_governance,
instantiate_with_native_staked_balances_governance,
instantiate_with_staked_balances_governance, instantiate_with_staking_active_threshold,
},
queries::{
query_balance_cw20, query_balance_native, query_cw20_token_staking_contracts,
Expand Down Expand Up @@ -977,6 +978,100 @@ fn test_take_proposal_deposit() {
};
}

#[test]
fn test_take_native_proposal_deposit() {
let mut app = App::default();
let _govmod_id = app.store_code(proposal_multiple_contract());

let quorum = PercentageThreshold::Percent(Decimal::percent(10));
let voting_strategy = VotingStrategy::SingleChoice { quorum };
let max_voting_period = cw_utils::Duration::Height(6);

let instantiate = InstantiateMsg {
min_voting_period: None,
close_proposal_on_execution_failure: true,
max_voting_period,
only_members_execute: false,
allow_revoting: false,
voting_strategy,
pre_propose_info: get_pre_propose_info(
&mut app,
Some(UncheckedDepositInfo {
denom: DepositToken::VotingModuleToken {
token_type: VotingModuleTokenType::Native,
},
amount: Uint128::new(1),
refund_policy: DepositRefundPolicy::OnlyPassed,
}),
false,
),
veto: None,
};

let core_addr = instantiate_with_native_staked_balances_governance(
&mut app,
instantiate,
Some(vec![Cw20Coin {
address: "blue".to_string(),
amount: Uint128::new(2),
}]),
);

let gov_state: dao_interface::query::DumpStateResponse = app
.wrap()
.query_wasm_smart(core_addr, &dao_interface::msg::QueryMsg::DumpState {})
.unwrap();
let governance_modules = gov_state.proposal_modules;

assert_eq!(governance_modules.len(), 1);
let govmod = governance_modules.into_iter().next().unwrap().address;

let options = vec![
MultipleChoiceOption {
description: "multiple choice option 1".to_string(),
msgs: vec![],
title: "title".to_string(),
},
MultipleChoiceOption {
description: "multiple choice option 2".to_string(),
msgs: vec![],
title: "title".to_string(),
},
];

let mc_options = MultipleChoiceOptions { options };

let (deposit_config, pre_propose_module) =
query_deposit_config_and_pre_propose_module(&app, &govmod);
if let CheckedDepositInfo {
denom: CheckedDenom::Native(ref denom),
..
} = deposit_config.deposit_info.unwrap()
{
app.execute_contract(
Addr::unchecked("blue"),
pre_propose_module,
&cppm::ExecuteMsg::Propose {
msg: cppm::ProposeMessage::Propose {
title: "title".to_string(),
description: "description".to_string(),
choices: mc_options.clone(),
},
},
&[],
)
.unwrap_err();

make_proposal(&mut app, &govmod, "blue", mc_options);

// Proposal has been executed so deposit has been refunded.
let balance = query_balance_native(&app, "blue", denom);
assert_eq!(balance, Uint128::new(1));
} else {
panic!()

Check warning on line 1071 in contracts/proposal/dao-proposal-multiple/src/testing/tests.rs

View check run for this annotation

Codecov / codecov/patch

contracts/proposal/dao-proposal-multiple/src/testing/tests.rs#L1071

Added line #L1071 was not covered by tests
};
}

#[test]
fn test_native_proposal_deposit() {
let mut app = App::default();
Expand Down

0 comments on commit 9314a7b

Please sign in to comment.