Skip to content

Commit

Permalink
Get tests sort of working
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake Hartnell committed Aug 30, 2023
1 parent 2ffe8dd commit 57b7e2b
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::testing::{
},
queries::{query_balance_cw20, query_dao_token, query_proposal, query_single_proposal_module},
};
use cosmwasm_std::{to_binary, Addr, CosmosMsg, Decimal, Uint128, WasmMsg};
use cosmwasm_std::{to_binary, Addr, CosmosMsg, Decimal, Timestamp, Uint128, WasmMsg};
use cw20::Cw20Coin;
use cw_multi_test::{next_block, App};
use cw_utils::Duration;
Expand Down Expand Up @@ -139,7 +139,12 @@ fn test_execute_proposal_more_than_once() {

// assert proposal is passed, execute it
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);
execute_proposal(&mut app, &proposal_module, CREATOR_ADDR, proposal_id);

app.update_block(next_block);
Expand All @@ -160,6 +165,7 @@ pub fn test_executed_prop_state_remains_after_vote_swing() {
let mut app = App::default();

let instantiate = InstantiateMsg {
timelock: None,
threshold: AbsolutePercentage {
percentage: PercentageThreshold::Percent(Decimal::percent(15)),
},
Expand Down Expand Up @@ -256,6 +262,7 @@ pub fn test_passed_prop_state_remains_after_vote_swing() {
let mut app = App::default();

let instantiate = InstantiateMsg {
timelock: None,
threshold: AbsolutePercentage {
percentage: PercentageThreshold::Percent(Decimal::percent(15)),
},
Expand Down Expand Up @@ -331,7 +338,12 @@ pub fn test_passed_prop_state_remains_after_vote_swing() {

// assert proposal is passed with 20 votes in favor and none opposed
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);
assert_eq!(proposal.proposal.votes.yes, Uint128::new(20));
assert_eq!(proposal.proposal.votes.no, Uint128::zero());

Expand All @@ -358,7 +370,12 @@ pub fn test_passed_prop_state_remains_after_vote_swing() {
// assert that the late votes have been counted and proposal
// is still in passed state before executing it
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);
assert_eq!(proposal.proposal.votes.yes, Uint128::new(20));
assert_eq!(proposal.proposal.votes.no, Uint128::new(80));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::mem::discriminant;

use cosmwasm_std::{coins, Addr, Uint128};
use cw20::Cw20Coin;

Expand Down Expand Up @@ -121,6 +123,7 @@ where

let max_voting_period = cw_utils::Duration::Height(6);
let instantiate = InstantiateMsg {
timelock: None,
threshold,
max_voting_period,
min_voting_period: None,
Expand Down Expand Up @@ -269,7 +272,11 @@ where
.query_wasm_smart(proposal_single, &QueryMsg::Proposal { proposal_id: 1 })
.unwrap();

assert_eq!(proposal.proposal.status, expected_status);
// We just care about getting the right variant
assert_eq!(
discriminant::<Status>(&proposal.proposal.status),
discriminant::<Status>(&expected_status)
);

(app, core_addr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub(crate) fn get_pre_propose_info(

pub(crate) fn get_default_token_dao_proposal_module_instantiate(app: &mut App) -> InstantiateMsg {
InstantiateMsg {
timelock: None,
threshold: ThresholdQuorum {
quorum: PercentageThreshold::Percent(Decimal::percent(15)),
threshold: PercentageThreshold::Majority {},
Expand All @@ -74,6 +75,7 @@ pub(crate) fn get_default_non_token_dao_proposal_module_instantiate(
app: &mut App,
) -> InstantiateMsg {
InstantiateMsg {
timelock: None,
threshold: ThresholdQuorum {
threshold: PercentageThreshold::Percent(Decimal::percent(15)),
quorum: PercentageThreshold::Majority {},
Expand Down
85 changes: 74 additions & 11 deletions contracts/proposal/dao-proposal-single/src/testing/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use cosmwasm_std::{
coins,
testing::{mock_dependencies, mock_env},
to_binary, Addr, Attribute, BankMsg, Binary, ContractInfoResponse, CosmosMsg, Decimal, Empty,
Reply, StdError, SubMsgResult, Uint128, WasmMsg, WasmQuery,
Reply, StdError, SubMsgResult, Timestamp, Uint128, WasmMsg, WasmQuery,
};
use cw2::ContractVersion;
use cw20::Cw20Coin;
Expand All @@ -25,6 +25,7 @@ use dao_voting::{
},
status::Status,
threshold::{ActiveThreshold, PercentageThreshold, Threshold},
timelock::Timelock,
voting::{Vote, Votes},
};

Expand Down Expand Up @@ -349,7 +350,12 @@ fn test_proposal_message_execution() {
Vote::Yes,
);
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);

// Can't use library function because we expect this to fail due
// to insufficent balance in the bank module.
Expand All @@ -361,7 +367,12 @@ fn test_proposal_message_execution() {
)
.unwrap_err();
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);

mint_natives(&mut app, core_addr.as_str(), coins(10, "ujuno"));
execute_proposal(&mut app, &proposal_module, CREATOR_ADDR, proposal_id);
Expand Down Expand Up @@ -446,7 +457,12 @@ fn test_proposal_cant_close_after_expiry_is_passed() {
// Expire the proposal. This should pass it.
app.update_block(|b| b.time = b.time.plus_seconds(604800));
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1572402219879305533)
}
);

// Make sure it can't be closed.
let err = close_proposal_should_fail(&mut app, &proposal_module, CREATOR_ADDR, proposal_id);
Expand Down Expand Up @@ -579,6 +595,11 @@ fn test_update_config() {
vec![WasmMsg::Execute {
contract_addr: proposal_module.to_string(),
msg: to_binary(&ExecuteMsg::UpdateConfig {
timelock: Some(Timelock {
delay: Timestamp::from_seconds(100),
vetoer: CREATOR_ADDR.to_string(),
early_execute: false,
}),
threshold: Threshold::AbsoluteCount {
threshold: Uint128::new(10_000),
},
Expand Down Expand Up @@ -607,6 +628,11 @@ fn test_update_config() {
assert_eq!(
config,
Config {
timelock: Some(Timelock {
delay: Timestamp::from_seconds(100),
vetoer: CREATOR_ADDR.to_string(),
early_execute: false
}),
threshold: Threshold::AbsoluteCount {
threshold: Uint128::new(10_000)
},
Expand All @@ -625,6 +651,7 @@ fn test_update_config() {
Addr::unchecked(CREATOR_ADDR),
proposal_module,
&&ExecuteMsg::UpdateConfig {
timelock: None,
threshold: Threshold::AbsoluteCount {
threshold: Uint128::new(10_000),
},
Expand Down Expand Up @@ -1052,7 +1079,12 @@ fn test_min_voting_period_no_early_pass() {

app.update_block(|block| block.height += 10);
let proposal_response = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal_response.proposal.status, Status::Passed);
assert_eq!(
proposal_response.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);
}

// Setting the min duration the same as the proposal duration just
Expand Down Expand Up @@ -1090,7 +1122,12 @@ fn test_min_duration_same_as_proposal_duration() {

app.update_block(|b| b.height += 100);
let proposal_response = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal_response.proposal.status, Status::Passed);
assert_eq!(
proposal_response.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);
}

#[test]
Expand Down Expand Up @@ -1149,7 +1186,12 @@ fn test_revoting_playthrough() {
// Expire the proposal allowing the votes to be tallied.
app.update_block(|b| b.time = b.time.plus_seconds(604800));
let proposal_response = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal_response.proposal.status, Status::Passed);
assert_eq!(
proposal_response.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1572402219879305533)
}
);
execute_proposal(&mut app, &proposal_module, CREATOR_ADDR, proposal_id);

// Can't vote once the proposal is passed.
Expand Down Expand Up @@ -1185,6 +1227,7 @@ fn test_allow_revoting_config_changes() {
core_addr.clone(),
proposal_module.clone(),
&ExecuteMsg::UpdateConfig {
timelock: None,
threshold: Threshold::ThresholdQuorum {
quorum: PercentageThreshold::Percent(Decimal::percent(15)),
threshold: PercentageThreshold::Majority {},
Expand Down Expand Up @@ -1221,7 +1264,12 @@ fn test_allow_revoting_config_changes() {

// Proposal without revoting should have passed.
let proposal_resp = query_proposal(&app, &proposal_module, no_revoting_proposal);
assert_eq!(proposal_resp.proposal.status, Status::Passed);
assert_eq!(
proposal_resp.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);

// Proposal with revoting should not have passed.
let proposal_resp = query_proposal(&app, &proposal_module, revoting_proposal);
Expand Down Expand Up @@ -1299,7 +1347,12 @@ fn test_three_of_five_multisig() {
vote_on_proposal(&mut app, &proposal_module, "three", proposal_id, Vote::Yes);

let proposal: ProposalResponse = query_proposal(&app, &proposal_module, 1);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);

execute_proposal(&mut app, &proposal_module, "four", proposal_id);

Expand Down Expand Up @@ -1426,7 +1479,9 @@ fn test_absolute_count_threshold_non_multisig() {
Threshold::AbsoluteCount {
threshold: Uint128::new(11),
},
Status::Passed,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533),
},
None,
);
}
Expand Down Expand Up @@ -1488,6 +1543,7 @@ fn test_proposal_count_initialized_to_zero() {
let core_addr = instantiate_with_staked_balances_governance(
&mut app,
InstantiateMsg {
timelock: None,
threshold: Threshold::ThresholdQuorum {
threshold: PercentageThreshold::Majority {},
quorum: PercentageThreshold::Percent(Decimal::percent(10)),
Expand Down Expand Up @@ -1776,6 +1832,7 @@ fn test_migrate_from_v1() {
assert_eq!(
new_config,
Config {
timelock: None,
threshold: Threshold::AbsolutePercentage {
percentage: PercentageThreshold::Majority {}
},
Expand Down Expand Up @@ -1910,6 +1967,7 @@ fn test_execution_failed() {
core_addr,
proposal_module.clone(),
&ExecuteMsg::UpdateConfig {
timelock: None,
threshold: config.threshold,
max_voting_period: config.max_voting_period,
min_voting_period: config.min_voting_period,
Expand Down Expand Up @@ -1945,7 +2003,12 @@ fn test_execution_failed() {
// Even though this proposal was created before the config change
// was made it still gets retroactively applied.
let proposal = query_proposal(&app, &proposal_module, proposal_id);
assert_eq!(proposal.proposal.status, Status::Passed);
assert_eq!(
proposal.proposal.status,
Status::Passed {
at_time: Timestamp::from_nanos(1571797419879305533)
}
);

// This proposal's deposit should not have been returned. It will
// not be returnable until this is executed, or close on execution
Expand Down
Loading

0 comments on commit 57b7e2b

Please sign in to comment.