Skip to content

Commit 1b15ff2

Browse files
ben-kaufmanOren Sokolowsky
and
Oren Sokolowsky
authored
Use buidler (#807)
* Use buidler * Fix coverall * Update .solcover.js * remove timeout * Update .solcover.js * hardhat * travis * coverage * coverage * reputation from token test * coverage * release.sh Co-authored-by: Oren Sokolowsky <[email protected]>
1 parent d0678a3 commit 1b15ff2

30 files changed

+18062
-6304
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ coverage.json
1212
.covera*
1313
cache/
1414
yarn*
15+
16+
node_modules
17+
18+
#Hardhat files
19+
cache
20+
artifacts

.solcover.js

+108-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,112 @@ module.exports = {
22
mocha: {
33
enableTimeouts: false,
44
grep: "@skip-on-coverage", // Find everything with this tag
5-
invert: true // Run the grep's inverse set.
5+
invert: true, // Run the grep's inverse set.
6+
timeout: 100000,
67
},
7-
skipFiles: ['test/']
8-
}
8+
skipFiles: ['test/'],
9+
providerOptions: {
10+
accounts: [
11+
{
12+
secretKey:
13+
"0xc5e8f61d1ab959b397eecc0a37a6517b8e67a0e7cf1f4bce5591f3ed80199122",
14+
balance: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
15+
},
16+
{
17+
secretKey:
18+
"0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
19+
balance: "10000000000000000000000"
20+
},
21+
{
22+
secretKey:
23+
"0x23c601ae397441f3ef6f1075dcb0031ff17fb079837beadaf3c84d96c6f3e569",
24+
balance: "10000000000000000000000"
25+
},
26+
{
27+
secretKey:
28+
"0xee9d129c1997549ee09c0757af5939b2483d80ad649a0eda68e8b0357ad11131",
29+
balance: "10000000000000000000000"
30+
},
31+
{
32+
secretKey:
33+
"0x87630b2d1de0fbd5044eb6891b3d9d98c34c8d310c852f98550ba774480e47cc",
34+
balance: "10000000000000000000000"
35+
},
36+
{
37+
secretKey:
38+
"0x275cc4a2bfd4f612625204a20a2280ab53a6da2d14860c47a9f5affe58ad86d4",
39+
balance: "10000000000000000000000"
40+
},
41+
{
42+
secretKey:
43+
"0x7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff",
44+
balance: "10000000000000000000000"
45+
},
46+
{
47+
secretKey:
48+
"0x2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60",
49+
balance: "10000000000000000000000"
50+
},
51+
{
52+
secretKey:
53+
"0x8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e",
54+
balance: "10000000000000000000000"
55+
},
56+
{
57+
secretKey:
58+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29085",
59+
balance: "10000000000000000000000"
60+
},
61+
{
62+
secretKey:
63+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29086",
64+
balance: "10000000000000000000000"
65+
},
66+
{
67+
secretKey:
68+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087",
69+
balance: "10000000000000000000000"
70+
},
71+
{
72+
secretKey:
73+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088",
74+
balance: "10000000000000000000000"
75+
},
76+
{
77+
secretKey:
78+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089",
79+
balance: "10000000000000000000000"
80+
},
81+
{
82+
secretKey:
83+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908a",
84+
balance: "10000000000000000000000"
85+
},
86+
{
87+
secretKey:
88+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908b",
89+
balance: "10000000000000000000000"
90+
},
91+
{
92+
secretKey:
93+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908c",
94+
balance: "10000000000000000000000"
95+
},
96+
{
97+
secretKey:
98+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908d",
99+
balance: "10000000000000000000000"
100+
},
101+
{
102+
secretKey:
103+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908e",
104+
balance: "10000000000000000000000"
105+
},
106+
{
107+
secretKey:
108+
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908f",
109+
balance: "10000000000000000000000"
110+
}
111+
]
112+
}
113+
};

.travis.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ dist: trusty
33
language: node_js
44

55
node_js:
6-
- "12.19.0"
6+
- "14.5.0"
77

88
before_install:
99

1010
install:
11-
- npm ci
11+
- rm -rf node_modules/ # remove any remaining artifacts from a previous build
12+
- npm i
1213
- rm -rf build/ # remove any remaining artifacts from a previous build
13-
- truffle version
14+
- npx hardhat --version
15+
- npx hardhat clean
1416

1517
jobs:
1618
include:
1719
- stage: tests
1820
name: "Unit tests"
19-
script: npm run test
21+
script: npx hardhat test
2022

2123
- stage: tests
2224
name: "Solidity Lint"
23-
script: npm run solhint
25+
script: npx hardhat check
2426

2527
- stage: tests
2628
name: "JS Lint"
27-
script: npm run lint
29+
script: npx eslint .
2830

2931
- stage: coverage
3032
name: "Solidity Test Coverage"

contracts/Migrations.sol

-26
This file was deleted.

contracts/universalSchemes/ContributionReward.sol

+18-12
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import "../votingMachines/VotingMachineCallbacks.sol";
1111
* @dev An agent can ask an organization to recognize a contribution and reward
1212
* him with token, reputation, ether or any combination.
1313
*/
14-
1514
contract ContributionReward is UniversalScheme, VotingMachineCallbacks, ProposalExecuteInterface {
1615
using SafeMath for uint;
1716

@@ -82,8 +81,10 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
8281
*/
8382
function executeProposal(bytes32 _proposalId, int256 _param) external onlyVotingMachine(_proposalId) returns(bool) {
8483
ProposalInfo memory proposal = proposalsInfo[msg.sender][_proposalId];
85-
require(organizationsProposals[address(proposal.avatar)][_proposalId].executionTime == 0);
86-
require(organizationsProposals[address(proposal.avatar)][_proposalId].beneficiary != address(0));
84+
require(organizationsProposals[address(proposal.avatar)][_proposalId].executionTime == 0,
85+
"cannot execute twice");
86+
require(organizationsProposals[address(proposal.avatar)][_proposalId].beneficiary != address(0),
87+
"proposal must exist");
8788
// Check if vote was successful:
8889
if (_param == 1) {
8990
// solhint-disable-next-line not-rely-on-time
@@ -192,7 +193,7 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
192193

193194
ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
194195
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
195-
require(proposal.executionTime != 0);
196+
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
196197
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 0);
197198

198199
//set proposal reward to zero to prevent reentrancy attack.
@@ -201,11 +202,13 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
201202
if (reputation > 0) {
202203
require(
203204
Controller(
204-
_avatar.owner()).mintReputation(uint(reputation), _proposal.beneficiary, address(_avatar)));
205+
_avatar.owner()).mintReputation(uint(reputation), _proposal.beneficiary, address(_avatar)),
206+
"failed to mint reputation");
205207
} else if (reputation < 0) {
206208
require(
207209
Controller(
208-
_avatar.owner()).burnReputation(uint(reputation*(-1)), _proposal.beneficiary, address(_avatar)));
210+
_avatar.owner()).burnReputation(uint(reputation*(-1)), _proposal.beneficiary, address(_avatar)),
211+
"failed to burn reputation");
209212
}
210213
if (reputation != 0) {
211214
proposal.redeemedPeriods[0] = proposal.redeemedPeriods[0].add(periodsToPay);
@@ -225,14 +228,15 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
225228

226229
ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
227230
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
228-
require(proposal.executionTime != 0);
231+
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
229232
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 1);
230233
//set proposal rewards to zero to prevent reentrancy attack.
231234
proposal.nativeTokenReward = 0;
232235

233236
amount = periodsToPay.mul(_proposal.nativeTokenReward);
234237
if (amount > 0) {
235-
require(Controller(_avatar.owner()).mintTokens(amount, _proposal.beneficiary, address(_avatar)));
238+
require(Controller(_avatar.owner()).mintTokens(amount, _proposal.beneficiary, address(_avatar)),
239+
"failed to mint tokens");
236240
proposal.redeemedPeriods[1] = proposal.redeemedPeriods[1].add(periodsToPay);
237241
emit RedeemNativeToken(address(_avatar), _proposalId, _proposal.beneficiary, amount);
238242
}
@@ -251,14 +255,15 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
251255

252256
ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
253257
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
254-
require(proposal.executionTime != 0);
258+
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
255259
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 2);
256260
//set proposal rewards to zero to prevent reentrancy attack.
257261
proposal.ethReward = 0;
258262
amount = periodsToPay.mul(_proposal.ethReward);
259263

260264
if (amount > 0) {
261-
require(Controller(_avatar.owner()).sendEther(amount, _proposal.beneficiary, _avatar));
265+
require(Controller(_avatar.owner()).sendEther(amount, _proposal.beneficiary, _avatar),
266+
"failed to send ether");
262267
proposal.redeemedPeriods[2] = proposal.redeemedPeriods[2].add(periodsToPay);
263268
emit RedeemEther(address(_avatar), _proposalId, _proposal.beneficiary, amount);
264269
}
@@ -277,7 +282,7 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
277282

278283
ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
279284
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
280-
require(proposal.executionTime != 0);
285+
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
281286
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 3);
282287
//set proposal rewards to zero to prevent reentrancy attack.
283288
proposal.externalTokenReward = 0;
@@ -288,7 +293,8 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
288293
require(
289294
Controller(
290295
_avatar.owner())
291-
.externalTokenTransfer(_proposal.externalToken, _proposal.beneficiary, amount, _avatar));
296+
.externalTokenTransfer(_proposal.externalToken, _proposal.beneficiary, amount, _avatar),
297+
"failed to transfer external token");
292298
proposal.redeemedPeriods[3] = proposal.redeemedPeriods[3].add(periodsToPay);
293299
emit RedeemExternalToken(address(_avatar), _proposalId, _proposal.beneficiary, amount);
294300
}

0 commit comments

Comments
 (0)