Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for cw3-fixed-multisig #95

Merged
merged 15 commits into from
Sep 27, 2020
16 changes: 14 additions & 2 deletions contracts/cw3-fixed-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ mod tests {
const VOTER2: &str = "voter0002";
const VOTER3: &str = "voter0003";
const VOTER4: &str = "voter0004";
const VOTER5: &str = "voter0005";
const SOMEBODY: &str = "somebody";

fn voter<T: Into<HumanAddr>>(addr: T, weight: u64) -> Voter {
Expand All @@ -501,6 +502,7 @@ mod tests {
voter(VOTER2, 2),
voter(VOTER3, 3),
voter(VOTER4, 4),
voter(VOTER5, 5),
];

let init_msg = InitMsg {
Expand Down Expand Up @@ -792,7 +794,7 @@ mod tests {

// Vote it again, so it passes
let env = mock_env(VOTER4, &[]);
let res = handle(&mut deps, env, yes_vote).unwrap();
let res = handle(&mut deps, env, yes_vote.clone()).unwrap();

// Verify
assert_eq!(
Expand All @@ -809,7 +811,17 @@ mod tests {
}
);

// TODO: non-Open proposals cannot be voted
// non-Open proposals cannot be voted
// Vote it again
let env = mock_env(VOTER5, &[]);
let res = handle(&mut deps, env, yes_vote);
Copy link
Contributor Author

@maurolacy maurolacy Sep 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After adding this test, I was left wondering that maybe it's a good idea to allow voting on Passed proposals: https://github.com/CosmWasm/cosmwasm-plus/blob/f979892bb7d32339769ad83ccb289e92e5a2f300/contracts/cw3-fixed-multisig/src/contract.rs#L165

That way, we can get better statistics on the final result of a given proposal. That is, despite a proposal having passed, it can have a large number of No / Veto votes (some of which could have been cast after it passed). Or, conversely, a proposal can have a larger adoption than the one reflected by the results; which currently "freeze" after it passes.


// Verify
assert!(res.is_err());
match res.unwrap_err() {
StdError::GenericErr { msg, .. } => assert_eq!(&msg, "Proposal is not open"),
e => panic!("unexpected error: {}", e),
}

// TODO: expired proposals cannot be voted
}
Expand Down