Skip to content

Commit

Permalink
All message logic tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Dec 14, 2020
1 parent 467dffc commit 8ccb6c9
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions contracts/cw3-flex-multisig/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,24 @@ mod tests {
// TODO: test the error messages

// 0 is never a valid percentage
assert!(valid_percentage(&Decimal::zero()).is_err());
let err = valid_percentage(&Decimal::zero()).unwrap_err();
assert_eq!(err.to_string(), ContractError::ZeroThreshold {}.to_string());

// 100% is
valid_percentage(&Decimal::one()).unwrap();

// 101% is not
assert!(valid_percentage(&Decimal::percent(101)).is_err());
let err = valid_percentage(&Decimal::percent(101)).unwrap_err();
assert_eq!(
err.to_string(),
ContractError::UnreachableThreshold {}.to_string()
);
// not 100.1%
assert!(valid_percentage(&Decimal::permille(1001)).is_err());
let err = valid_percentage(&Decimal::permille(1001)).unwrap_err();
assert_eq!(
err.to_string(),
ContractError::UnreachableThreshold {}.to_string()
);

// other values in between 0 and 1 are valid
valid_percentage(&Decimal::permille(1)).unwrap();
Expand Down Expand Up @@ -244,5 +253,42 @@ mod tests {
}

#[test]
fn threshold_response() {}
fn threshold_response() {
let total_weight: u64 = 100;

let res = Threshold::AbsoluteCount { weight_needed: 42 }.to_response(total_weight);
assert_eq!(
res,
ThresholdResponse::AbsoluteCount {
weight_needed: 42,
total_weight
}
);

let res = Threshold::AbsolutePercentage {
percentage_needed: Decimal::percent(51),
}
.to_response(total_weight);
assert_eq!(
res,
ThresholdResponse::AbsolutePercentage {
percentage_needed: Decimal::percent(51),
total_weight
}
);

let res = Threshold::ThresholdQuora {
threshold: Decimal::percent(66),
quroum: Decimal::percent(50),
}
.to_response(total_weight);
assert_eq!(
res,
ThresholdResponse::ThresholdQuora {
threshold: Decimal::percent(66),
quroum: Decimal::percent(50),
total_weight
}
);
}
}

0 comments on commit 8ccb6c9

Please sign in to comment.