diff --git a/solidity/examples/AliceGovernor.sol b/solidity/examples/AliceGovernor.sol index e8e1691..8ad69a2 100644 --- a/solidity/examples/AliceGovernor.sol +++ b/solidity/examples/AliceGovernor.sol @@ -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); } @@ -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; @@ -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) { diff --git a/solidity/test/integration/Propose.t.sol b/solidity/test/integration/Propose.t.sol index 1645691..0d330fe 100644 --- a/solidity/test/integration/Propose.t.sol +++ b/solidity/test/integration/Propose.t.sol @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/solidity/test/unit/WonderGovernor.t.sol b/solidity/test/unit/WonderGovernor.t.sol index a5badb0..bea899c 100644 --- a/solidity/test/unit/WonderGovernor.t.sol +++ b/solidity/test/unit/WonderGovernor.t.sol @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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);