Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Feb 1, 2024
1 parent 18baee4 commit 801a8bf
Show file tree
Hide file tree
Showing 9 changed files with 459 additions and 51 deletions.
21 changes: 14 additions & 7 deletions contracts/proposal/dao-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn execute(
proposal_id,
vote,
rationale,
} => execute_vote(deps, env, info, proposal_id, vote, rationale),
} => execute_vote(deps, env, info.sender, proposal_id, vote, rationale),
ExecuteMsg::Execute { proposal_id } => execute_execute(deps, env, info, proposal_id),
ExecuteMsg::Veto { proposal_id } => execute_veto(deps, env, info, proposal_id),
ExecuteMsg::Close { proposal_id } => execute_close(deps, env, info, proposal_id),
Expand Down Expand Up @@ -255,7 +255,14 @@ pub fn execute_propose(

// Auto cast vote if given.
let (vote_hooks, vote_attributes) = if let Some(vote) = vote {
let response = execute_vote(deps, env, info, id, vote.vote, vote.rationale.clone())?;
let response = execute_vote(
deps,
env,
proposer.clone(),
id,
vote.vote,
vote.rationale.clone(),
)?;
(
response.messages,
vec![
Expand Down Expand Up @@ -359,7 +366,7 @@ pub fn execute_veto(
pub fn execute_vote(
deps: DepsMut,
env: Env,
info: MessageInfo,
sender: Addr,
proposal_id: u64,
vote: MultipleChoiceVote,
rationale: Option<String>,
Expand Down Expand Up @@ -387,15 +394,15 @@ pub fn execute_vote(

let vote_power = get_voting_power(
deps.as_ref(),
info.sender.clone(),
sender.clone(),
&config.dao,
Some(prop.start_height),
)?;
if vote_power.is_zero() {
return Err(ContractError::NotRegistered {});
}

BALLOTS.update(deps.storage, (proposal_id, &info.sender), |bal| match bal {
BALLOTS.update(deps.storage, (proposal_id, &sender), |bal| match bal {
Some(current_ballot) => {
if prop.allow_revoting {
if current_ballot.vote == vote {
Expand Down Expand Up @@ -441,14 +448,14 @@ pub fn execute_vote(
VOTE_HOOKS,
deps.storage,
proposal_id,
info.sender.to_string(),
sender.to_string(),
vote.to_string(),
)?;
Ok(Response::default()
.add_submessages(change_hooks)
.add_submessages(vote_hooks)
.add_attribute("action", "vote")
.add_attribute("sender", info.sender)
.add_attribute("sender", sender)
.add_attribute("proposal_id", proposal_id.to_string())
.add_attribute("position", vote.to_string())
.add_attribute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn setup_test(_messages: Vec<CosmosMsg>) -> CommonTest {

let mc_options = MultipleChoiceOptions { options };

let proposal_id = make_proposal(&mut app, &proposal_module, CREATOR_ADDR, mc_options);
let proposal_id = make_proposal(&mut app, &proposal_module, CREATOR_ADDR, mc_options, None);

CommonTest {
app,
Expand Down Expand Up @@ -332,7 +332,7 @@ pub fn test_allow_voting_after_proposal_execution_pre_expiration_cw20() {

let mc_options = MultipleChoiceOptions { options };

let proposal_id = make_proposal(&mut app, &proposal_module, CREATOR_ADDR, mc_options);
let proposal_id = make_proposal(&mut app, &proposal_module, CREATOR_ADDR, mc_options, None);

// assert initial CREATOR_ADDR address balance is 0
let balance = query_balance_cw20(&app, gov_token.to_string(), CREATOR_ADDR);
Expand Down
11 changes: 7 additions & 4 deletions contracts/proposal/dao-proposal-multiple/src/testing/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ use cw_multi_test::{App, Executor};
use cw_denom::CheckedDenom;
use dao_pre_propose_multiple as cppm;
use dao_voting::{
deposit::CheckedDepositInfo, multiple_choice::MultipleChoiceOptions,
pre_propose::ProposalCreationPolicy, proposal::MultipleChoiceProposeMsg as ProposeMsg,
deposit::CheckedDepositInfo,
multiple_choice::{MultipleChoiceAutoVote, MultipleChoiceOptions},
pre_propose::ProposalCreationPolicy,
proposal::MultipleChoiceProposeMsg as ProposeMsg,
};

use crate::{
Expand All @@ -24,6 +26,7 @@ pub fn make_proposal(
proposal_multiple: &Addr,
proposer: &str,
choices: MultipleChoiceOptions,
vote: Option<MultipleChoiceAutoVote>,
) -> u64 {
let proposal_creation_policy = query_creation_policy(app, proposal_multiple);

Expand Down Expand Up @@ -73,7 +76,7 @@ pub fn make_proposal(
description: "description".to_string(),
choices,
proposer: None,
vote: None,
vote,
}),
&[],
)
Expand All @@ -87,7 +90,7 @@ pub fn make_proposal(
title: "title".to_string(),
description: "description".to_string(),
choices,
vote: None,
vote,
},
},
&funds,
Expand Down
Loading

0 comments on commit 801a8bf

Please sign in to comment.