Skip to content

Commit

Permalink
Add one test for AbsolutePercentage and abstain, cargo schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey committed Dec 16, 2020
1 parent e574ff7 commit d87e498
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion contracts/cw3-flex-multisig/schema/init_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
},
{
"description": "Declares a percentage of the total weight that must cast yes votes in order for a proposal to pass. As with `AbsoluteCount`, it only matters the sum of yes votes.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters and participation is required. The advantage here is that if the voting set (group) changes between proposals, the number of votes needed is adjusted accordingly.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.\n\nA proposal of this type can pass early as soon as the needed weight of yes votes has been cast.",
"description": "Declares a percentage of the total weight that must cast yes votes in order for a proposal to pass. The percentage is computed over the total weight minus the weight of the abstained votes.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters and participation is required. The advantage here is that if the voting set (group) changes between proposals, the number of votes needed is adjusted accordingly.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.\n\nA proposal of this type can pass early as soon as the needed weight of yes votes has been cast.",
"type": "object",
"required": [
"absolute_percentage"
Expand Down
6 changes: 6 additions & 0 deletions contracts/cw3-flex-multisig/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ mod test {
votes.add_vote(Vote::No, 4);
votes.add_vote(Vote::Abstain, 2);
// same expired or not, if yes >= ceiling(0.5 * (total - abstained))
// 7 of (15-2) passes
assert_eq!(
true,
check_is_passed(percent.clone(), votes.clone(), 15, false)
Expand All @@ -271,6 +272,11 @@ mod test {
true,
check_is_passed(percent.clone(), votes.clone(), 15, true)
);
// but 7 of (17-2) fails
assert_eq!(
false,
check_is_passed(percent.clone(), votes.clone(), 17, false)
);

// if the total were a bit lower, this would pass
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion packages/cw3/schema/proposal_list_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@
}
},
{
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. As with `AbsoluteCount`, Yes votes are the only ones that count.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. The passing weight is computed over the total weight minus the weight of the abstained votes.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"type": "object",
"required": [
"absolute_percentage"
Expand Down
2 changes: 1 addition & 1 deletion packages/cw3/schema/proposal_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
}
},
{
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. As with `AbsoluteCount`, Yes votes are the only ones that count.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. The passing weight is computed over the total weight minus the weight of the abstained votes.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"type": "object",
"required": [
"absolute_percentage"
Expand Down
2 changes: 1 addition & 1 deletion packages/cw3/schema/threshold_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
},
{
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. As with `AbsoluteCount`, Yes votes are the only ones that count.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"description": "Declares a percentage of the total weight that must cast Yes votes, in order for a proposal to pass. The passing weight is computed over the total weight minus the weight of the abstained votes.\n\nThis is useful for similar circumstances as `AbsoluteCount`, where we have a relatively small set of voters, and participation is required. It is understood that if the voting set (group) changes between different proposals that refer to the same group, each proposal will work with a different set of voter weights (the ones snapshotted at proposal creation), and the passing weight for each proposal will be computed based on the absolute percentage, times the total weights of the members at the time of each proposal creation.\n\nExample: we set `percentage` to 51%. Proposal 1 starts when there is a `total_weight` of 5. This will require 3 weight of Yes votes in order to pass. Later, the Proposal 2 starts but the `total_weight` of the group has increased to 9. That proposal will then automatically require 5 Yes of 9 to pass, rather than 3 yes of 9 as would be the case with `AbsoluteCount`.",
"type": "object",
"required": [
"absolute_percentage"
Expand Down

0 comments on commit d87e498

Please sign in to comment.