Skip to content

Commit

Permalink
increase test coverage + set genesis protocol parameters at schemes i…
Browse files Browse the repository at this point in the history
…nitilize function. (#733)

* increase test coverage

* set generisProtocolParams upon schemes initilization

* tests

* tests

* tests

* reputationFromToken test . redeemWithSignature

* solc 0.5.17

* test coverage

* clean daofactory

* reputationFromToken test fix

* bump version
  • Loading branch information
orenyodfat authored Apr 13, 2020
1 parent 954e328 commit 72478fd
Show file tree
Hide file tree
Showing 72 changed files with 930 additions and 388 deletions.
1 change: 0 additions & 1 deletion .coveralls.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"eol-last": 2,
"eqeqeq": "error"
},
"ignorePatterns": ["cache/", "node_modules/"]
"ignorePatterns": ["cache/", "node_modules/","coverage/"]
}
1 change: 1 addition & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
grep: "@skip-on-coverage", // Find everything with this tag
invert: true // Run the grep's inverse set.
},
skipFiles: ['test/'],
providerOptions: {
accounts: [
{
Expand Down
3 changes: 2 additions & 1 deletion buidler.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
usePlugin("@nomiclabs/buidler-truffle5");
usePlugin("@nomiclabs/buidler-solhint");
usePlugin("solidity-coverage");
usePlugin("@nomiclabs/buidler-web3");

// This is a sample Buidler task. To learn how to create your own go to
// https://buidler.dev/guides/create-task.html
Expand Down Expand Up @@ -123,7 +124,7 @@ module.exports = {
}
},
solc: {
version: "0.5.16", // Fetch exact version from solc-bin (default: truffle's version)
version: "0.5.17", // Fetch exact version from solc-bin (default: truffle's version)
optimizer: {
enabled: true,
runs: 200
Expand Down
26 changes: 0 additions & 26 deletions contracts/Migrations.sol

This file was deleted.

2 changes: 1 addition & 1 deletion contracts/controller/Avatar.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@daostack/infra-experimental/contracts/Reputation.sol";
import "./DAOToken.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/Controller.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "./Avatar.sol";
import "../globalConstraints/GlobalConstraintInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/controller/DAOToken.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Burnable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/globalConstraints/GlobalConstraintInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;


contract GlobalConstraintInterface {
Expand Down
2 changes: 1 addition & 1 deletion contracts/globalConstraints/TokenCapGC.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol";
import "./GlobalConstraintInterface.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/libs/Bytes32ToStr.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

library Bytes32ToStr {
function toStr(bytes32 x) internal pure returns (string memory) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/libs/StringUtil.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;


library StringUtil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "../schemes/CurveInterface.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Agreement.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

/**
* @title A scheme for conduct ERC20 Tokens auction for reputation
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Auction4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "../controller/Controller.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/CommonInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;


contract CommonInterface {
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Competition.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.16;
pragma solidity 0.5.17;

import "./ContributionRewardExt.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ContinuousLockingToken4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/math/Math.sol";
Expand Down
31 changes: 24 additions & 7 deletions contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "../votingMachines/VotingMachineCallbacks.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol";


/**
* @title A scheme for proposing and rewarding contributions to an organization
* @dev An agent can ask an organization to recognize a contribution and reward
* him with token, reputation, ether or any combination.
*/

contract ContributionReward is
VotingMachineCallbacks,
ProposalExecuteInterface,
Expand Down Expand Up @@ -67,27 +67,44 @@ contract ContributionReward is
mapping(bytes32=>ContributionProposal) public organizationProposals;

IntVoteInterface public votingMachine;
bytes32 public voteParams;
bytes32 public voteParamsHash;
Avatar public avatar;

/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingMachine the voting machines address to
* @param _voteParams voting machine parameters.
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParams
uint256[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash
)
external
initializer
{
require(_avatar != Avatar(0), "avatar cannot be zero");
avatar = _avatar;
votingMachine = _votingMachine;
voteParams = _voteParams;
if (_voteParamsHash == bytes32(0)) {
//genesisProtocol
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
genesisProtocol.parameters(voteParamsHash);
if (queuedVoteRequiredPercentage == 0) {
//params not set already
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
}
} else {
//for other voting machines
voteParamsHash = _voteParamsHash;
}
}

/**
Expand Down Expand Up @@ -135,7 +152,7 @@ contract ContributionReward is
returns(bytes32)
{
validateProposalParams(_reputationChange, _rewards);
bytes32 proposalId = votingMachine.propose(2, voteParams, msg.sender, address(avatar));
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
29 changes: 23 additions & 6 deletions contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.5.16;
pragma solidity 0.5.17;

import "../votingMachines/VotingMachineCallbacks.sol";

Expand Down Expand Up @@ -72,7 +72,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
mapping(bytes32=>ContributionProposal) public organizationProposals;

IntVoteInterface public votingMachine;
bytes32 public voteParams;
bytes32 public voteParamsHash;
Avatar public avatar;
address public rewarder;
Vault public vault;
Expand All @@ -81,14 +81,18 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
* @dev initialize
* @param _avatar the avatar to mint reputation from
* @param _votingMachine the voting machines address
* @param _voteParams voting machine parameters
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters
* @param _rewarder an address which allowed to redeem the contribution.
if _rewarder is 0 this param is agnored.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParams,
uint[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash,
address _rewarder
)
external
Expand All @@ -98,7 +102,20 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
avatar = _avatar;
votingMachine = _votingMachine;
voteParams = _voteParams;
if (_voteParamsHash == bytes32(0)) {
//genesisProtocol
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
genesisProtocol.parameters(voteParamsHash);
if (queuedVoteRequiredPercentage == 0) {
//params not set already
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
}
} else {
//for other voting machines
voteParamsHash = _voteParamsHash;
}
rewarder = _rewarder;
vault = new Vault();
vault.initialize(address(this));
Expand Down Expand Up @@ -149,7 +166,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
if (proposer == address(0)) {
proposer = msg.sender;
}
proposalId = votingMachine.propose(2, voteParams, proposer, address(avatar));
proposalId = votingMachine.propose(2, voteParamsHash, proposer, address(avatar));
address payable beneficiary = _beneficiary;
if (beneficiary == address(0)) {
beneficiary = msg.sender;
Expand Down
31 changes: 24 additions & 7 deletions contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "@daostack/infra-experimental/contracts/votingMachines/IntVoteInterface.sol";
import "@daostack/infra-experimental/contracts/votingMachines/ProposalExecuteInterface.sol";
Expand Down Expand Up @@ -40,27 +40,44 @@ contract ControllerUpgradeScheme is Initializable, VotingMachineCallbacks, Propo
mapping(bytes32=>UpgradeProposal) public organizationProposals;

IntVoteInterface public votingMachine;
bytes32 public voteParams;
bytes32 public voteParamsHash;
Avatar public avatar;

/**
* @dev initialize
* @param _avatar the avatar this scheme referring to.
* @param _votingMachine the voting machines address to
* @param _voteParams voting machine parameters.
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
* @param _voteParamsHash voting machine parameters.
*/
function initialize(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParams
uint256[11] calldata _votingParams,
address _voteOnBehalf,
bytes32 _voteParamsHash
)
external
initializer
{
require(_avatar != Avatar(0), "avatar cannot be zero");
avatar = _avatar;
votingMachine = _votingMachine;
voteParams = _voteParams;
if (_voteParamsHash == bytes32(0)) {
//genesisProtocol
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
voteParamsHash = genesisProtocol.getParametersHash(_votingParams, _voteOnBehalf);
(uint256 queuedVoteRequiredPercentage, , , , , , , , , , , ,) =
genesisProtocol.parameters(voteParamsHash);
if (queuedVoteRequiredPercentage == 0) {
//params not set already
genesisProtocol.setParameters(_votingParams, _voteOnBehalf);
}
} else {
//for other voting machines
voteParamsHash = _voteParamsHash;
}
}

/**
Expand Down Expand Up @@ -108,7 +125,7 @@ contract ControllerUpgradeScheme is Initializable, VotingMachineCallbacks, Propo
public
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParams, msg.sender, address(avatar));
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
UpgradeProposal memory proposal = UpgradeProposal({
proposalType: 1,
upgradeContract: _newController
Expand Down Expand Up @@ -141,7 +158,7 @@ contract ControllerUpgradeScheme is Initializable, VotingMachineCallbacks, Propo
public
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParams, msg.sender, address(avatar));
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
require(organizationProposals[proposalId].proposalType == 0);

UpgradeProposal memory proposal = UpgradeProposal({
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/CurveInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

interface CurveInterface {

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ExternalLocking4Reputation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "./Locking4Reputation.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/FixedReputationAllocation.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.16;
pragma solidity ^0.5.17;

import "../controller/Controller.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";
Expand Down
Loading

0 comments on commit 72478fd

Please sign in to comment.