Skip to content

Commit

Permalink
Use overloading for function names
Browse files Browse the repository at this point in the history
  • Loading branch information
jac18281828 committed Sep 16, 2022
1 parent 9007e9e commit ec84efa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 74 deletions.
52 changes: 26 additions & 26 deletions abi/VoteStrategy.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
}
],
"name": "abstainFromVote",
"name": "abstainFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand All @@ -119,14 +124,9 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
}
],
"name": "abstainWithTokenId",
"name": "abstainFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand All @@ -144,7 +144,7 @@
"type": "uint256[]"
}
],
"name": "abstainWithTokenList",
"name": "abstainFrom",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down Expand Up @@ -219,6 +219,11 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
}
],
"name": "undoVote",
Expand All @@ -232,14 +237,9 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
}
],
"name": "undoWithTokenId",
"name": "undoVote",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down Expand Up @@ -283,7 +283,7 @@
"type": "uint256"
}
],
"name": "voteAgainstWithTokenId",
"name": "voteAgainst",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand All @@ -301,7 +301,7 @@
"type": "uint256[]"
}
],
"name": "voteAgainstWithTokenList",
"name": "voteAgainst",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand All @@ -312,6 +312,11 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
}
],
"name": "voteFor",
Expand All @@ -327,12 +332,12 @@
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_tokenId",
"type": "uint256"
"internalType": "uint256[]",
"name": "_tokenIdList",
"type": "uint256[]"
}
],
"name": "voteForWithTokenId",
"name": "voteFor",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand All @@ -343,14 +348,9 @@
"internalType": "uint256",
"name": "_proposalId",
"type": "uint256"
},
{
"internalType": "uint256[]",
"name": "_tokenIdList",
"type": "uint256[]"
}
],
"name": "voteForWithTokenList",
"name": "voteFor",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
Expand Down
32 changes: 8 additions & 24 deletions contracts/CollectiveGovernance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function voteForWithTokenId(uint256 _proposalId, uint256 _tokenId)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
{
function voteFor(uint256 _proposalId, uint256 _tokenId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
uint256 count = _storage.voteForByShare(_proposalId, msg.sender, _tokenId);
if (count > 0) {
emit VoteTally(_proposalId, msg.sender, count);
Expand All @@ -186,7 +182,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function voteForWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList)
function voteFor(uint256 _proposalId, uint256[] memory _tokenIdList)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
Expand Down Expand Up @@ -217,11 +213,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function undoWithTokenId(uint256 _proposalId, uint256 _tokenId)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
{
function undoVote(uint256 _proposalId, uint256 _tokenId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
uint256 count = _storage.undoVoteById(_proposalId, msg.sender, _tokenId);
if (count > 0) {
emit VoteUndo(_proposalId, msg.sender, count);
Expand All @@ -244,11 +236,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function voteAgainstWithTokenId(uint256 _proposalId, uint256 _tokenId)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
{
function voteAgainst(uint256 _proposalId, uint256 _tokenId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
uint256 count = _storage.voteAgainstByShare(_proposalId, msg.sender, _tokenId);
if (count > 0) {
emit VoteTally(_proposalId, msg.sender, count);
Expand All @@ -257,7 +245,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function voteAgainstWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList)
function voteAgainst(uint256 _proposalId, uint256[] memory _tokenIdList)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
Expand All @@ -273,7 +261,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function abstainFromVote(uint256 _proposalId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
function abstainFrom(uint256 _proposalId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
uint256[] memory _shareList = _voterClass.discover(msg.sender);
uint256 count = 0;
for (uint256 i = 0; i < _shareList.length; i++) {
Expand All @@ -287,11 +275,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function abstainWithTokenId(uint256 _proposalId, uint256 _tokenId)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
{
function abstainFrom(uint256 _proposalId, uint256 _tokenId) external requireVoteOpen(_proposalId) requireNoVeto(_proposalId) {
uint256 count = _storage.abstainForShare(_proposalId, msg.sender, _tokenId);
if (count > 0) {
emit AbstentionTally(_proposalId, msg.sender, count);
Expand All @@ -300,7 +284,7 @@ contract CollectiveGovernance is Governance, VoteStrategy, ERC165 {
}
}

function abstainWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList)
function abstainFrom(uint256 _proposalId, uint256[] memory _tokenIdList)
external
requireVoteOpen(_proposalId)
requireNoVeto(_proposalId)
Expand Down
16 changes: 8 additions & 8 deletions contracts/VoteStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,25 @@ interface VoteStrategy {

function voteFor(uint256 _proposalId) external;

function voteForWithTokenId(uint256 _proposalId, uint256 _tokenId) external;
function voteFor(uint256 _proposalId, uint256 _tokenId) external;

function voteForWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList) external;
function voteFor(uint256 _proposalId, uint256[] memory _tokenIdList) external;

function voteAgainst(uint256 _proposalId) external;

function voteAgainstWithTokenId(uint256 _proposalId, uint256 _tokenId) external;
function voteAgainst(uint256 _proposalId, uint256 _tokenId) external;

function voteAgainstWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList) external;
function voteAgainst(uint256 _proposalId, uint256[] memory _tokenIdList) external;

function abstainFromVote(uint256 _proposalId) external;
function abstainFrom(uint256 _proposalId) external;

function abstainWithTokenId(uint256 _proposalId, uint256 _tokenId) external;
function abstainFrom(uint256 _proposalId, uint256 _tokenId) external;

function abstainWithTokenList(uint256 _proposalId, uint256[] memory _tokenIdList) external;
function abstainFrom(uint256 _proposalId, uint256[] memory _tokenIdList) external;

function undoVote(uint256 _proposalId) external;

function undoWithTokenId(uint256 _proposalId, uint256 _tokenId) external;
function undoVote(uint256 _proposalId, uint256 _tokenId) external;

function veto(uint256 _proposalId) external;

Expand Down
32 changes: 16 additions & 16 deletions test/CollectiveGovernance.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
assertEq(_storage.forVotes(PROPOSAL_ID), 1);
}

Expand All @@ -108,7 +108,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
assertEq(_storage.forVotes(PROPOSAL_ID), 1);
}

Expand All @@ -118,7 +118,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteForWithTokenList(PROPOSAL_ID, _tokenIdList);
governance.voteFor(PROPOSAL_ID, _tokenIdList);
assertEq(_storage.forVotes(PROPOSAL_ID), 3);
}

Expand All @@ -128,7 +128,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteAgainstWithTokenList(PROPOSAL_ID, _tokenIdList);
governance.voteAgainst(PROPOSAL_ID, _tokenIdList);
assertEq(_storage.againstVotes(PROPOSAL_ID), 3);
}

Expand All @@ -138,7 +138,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.abstainWithTokenList(PROPOSAL_ID, _tokenIdList);
governance.abstainFrom(PROPOSAL_ID, _tokenIdList);
assertEq(_storage.abstentionCount(PROPOSAL_ID), 3);
}

Expand All @@ -149,7 +149,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.prank(_VOTER1);
vm.roll(block.number + 2);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
assertEq(_storage.forVotes(PROPOSAL_ID), 1);
}

Expand All @@ -160,7 +160,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.expectRevert("Not owner");
vm.prank(_NOT_VOTER);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
}

function testVoteAgainst() public {
Expand All @@ -169,7 +169,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteAgainstWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteAgainst(PROPOSAL_ID, TOKEN_ID1);
assertEq(_storage.againstVotes(PROPOSAL_ID), 1);
}

Expand All @@ -180,7 +180,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.expectRevert("Not owner");
vm.prank(_NOT_VOTER);
governance.voteAgainstWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteAgainst(PROPOSAL_ID, TOKEN_ID1);
}

function testAbstain() public {
Expand All @@ -189,7 +189,7 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.abstainWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.abstainFrom(PROPOSAL_ID, TOKEN_ID1);
assertEq(_storage.abstentionCount(PROPOSAL_ID), 1);
}

Expand All @@ -200,7 +200,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.prank(_NOT_VOTER);
vm.expectRevert("Not owner");
governance.abstainWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.abstainFrom(PROPOSAL_ID, TOKEN_ID1);
}

function testOpenVote() public {
Expand Down Expand Up @@ -361,12 +361,12 @@ contract CollectiveGovernanceTest is Test {
governance.openVote(PROPOSAL_ID);
vm.stopPrank();
vm.prank(_VOTER1);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
vm.prank(_VOTER1);
_erc721.transferFrom(_VOTER1, _VOTER2, TOKEN_ID1);
vm.expectRevert("Already voted");
vm.prank(_VOTER2);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
}

function testUndoRequiresOpen() public {
Expand Down Expand Up @@ -410,12 +410,12 @@ contract CollectiveGovernanceTest is Test {
vm.prank(_OWNER);
governance.openVote(PROPOSAL_ID);
vm.prank(_VOTER1);
governance.voteForWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.voteFor(PROPOSAL_ID, TOKEN_ID1);
vm.prank(_VOTER1);
_erc721.transferFrom(_VOTER1, _VOTER2, TOKEN_ID1);
vm.expectRevert("Not voter");
vm.prank(_VOTER2);
governance.undoWithTokenId(PROPOSAL_ID, TOKEN_ID1);
governance.undoVote(PROPOSAL_ID, TOKEN_ID1);
}

function testUndoVoteNotDefaultEnabled() public {
Expand Down Expand Up @@ -701,7 +701,7 @@ contract CollectiveGovernanceTest is Test {
vm.stopPrank();
vm.expectRevert("Voting is closed");
vm.prank(_VOTER1);
governance.abstainFromVote(PROPOSAL_ID);
governance.abstainFrom(PROPOSAL_ID);
}

function testVoteDelayPreventsVote(uint256 blockStep) public {
Expand Down

0 comments on commit ec84efa

Please sign in to comment.