Skip to content

Commit

Permalink
fix: remove multiple voting for testing
Browse files Browse the repository at this point in the history
Signed-off-by: 0xRaccoon <[email protected]>
  • Loading branch information
0xRaccoon authored Jan 12, 2024
1 parent 72a1677 commit 34523e9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
17 changes: 10 additions & 7 deletions solidity/examples/AliceGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ contract AliceGovernor is WonderGovernor {
}

struct ProposalTrack {
uint256 proposalId;
uint256 votes;
uint256 forVotes;
uint256 againstVotes;
uint256 abstainVotes;
}

error AliceGovernorAccountAlreadyVoted(uint256 proposalId, address account);

constructor(address _wonderToken) WonderGovernor('AliceGovernor') {
votes = WonderVotes(_wonderToken);
}
Expand Down Expand Up @@ -85,6 +86,14 @@ contract AliceGovernor is WonderGovernor {
uint256 _weight,
bytes memory _params
) internal virtual override {
if (receipts[_proposalId][_account].hasVoted) revert AliceGovernorAccountAlreadyVoted(_proposalId, _account);

BallotReceipt storage _receipt = receipts[_proposalId][_account];

_receipt.hasVoted = true;
_receipt.support = _support;
_receipt.votes = _weight;

proposalTracks[_proposalId].votes += _weight;
if (_support == 0) {
proposalTracks[_proposalId].againstVotes += _weight;
Expand All @@ -95,12 +104,6 @@ contract AliceGovernor is WonderGovernor {
} else {
revert InvalidVoteType(_support);
}

BallotReceipt storage _receipt = receipts[_proposalId][_account];

_receipt.hasVoted = true;
_receipt.support = _support;
_receipt.votes = _weight;
}

function hasVoted(uint256 _proposalId, address _account) external view override returns (bool) {
Expand Down
8 changes: 4 additions & 4 deletions solidity/test/integration/Propose.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ contract Integration_Propose is IntegrationBase {

_vote(_proposalId, _forVoters, _againstVoters);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_forVotes, INITIAL_VOTERS_BALANCE * _forVoters);
Expand All @@ -73,7 +73,7 @@ contract Integration_Propose is IntegrationBase {

_vote(_proposalId, _forVoters, _againstVoters);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_forVotes, INITIAL_VOTERS_BALANCE * _forVoters);
Expand All @@ -97,7 +97,7 @@ contract Integration_Propose is IntegrationBase {

_vote(_proposalId, _forVoters, _againstVoters);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_forVotes, INITIAL_VOTERS_BALANCE * _forVoters);
Expand All @@ -122,7 +122,7 @@ contract Integration_Propose is IntegrationBase {

_vote(_proposalId, _forVoters, _againstVoters);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_forVotes, INITIAL_VOTERS_BALANCE * _forVoters);
Expand Down
18 changes: 9 additions & 9 deletions solidity/test/unit/WonderGovernor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ contract Unit_CastVote is BaseTest {
vm.prank(cat);
governor.castVote(_proposalId, 1);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -396,7 +396,7 @@ contract Unit_CastVote is BaseTest {
vm.prank(cat);
governor.castVote(_proposalId, 0);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -428,7 +428,7 @@ contract Unit_CastVote is BaseTest {
vm.prank(cat);
governor.castVote(_proposalId, 2);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -526,7 +526,7 @@ contract Unit_CastVoteWithReason is BaseTest {
vm.prank(cat);
governor.castVoteWithReason(_proposalId, 1, _reason);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -559,7 +559,7 @@ contract Unit_CastVoteWithReason is BaseTest {
vm.prank(cat);
governor.castVoteWithReason(_proposalId, 0, _reason);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -592,7 +592,7 @@ contract Unit_CastVoteWithReason is BaseTest {
vm.prank(cat);
governor.castVoteWithReason(_proposalId, 2, _reason);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -697,7 +697,7 @@ contract Unit_CastVoteWithReasonAndParams is BaseTest {
vm.prank(cat);
governor.castVoteWithReasonAndParams(_proposalId, 1, _reason, _params);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -732,7 +732,7 @@ contract Unit_CastVoteWithReasonAndParams is BaseTest {
vm.prank(cat);
governor.castVoteWithReasonAndParams(_proposalId, 0, _reason, _params);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down Expand Up @@ -767,7 +767,7 @@ contract Unit_CastVoteWithReasonAndParams is BaseTest {
vm.prank(cat);
governor.castVoteWithReasonAndParams(_proposalId, 2, _reason, _params);

(uint256 _id, uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
(uint256 _votes, uint256 _forVotes, uint256 _againstVotes, uint256 _abstainVotes) =
AliceGovernor(payable(address(governor))).proposalTracks(_proposalId);

assertEq(_votes, _voterVotes);
Expand Down

0 comments on commit 34523e9

Please sign in to comment.