Skip to content

Commit

Permalink
Implement PartialEq for cw3-flex-multisig errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maurolacy committed Mar 26, 2021
1 parent 217cab3 commit 009fa34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
44 changes: 20 additions & 24 deletions contracts/cw3-flex-multisig/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,9 @@ mod tests {
&[],
"zero required weight",
);

// Verify
assert_eq!(
res.unwrap_err(),
ContractError::ZeroThreshold {}.to_string()
ContractError::ZeroThreshold {}.to_string(),
res.unwrap_err()
);

// Total weight less than required weight not allowed
Expand All @@ -653,11 +651,9 @@ mod tests {
&[],
"high required weight",
);

// Verify
assert_eq!(
res.unwrap_err(),
ContractError::UnreachableThreshold {}.to_string()
ContractError::UnreachableThreshold {}.to_string(),
res.unwrap_err()
);

// All valid
Expand Down Expand Up @@ -717,7 +713,7 @@ mod tests {
let proposal = pay_somebody_proposal();
// Only voters can propose
let res = app.execute_contract(SOMEBODY, &flex_addr, &proposal, &[]);
assert_eq!(res.unwrap_err(), ContractError::Unauthorized {}.to_string());
assert_eq!(ContractError::Unauthorized {}.to_string(), res.unwrap_err());

// Wrong expiration option fails
let msgs = match proposal.clone() {
Expand All @@ -732,8 +728,8 @@ mod tests {
};
let res = app.execute_contract(OWNER, &flex_addr, &proposal_wrong_exp, &[]);
assert_eq!(
res.unwrap_err(),
ContractError::WrongExpiration {}.to_string()
ContractError::WrongExpiration {}.to_string(),
res.unwrap_err()
);

// Proposal from voter works
Expand Down Expand Up @@ -927,13 +923,13 @@ mod tests {
let err = app
.execute_contract(OWNER, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::AlreadyVoted {}.to_string());
assert_eq!(ContractError::AlreadyVoted {}.to_string(), err);

// Only voters can vote
let err = app
.execute_contract(SOMEBODY, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::Unauthorized {}.to_string());
assert_eq!(ContractError::Unauthorized {}.to_string(), err);

// But voter1 can
let res = app
Expand Down Expand Up @@ -978,14 +974,14 @@ mod tests {
let err = app
.execute_contract(VOTER3, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::AlreadyVoted {}.to_string());
assert_eq!(ContractError::AlreadyVoted {}.to_string(), err);

// Expired proposals cannot be voted
app.update_block(expire(voting_period));
let err = app
.execute_contract(VOTER4, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::Expired {}.to_string());
assert_eq!(ContractError::Expired {}.to_string(), err);
app.update_block(unexpire(voting_period));

// Powerful voter supports it, so it passes
Expand All @@ -1006,7 +1002,7 @@ mod tests {
let err = app
.execute_contract(VOTER5, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::NotOpen {}.to_string());
assert_eq!(ContractError::NotOpen {}.to_string(), err);

// query individual votes
// initial (with 0 weight)
Expand Down Expand Up @@ -1080,7 +1076,7 @@ mod tests {
let err = app
.execute_contract(OWNER, &flex_addr, &execution, &[])
.unwrap_err();
assert_eq!(err, ContractError::WrongExecuteStatus {}.to_string());
assert_eq!(ContractError::WrongExecuteStatus {}.to_string(), err);

// Vote it, so it passes
let vote = HandleMsg::Vote {
Expand All @@ -1105,7 +1101,7 @@ mod tests {
let err = app
.execute_contract(OWNER, &flex_addr, &closing, &[])
.unwrap_err();
assert_eq!(err, ContractError::WrongCloseStatus {}.to_string());
assert_eq!(ContractError::WrongCloseStatus {}.to_string(), err);

// Execute works. Anybody can execute Passed proposals
let res = app
Expand All @@ -1130,7 +1126,7 @@ mod tests {
let err = app
.execute_contract(OWNER, &flex_addr, &closing, &[])
.unwrap_err();
assert_eq!(err, ContractError::WrongCloseStatus {}.to_string());
assert_eq!(ContractError::WrongCloseStatus {}.to_string(), err);
}

#[test]
Expand Down Expand Up @@ -1161,7 +1157,7 @@ mod tests {
let err = app
.execute_contract(SOMEBODY, &flex_addr, &closing, &[])
.unwrap_err();
assert_eq!(err, ContractError::NotExpired {}.to_string());
assert_eq!(ContractError::NotExpired {}.to_string(), err);

// Expired proposals can be closed
app.update_block(expire(voting_period));
Expand All @@ -1182,7 +1178,7 @@ mod tests {
let err = app
.execute_contract(SOMEBODY, &flex_addr, &closing, &[])
.unwrap_err();
assert_eq!(err, ContractError::WrongCloseStatus {}.to_string());
assert_eq!(ContractError::WrongCloseStatus {}.to_string(), err);
}

// uses the power from the beginning of the voting period
Expand Down Expand Up @@ -1291,7 +1287,7 @@ mod tests {
let err = app
.execute_contract(newbie, &flex_addr, &yes_vote, &[])
.unwrap_err();
assert_eq!(err, ContractError::Unauthorized {}.to_string());
assert_eq!(ContractError::Unauthorized {}.to_string(), err);

// previously removed VOTER3 can still vote, passing the proposal
app.execute_contract(VOTER3, &flex_addr, &yes_vote, &[])
Expand Down Expand Up @@ -1407,7 +1403,7 @@ mod tests {
let err = app
.execute_contract(VOTER3, &flex_addr, &cash_proposal, &[])
.unwrap_err();
assert_eq!(err, ContractError::Unauthorized {}.to_string());
assert_eq!(ContractError::Unauthorized {}.to_string(), err);

// extra: ensure no one else can call the hook
let hook_hack = HandleMsg::MemberChangedHook(MemberChangedHookMsg {
Expand All @@ -1416,7 +1412,7 @@ mod tests {
let err = app
.execute_contract(VOTER2, &flex_addr, &hook_hack, &[])
.unwrap_err();
assert_eq!(err, ContractError::Unauthorized {}.to_string());
assert_eq!(ContractError::Unauthorized {}.to_string(), err);
}

// uses the power from the beginning of the voting period
Expand Down
2 changes: 1 addition & 1 deletion contracts/cw3-flex-multisig/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_std::{HumanAddr, StdError};
use thiserror::Error;

#[derive(Error, Debug)]
#[derive(Error, Debug, PartialEq)]
pub enum ContractError {
#[error("{0}")]
Std(#[from] StdError),
Expand Down

0 comments on commit 009fa34

Please sign in to comment.