Skip to content

Commit

Permalink
Use buidler (#807)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
ben-kaufman and Oren Sokolowsky authored Nov 23, 2020
1 parent d0678a3 commit 1b15ff2
Show file tree
Hide file tree
Showing 30 changed files with 18,062 additions and 6,304 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ coverage.json
.covera*
cache/
yarn*

node_modules

#Hardhat files
cache
artifacts
111 changes: 108 additions & 3 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,112 @@ module.exports = {
mocha: {
enableTimeouts: false,
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
invert: true, // Run the grep's inverse set.
timeout: 100000,
},
skipFiles: ['test/']
}
skipFiles: ['test/'],
providerOptions: {
accounts: [
{
secretKey:
"0xc5e8f61d1ab959b397eecc0a37a6517b8e67a0e7cf1f4bce5591f3ed80199122",
balance: "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
},
{
secretKey:
"0xd49743deccbccc5dc7baa8e69e5be03298da8688a15dd202e20f15d5e0e9a9fb",
balance: "10000000000000000000000"
},
{
secretKey:
"0x23c601ae397441f3ef6f1075dcb0031ff17fb079837beadaf3c84d96c6f3e569",
balance: "10000000000000000000000"
},
{
secretKey:
"0xee9d129c1997549ee09c0757af5939b2483d80ad649a0eda68e8b0357ad11131",
balance: "10000000000000000000000"
},
{
secretKey:
"0x87630b2d1de0fbd5044eb6891b3d9d98c34c8d310c852f98550ba774480e47cc",
balance: "10000000000000000000000"
},
{
secretKey:
"0x275cc4a2bfd4f612625204a20a2280ab53a6da2d14860c47a9f5affe58ad86d4",
balance: "10000000000000000000000"
},
{
secretKey:
"0x7f307c41137d1ed409f0a7b028f6c7596f12734b1d289b58099b99d60a96efff",
balance: "10000000000000000000000"
},
{
secretKey:
"0x2a8aede924268f84156a00761de73998dac7bf703408754b776ff3f873bcec60",
balance: "10000000000000000000000"
},
{
secretKey:
"0x8b24fd94f1ce869d81a34b95351e7f97b2cd88a891d5c00abc33d0ec9501902e",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29085",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29086",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29087",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29088",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b29089",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908a",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908b",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908c",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908d",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908e",
balance: "10000000000000000000000"
},
{
secretKey:
"0x28d1bfbbafe9d1d4f5a11c3c16ab6bf9084de48d99fbac4058bdfa3c80b2908f",
balance: "10000000000000000000000"
}
]
}
};
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@ dist: trusty
language: node_js

node_js:
- "12.19.0"
- "14.5.0"

before_install:

install:
- npm ci
- rm -rf node_modules/ # remove any remaining artifacts from a previous build
- npm i
- rm -rf build/ # remove any remaining artifacts from a previous build
- truffle version
- npx hardhat --version
- npx hardhat clean

jobs:
include:
- stage: tests
name: "Unit tests"
script: npm run test
script: npx hardhat test

- stage: tests
name: "Solidity Lint"
script: npm run solhint
script: npx hardhat check

- stage: tests
name: "JS Lint"
script: npm run lint
script: npx eslint .

- stage: coverage
name: "Solidity Test Coverage"
Expand Down
26 changes: 0 additions & 26 deletions contracts/Migrations.sol

This file was deleted.

30 changes: 18 additions & 12 deletions contracts/universalSchemes/ContributionReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import "../votingMachines/VotingMachineCallbacks.sol";
* @dev An agent can ask an organization to recognize a contribution and reward
* him with token, reputation, ether or any combination.
*/

contract ContributionReward is UniversalScheme, VotingMachineCallbacks, ProposalExecuteInterface {
using SafeMath for uint;

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

ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
require(proposal.executionTime != 0);
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 0);

//set proposal reward to zero to prevent reentrancy attack.
Expand All @@ -201,11 +202,13 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
if (reputation > 0) {
require(
Controller(
_avatar.owner()).mintReputation(uint(reputation), _proposal.beneficiary, address(_avatar)));
_avatar.owner()).mintReputation(uint(reputation), _proposal.beneficiary, address(_avatar)),
"failed to mint reputation");
} else if (reputation < 0) {
require(
Controller(
_avatar.owner()).burnReputation(uint(reputation*(-1)), _proposal.beneficiary, address(_avatar)));
_avatar.owner()).burnReputation(uint(reputation*(-1)), _proposal.beneficiary, address(_avatar)),
"failed to burn reputation");
}
if (reputation != 0) {
proposal.redeemedPeriods[0] = proposal.redeemedPeriods[0].add(periodsToPay);
Expand All @@ -225,14 +228,15 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal

ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
require(proposal.executionTime != 0);
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 1);
//set proposal rewards to zero to prevent reentrancy attack.
proposal.nativeTokenReward = 0;

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

ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
require(proposal.executionTime != 0);
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 2);
//set proposal rewards to zero to prevent reentrancy attack.
proposal.ethReward = 0;
amount = periodsToPay.mul(_proposal.ethReward);

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

ContributionProposal memory _proposal = organizationsProposals[address(_avatar)][_proposalId];
ContributionProposal storage proposal = organizationsProposals[address(_avatar)][_proposalId];
require(proposal.executionTime != 0);
require(proposal.executionTime != 0, "cannot execute unapproved proposal");
uint256 periodsToPay = getPeriodsToPay(_proposalId, address(_avatar), 3);
//set proposal rewards to zero to prevent reentrancy attack.
proposal.externalTokenReward = 0;
Expand All @@ -288,7 +293,8 @@ contract ContributionReward is UniversalScheme, VotingMachineCallbacks, Proposal
require(
Controller(
_avatar.owner())
.externalTokenTransfer(_proposal.externalToken, _proposal.beneficiary, amount, _avatar));
.externalTokenTransfer(_proposal.externalToken, _proposal.beneficiary, amount, _avatar),
"failed to transfer external token");
proposal.redeemedPeriods[3] = proposal.redeemedPeriods[3].add(periodsToPay);
emit RedeemExternalToken(address(_avatar), _proposalId, _proposal.beneficiary, amount);
}
Expand Down
Loading

0 comments on commit 1b15ff2

Please sign in to comment.