Skip to content

Commit

Permalink
[WIP]: Increase test coverage (#743)
Browse files Browse the repository at this point in the history
* ArcScem and Redeemer test coverage

* coverage ContributionRewardExt

* Update fundingrequest.js

* Update schemefactory.js

* Update competition.js

* lint

* redeemer test coverage

* Move setting scheme voting params to ArcScheme

* Add initializeGovernance function

* Update ArcScheme.sol

* Fix require

* doc

* Add arc scheme test
  • Loading branch information
ben-kaufman authored May 4, 2020
1 parent 7595ff7 commit 39c063b
Show file tree
Hide file tree
Showing 30 changed files with 504 additions and 207 deletions.
40 changes: 36 additions & 4 deletions contracts/schemes/ArcScheme.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity ^0.5.17;

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

Expand All @@ -13,14 +14,45 @@ contract ArcScheme is Initializable {
/**
* @dev _initialize
* @param _avatar the scheme avatar
* @param _votingMachine the scheme voting machine
* @param _voteParamsHash the scheme vote params
*/
function _initialize(Avatar _avatar, IntVoteInterface _votingMachine, bytes32 _voteParamsHash) internal initializer
function _initialize(Avatar _avatar) internal initializer
{
require(address(_avatar) != address(0), "Scheme must have avatar");
avatar = _avatar;
}

/**
* @dev _initializeGovernance
* @param _avatar the scheme avatar
* @param _votingMachine the scheme voting machine
* @param _voteParamsHash the scheme vote params
* @param _votingParams genesisProtocol parameters - valid only if _voteParamsHash is zero
* @param _voteOnBehalf genesisProtocol parameter - valid only if _voteParamsHash is zero
*/
function _initializeGovernance(
Avatar _avatar,
IntVoteInterface _votingMachine,
bytes32 _voteParamsHash,
uint256[11] memory _votingParams,
address _voteOnBehalf
) internal
{
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
_initialize(_avatar);
votingMachine = _votingMachine;
voteParamsHash = _voteParamsHash;
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;
}
}
}
2 changes: 1 addition & 1 deletion contracts/schemes/Auction4Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract Auction4Reputation is Agreement, ArcScheme {
bytes32 _agreementHash )
external
{
super._initialize(_avatar, IntVoteInterface(0), 0);
super._initialize(_avatar);
require(_numberOfAuctions > 0, "number of auctions cannot be zero");
//_auctionPeriod should be greater than block interval
require(_auctionPeriod > 15, "auctionPeriod should be > 15");
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ContinuousLocking4Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract ContinuousLocking4Reputation is Agreement, ArcScheme {
bytes32 _agreementHash )
external
{
super._initialize(_avatar, IntVoteInterface(0), 0);
super._initialize(_avatar);
// _batchTime should be greater than block interval
require(_batchTime > 15, "batchTime should be > 15");
require(_maxLockingBatches <= MAX_LOCKING_BATCHES_HARDCAP,
Expand Down
19 changes: 1 addition & 18 deletions contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pragma solidity ^0.5.17;

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


/**
* @title A scheme for proposing and rewarding contributions to an organization
Expand Down Expand Up @@ -82,22 +80,7 @@ contract ContributionReward is
external
initializer
{
avatar = _avatar;
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
Expand Down
17 changes: 1 addition & 16 deletions contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
)
external
{
require(_votingMachine != IntVoteInterface(0), "votingMachine cannot be zero");
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
rewarder = _rewarder;
vault = new Vault();
vault.initialize(address(this));
Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/FixedReputationAllocation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract FixedReputationAllocation is Ownable, ArcScheme {
function initialize(Avatar _avatar, uint256 _reputationReward, uint256 _redeemEnableTime, address _owner)
external
{
super._initialize(_avatar, IntVoteInterface(0), 0);
super._initialize(_avatar);
reputationReward = _reputationReward;
redeemEnableTime = _redeemEnableTime;
Ownable.initialize(_owner);
Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/FundingRequest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,7 @@ contract FundingRequest is
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
fundingToken = _fundingToken;
}

Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/GenericScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,7 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
contractToCall = _contractToCall;
}

Expand Down
18 changes: 2 additions & 16 deletions contracts/schemes/GlobalConstraintRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,9 @@ contract GlobalConstraintRegistrar is VotingMachineCallbacks, ProposalExecuteInt
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
* @dev execution of proposals, can only be called by the voting machine in which the vote is held.
* @param _proposalId the ID of the voting in the voting machine
Expand Down
17 changes: 1 addition & 16 deletions contracts/schemes/JoinAndQuit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,7 @@ contract JoinAndQuit is
)
external
{
avatar = _avatar;
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
fundingToken = _fundingToken;
minFeeToJoin = _minFeeToJoin;
memberReputation = _memberReputation;
Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/Locking4Reputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ contract Locking4Reputation is Agreement, ArcScheme {
bytes32 _agreementHash )
internal
{
super._initialize(_avatar, IntVoteInterface(0), 0);
super._initialize(_avatar);
require(_lockingEndTime > _lockingStartTime, "locking end time should be greater than locking start time");
require(_redeemEnableTime >= _lockingEndTime, "redeemEnableTime >= lockingEndTime");

Expand Down
2 changes: 1 addition & 1 deletion contracts/schemes/ReputationFromToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract ReputationFromToken is ArcScheme {
*/
function initialize(Avatar _avatar, IERC20 _tokenContract, CurveInterface _curve) external
{
super._initialize(_avatar, IntVoteInterface(0), 0);
super._initialize(_avatar);
tokenContract = _tokenContract;
curve = _curve;
}
Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/SchemeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,7 @@ contract SchemeFactory is VotingMachineCallbacks, ProposalExecuteInterface {
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
daoFactory = _daoFactory;
}

Expand Down
3 changes: 2 additions & 1 deletion contracts/schemes/SchemeRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ contract SchemeRegistrar is VotingMachineCallbacks, ProposalExecuteInterface {
)
external
{
super._initialize(_avatar, _votingMachine, 0);
super._initialize(_avatar);
votingMachine = _votingMachine;
if (_voteRegisterParamsHash == bytes32(0)) {
//genesisProtocol
GenesisProtocol genesisProtocol = GenesisProtocol(address(_votingMachine));
Expand Down
17 changes: 1 addition & 16 deletions contracts/schemes/SignalScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,7 @@ contract SignalScheme is VotingMachineCallbacks, ProposalExecuteInterface {
address _voteOnBehalf)
external
initializer {
bytes32 voteParamsHash;
if (_voteApproveParams == 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 = _voteApproveParams;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteApproveParams, _votingParams, _voteOnBehalf);
params = Parameters({
voteApproveParams: voteParamsHash,
signalType: _signalType,
Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/UpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,7 @@ contract UpgradeScheme is VotingMachineCallbacks, ProposalExecuteInterface {
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
arcPackage = _package;
}

Expand Down
16 changes: 1 addition & 15 deletions contracts/schemes/VoteInOrganizationScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,7 @@ contract VoteInOrganizationScheme is VotingMachineCallbacks, ProposalExecuteInte
)
external
{
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;
}
super._initialize(_avatar, _votingMachine, voteParamsHash);
super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions contracts/test/ARCGenesisProtocolCallbacksMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import "../votingMachines/VotingMachineCallbacks.sol";


contract ARCVotingMachineCallbacksMock is VotingMachineCallbacks {
function initialize(Avatar _avatar, address votingMachine)
function initialize(Avatar _avatar, address _votingMachine)
external {
super._initialize(_avatar, IntVoteInterface(votingMachine), 0);
super._initialize(_avatar);
votingMachine = IntVoteInterface(_votingMachine);
}

function propose(bytes32 _proposalId) public {
Expand Down
Loading

0 comments on commit 39c063b

Please sign in to comment.