Skip to content

Commit

Permalink
voting-contract: query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
uint authored and maurolacy committed Jan 12, 2022
1 parent 6689473 commit 1133f73
Show file tree
Hide file tree
Showing 6 changed files with 463 additions and 94 deletions.
26 changes: 2 additions & 24 deletions packages/voting-contract/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
use suite::SuiteBuilder;

use crate::state::RulesBuilder;

mod closing;
mod contracts;
mod early_end;
mod group_change;
mod proposing;
mod queries;
mod suite;
mod voting;

#[test]
fn simple_instantiate() {
let rules = RulesBuilder::new().build();
let mut suite = SuiteBuilder::new().with_rules(rules.clone()).build();

assert_eq!(rules, suite.query_rules().unwrap());
}

#[test]
fn list_voters() {
let mut suite = SuiteBuilder::new()
.with_member("alice", 2)
.with_member("bob", 3)
.with_member("eve", 999)
.build();

let owner = suite.owner.clone();
suite.assert_voters(&[("alice", 2), ("bob", 3), ("eve", 999)]);

suite
.modify_members(owner.as_str(), &[("alice", 7), ("charlie", 1)], &["eve"])
.unwrap();

suite.assert_voters(&[("alice", 7), ("bob", 3), ("charlie", 1)]);
SuiteBuilder::new().build();
}
4 changes: 2 additions & 2 deletions packages/voting-contract/src/multitest/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pub mod voting;

pub use voting::VotingContract;

use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo};
use cw_multi_test::{Contract, ContractWrapper};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use tg_bindings::TgradeMsg;

pub use voting::VotingContract;

pub fn engagement_contract() -> Box<dyn Contract<TgradeMsg>> {
let contract = ContractWrapper::new(
tg4_engagement::contract::execute,
Expand Down
31 changes: 26 additions & 5 deletions packages/voting-contract/src/multitest/contracts/voting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use cosmwasm_std::{from_slice, to_binary};
use cw3::Vote;

use crate::{list_voters, propose, query_proposal, query_rules, query_vote, state::VotingRules};
use crate::{
list_proposals, list_voters, list_votes, propose, query_group_contract, query_proposal,
query_rules, query_vote, query_voter, reverse_proposals, state::VotingRules,
};

use super::*;

Expand Down Expand Up @@ -39,20 +42,20 @@ pub enum QueryMsg {
/// Returns ProposalListResponse
ListProposals {
start_after: Option<u64>,
limit: Option<u32>,
limit: usize,
},
/// Returns ProposalListResponse
ReverseProposals {
start_before: Option<u64>,
limit: Option<u32>,
limit: usize,
},
/// Returns VoteResponse
Vote { proposal_id: u64, voter: String },
/// Returns VoteListResponse
ListVotes {
proposal_id: u64,
start_after: Option<String>,
limit: Option<u32>,
limit: usize,
},
/// Returns VoterResponse
Voter { address: String },
Expand Down Expand Up @@ -113,7 +116,25 @@ impl Contract<TgradeMsg> for VotingContract {
to_binary(&query_proposal::<String>(deps, env, proposal_id)?)
}
Vote { proposal_id, voter } => to_binary(&query_vote(deps, proposal_id, voter)?),
_ => todo!(),
ListProposals { start_after, limit } => {
to_binary(&list_proposals::<String>(deps, env, start_after, limit)?)
}
ReverseProposals {
start_before,
limit,
} => to_binary(&reverse_proposals::<String>(
deps,
env,
start_before,
limit,
)?),
ListVotes {
proposal_id,
start_after,
limit,
} => to_binary(&list_votes(deps, proposal_id, start_after, limit)?),
Voter { address } => to_binary(&query_voter(deps, address)?),
GroupContract {} => to_binary(&query_group_contract(deps)?),
}
.map_err(anyhow::Error::from)
}
Expand Down
Loading

0 comments on commit 1133f73

Please sign in to comment.