diff --git a/contracts/schemes/ArcScheme.sol b/contracts/schemes/ArcScheme.sol index 8106bcb4..96133b6f 100644 --- a/contracts/schemes/ArcScheme.sol +++ b/contracts/schemes/ArcScheme.sol @@ -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"; @@ -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; + } } } diff --git a/contracts/schemes/Auction4Reputation.sol b/contracts/schemes/Auction4Reputation.sol index 1ece274a..847f0ef5 100644 --- a/contracts/schemes/Auction4Reputation.sol +++ b/contracts/schemes/Auction4Reputation.sol @@ -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"); diff --git a/contracts/schemes/ContinuousLocking4Reputation.sol b/contracts/schemes/ContinuousLocking4Reputation.sol index 6c3ea7f3..949db3c2 100644 --- a/contracts/schemes/ContinuousLocking4Reputation.sol +++ b/contracts/schemes/ContinuousLocking4Reputation.sol @@ -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, diff --git a/contracts/schemes/ContributionReward.sol b/contracts/schemes/ContributionReward.sol index fbe714da..e1c49020 100644 --- a/contracts/schemes/ContributionReward.sol +++ b/contracts/schemes/ContributionReward.sol @@ -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 @@ -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); } /** diff --git a/contracts/schemes/ContributionRewardExt.sol b/contracts/schemes/ContributionRewardExt.sol index 844d7088..8d525056 100644 --- a/contracts/schemes/ContributionRewardExt.sol +++ b/contracts/schemes/ContributionRewardExt.sol @@ -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)); diff --git a/contracts/schemes/ControllerUpgradeScheme.sol b/contracts/schemes/ControllerUpgradeScheme.sol index 038fc52a..47df3d12 100644 --- a/contracts/schemes/ControllerUpgradeScheme.sol +++ b/contracts/schemes/ControllerUpgradeScheme.sol @@ -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); } /** diff --git a/contracts/schemes/FixedReputationAllocation.sol b/contracts/schemes/FixedReputationAllocation.sol index 0908b57f..43380ef8 100644 --- a/contracts/schemes/FixedReputationAllocation.sol +++ b/contracts/schemes/FixedReputationAllocation.sol @@ -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); diff --git a/contracts/schemes/FundingRequest.sol b/contracts/schemes/FundingRequest.sol index 6283a612..ec99430b 100644 --- a/contracts/schemes/FundingRequest.sol +++ b/contracts/schemes/FundingRequest.sol @@ -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; } diff --git a/contracts/schemes/GenericScheme.sol b/contracts/schemes/GenericScheme.sol index 2df5012b..229ee307 100644 --- a/contracts/schemes/GenericScheme.sol +++ b/contracts/schemes/GenericScheme.sol @@ -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; } diff --git a/contracts/schemes/GlobalConstraintRegistrar.sol b/contracts/schemes/GlobalConstraintRegistrar.sol index a89ba91f..1d44d503 100644 --- a/contracts/schemes/GlobalConstraintRegistrar.sol +++ b/contracts/schemes/GlobalConstraintRegistrar.sol @@ -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 diff --git a/contracts/schemes/JoinAndQuit.sol b/contracts/schemes/JoinAndQuit.sol index ec493641..24194b18 100644 --- a/contracts/schemes/JoinAndQuit.sol +++ b/contracts/schemes/JoinAndQuit.sol @@ -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; diff --git a/contracts/schemes/Locking4Reputation.sol b/contracts/schemes/Locking4Reputation.sol index 8ad41936..685816e5 100644 --- a/contracts/schemes/Locking4Reputation.sol +++ b/contracts/schemes/Locking4Reputation.sol @@ -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"); diff --git a/contracts/schemes/ReputationFromToken.sol b/contracts/schemes/ReputationFromToken.sol index e0b983cb..28aa57dd 100644 --- a/contracts/schemes/ReputationFromToken.sol +++ b/contracts/schemes/ReputationFromToken.sol @@ -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; } diff --git a/contracts/schemes/SchemeFactory.sol b/contracts/schemes/SchemeFactory.sol index 5440101a..cc805d79 100644 --- a/contracts/schemes/SchemeFactory.sol +++ b/contracts/schemes/SchemeFactory.sol @@ -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; } diff --git a/contracts/schemes/SchemeRegistrar.sol b/contracts/schemes/SchemeRegistrar.sol index 74254f75..e22608c0 100644 --- a/contracts/schemes/SchemeRegistrar.sol +++ b/contracts/schemes/SchemeRegistrar.sol @@ -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)); diff --git a/contracts/schemes/SignalScheme.sol b/contracts/schemes/SignalScheme.sol index 38f75639..3312855d 100644 --- a/contracts/schemes/SignalScheme.sol +++ b/contracts/schemes/SignalScheme.sol @@ -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, diff --git a/contracts/schemes/UpgradeScheme.sol b/contracts/schemes/UpgradeScheme.sol index 488c8795..c38ae0ed 100644 --- a/contracts/schemes/UpgradeScheme.sol +++ b/contracts/schemes/UpgradeScheme.sol @@ -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; } diff --git a/contracts/schemes/VoteInOrganizationScheme.sol b/contracts/schemes/VoteInOrganizationScheme.sol index afbf6a9a..3b18d9d9 100644 --- a/contracts/schemes/VoteInOrganizationScheme.sol +++ b/contracts/schemes/VoteInOrganizationScheme.sol @@ -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); } /** diff --git a/contracts/test/ARCGenesisProtocolCallbacksMock.sol b/contracts/test/ARCGenesisProtocolCallbacksMock.sol index 62a5a5fb..81414147 100644 --- a/contracts/test/ARCGenesisProtocolCallbacksMock.sol +++ b/contracts/test/ARCGenesisProtocolCallbacksMock.sol @@ -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 { diff --git a/contracts/test/SchemeMock.sol b/contracts/test/SchemeMock.sol index e0e0cc3b..e5aac255 100644 --- a/contracts/test/SchemeMock.sol +++ b/contracts/test/SchemeMock.sol @@ -10,7 +10,20 @@ contract SchemeMock is ArcScheme { function initialize(Avatar _avatar, uint256 _testData) external { - super._initialize(_avatar, IntVoteInterface(0), 0); + super._initialize(_avatar); + testData = _testData; + } + + function initializeGovernance( + Avatar _avatar, + IntVoteInterface _votingMachine, + uint256[11] calldata _votingParams, + address _voteOnBehalf, + bytes32 _voteParamsHash, + uint256 _testData + ) + external { + super._initializeGovernance(_avatar, _votingMachine, _voteParamsHash, _votingParams, _voteOnBehalf); testData = _testData; } diff --git a/contracts/utils/Redeemer.sol b/contracts/utils/Redeemer.sol index 11594294..27ec006c 100644 --- a/contracts/utils/Redeemer.sol +++ b/contracts/utils/Redeemer.sol @@ -2,7 +2,6 @@ pragma solidity ^0.5.17; import "../schemes/ContributionReward.sol"; import "../schemes/ContributionRewardExt.sol"; -import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol"; import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/votingMachines/VotingMachineCallbacks.sol b/contracts/votingMachines/VotingMachineCallbacks.sol index 7c9f052e..9c1ad01f 100644 --- a/contracts/votingMachines/VotingMachineCallbacks.sol +++ b/contracts/votingMachines/VotingMachineCallbacks.sol @@ -1,6 +1,5 @@ pragma solidity ^0.5.17; -import "@daostack/infra-experimental/contracts/votingMachines/GenesisProtocol.sol"; import "../controller/Avatar.sol"; import "../controller/Controller.sol"; import "../schemes/ArcScheme.sol"; diff --git a/test/arcscheme.js b/test/arcscheme.js new file mode 100644 index 00000000..e214f994 --- /dev/null +++ b/test/arcscheme.js @@ -0,0 +1,101 @@ +const helpers = require("./helpers"); +const ERC20Mock = artifacts.require('./test/ERC20Mock.sol'); + +const SchemeMock = artifacts.require('./test/SchemeMock.sol'); + + + var registration; +const setup = async function (accounts, initGov=true, avatarZero=false, vmZero=false, gpParamsHash=true) { + var testSetup = new helpers.TestSetup(); + registration = await helpers.registerImplementation(); + testSetup.proxyAdmin = accounts[5]; + testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin, + accounts, + registration, + [accounts[0]], + [1000], + [1000]); + testSetup.standardTokenMock = await ERC20Mock.new(testSetup.org.avatar.address,100); + + var schemeMockData; + if (!initGov) { + schemeMockData = await new web3.eth.Contract(registration.schemeMock.abi) + .methods + .initialize( + avatarZero ? helpers.NULL_ADDRESS : testSetup.org.avatar.address, + 1 + ) + .encodeABI(); + } else { + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + testSetup.votingMachine = await helpers.setupGenesisProtocol(accounts,standardTokenMock.address,helpers.NULL_ADDRESS); + schemeMockData = await new web3.eth.Contract(registration.schemeMock.abi) + .methods + .initializeGovernance( + avatarZero ? helpers.NULL_ADDRESS : testSetup.org.avatar.address, + vmZero ? helpers.NULL_ADDRESS : testSetup.votingMachine.genesisProtocol.address, + testSetup.votingMachine.uintArray, + testSetup.votingMachine.voteOnBehalf, + gpParamsHash ? testSetup.votingMachine.params : helpers.NULL_HASH, + 1 + ) + .encodeABI(); + } + + + var permissions = "0x00000000"; + var tx = await registration.daoFactory.setSchemes( + testSetup.org.avatar.address, + [web3.utils.fromAscii("SchemeMock")], + schemeMockData, + [helpers.getBytesLength(schemeMockData)], + [permissions], + "metaData", + {from:testSetup.proxyAdmin}); + + if (!avatarZero && !vmZero) { + testSetup.schemeMock = await SchemeMock.at(tx.logs[1].args._scheme); + + return testSetup; + } +}; +contract('VotingMachineCallbacks', function(accounts) { + + it("avatar address cannot be 0 ", async function() { + try { + await setup(accounts, false, true); + assert(false, "avatar 0 address should revert"); + } catch(error) { + // revert + } + }); + + it("vm address cannot be 0 ", async function() { + try { + await setup(accounts, true, false, true); + assert(false, "vm 0 address should revert"); + } catch(error) { + // revert + } + }); + + it("initialize ", async function() { + var testSetup = await setup(accounts, false); + + assert.equal(await testSetup.schemeMock.avatar(), testSetup.org.avatar.address); + }); + + it("initializeGovernance ", async function() { + var testSetup = await setup(accounts); + assert.equal(await testSetup.schemeMock.avatar(), testSetup.org.avatar.address); + assert.equal(await testSetup.schemeMock.votingMachine(), testSetup.votingMachine.genesisProtocol.address); + assert.equal(await testSetup.schemeMock.voteParamsHash(), testSetup.votingMachine.params); + }); + + it("initializeGovernance gp set params", async function() { + var testSetup = await setup(accounts, true, false, false, false); + assert.equal(await testSetup.schemeMock.avatar(), testSetup.org.avatar.address); + assert.equal(await testSetup.schemeMock.votingMachine(), testSetup.votingMachine.genesisProtocol.address); + assert.equal(await testSetup.schemeMock.voteParamsHash(), testSetup.votingMachine.params); + }); +}); diff --git a/test/competition.js b/test/competition.js index edde894a..f4a4613f 100644 --- a/test/competition.js +++ b/test/competition.js @@ -113,7 +113,7 @@ const proposeCompetition = async function( ) { var block = await web3.eth.getBlock("latest"); - _testSetup.startTime = block.timestamp + _startTime; + _testSetup.startTime = _startTime > 0 ? block.timestamp + _startTime : 0; _testSetup.votingStartTime = block.timestamp + _votingStartTime; _testSetup.endTime = block.timestamp + _endTime; _testSetup.suggestionsEndTime = block.timestamp + _suggestionsEndTime; @@ -145,7 +145,8 @@ const proposeCompetition = async function( assert.equal(tx.logs[0].args._rewardSplit[1],_rewardSplit[1]); assert.equal(tx.logs[0].args._rewardSplit[2],_rewardSplit[2]); assert.equal(tx.logs[0].args._rewardSplit[3],_rewardSplit[3]); - assert.equal(tx.logs[0].args._startTime,_testSetup.startTime); + block = await web3.eth.getBlock("latest"); + assert.equal(tx.logs[0].args._startTime,_testSetup.startTime === 0 ? block.timestamp : _testSetup.startTime); assert.equal(tx.logs[0].args._votingStartTime,_testSetup.votingStartTime); assert.equal(tx.logs[0].args._endTime,_testSetup.endTime); assert.equal(tx.logs[0].args._maxNumberOfVotesPerVoter,_maxNumberOfVotesPerVoter); @@ -245,6 +246,11 @@ contract('Competition', accounts => { } }); + it("proposeCompetition no start time", async function() { + var testSetup = await setup(accounts); + await proposeCompetition(testSetup,"description-hash",10,[1,2,3],[50,25,15,10],0); + }); + it("suggest", async function() { var testSetup = await setup(accounts); var proposalId = await proposeCompetition(testSetup); diff --git a/test/contributionreward.js b/test/contributionreward.js index 1ebe345b..61158ff0 100644 --- a/test/contributionreward.js +++ b/test/contributionreward.js @@ -518,9 +518,11 @@ contract('ContributionReward', accounts => { it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer", async function() { var standardTokenMock = await ERC20Mock.new(accounts[0],1000); var testSetup = await setup(accounts,true,standardTokenMock.address); + await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,30,{from:accounts[1]}); var reputationReward = 12; var nativeTokenReward = 12; var ethReward = 12; + var externalTokenReward = 12; var periodLength = 50; var numberOfPeriods = 1; //send some ether to the org avatar @@ -530,7 +532,7 @@ contract('ContributionReward', accounts => { var tx = await testSetup.contributionReward.proposeContributionReward( web3.utils.asciiToHex("description"), reputationReward, - [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], + [nativeTokenReward,ethReward,externalTokenReward,periodLength,numberOfPeriods], testSetup.standardTokenMock.address, otherAvatar.address ); @@ -552,7 +554,7 @@ contract('ContributionReward', accounts => { assert.equal(redeemRewards[4],reputationReward); //crReputationReward assert.equal(redeemRewards[5],nativeTokenReward); //crNativeTokenReward assert.equal(redeemRewards[6],ethReward); //crEthReward - assert.equal(redeemRewards[7],0); //crExternalTokenReward + assert.equal(redeemRewards[7],externalTokenReward); //crExternalTokenReward await arcUtils.redeem(testSetup.contributionReward.address, testSetup.contributionRewardParams.votingMachine.genesisProtocol.address, @@ -563,6 +565,7 @@ contract('ContributionReward', accounts => { assert.equal(eth,ethReward); assert.equal(await testSetup.org.reputation.balanceOf(otherAvatar.address),reputationReward); assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); + assert.equal(await testSetup.standardTokenMock.balanceOf(otherAvatar.address),externalTokenReward); var reputation = await testSetup.org.reputation.balanceOf(accounts[0]); var reputationGainAsVoter = 0; var proposingRepRewardConstA=60; @@ -570,6 +573,100 @@ contract('ContributionReward', accounts => { assert.equal(reputation, 1000+reputationGainAsVoter + reputationGainAsProposer); }); + + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer all 0", async function() { + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 0; + var ethReward = 0; + var periodLength = 50; + var numberOfPeriods = 1; + //send some ether to the org avatar + var otherAvatar = await Avatar.new(); + await otherAvatar.initialize('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS,accounts[0]); + await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionReward.proposeContributionReward( + web3.utils.asciiToHex("description"), + reputationReward, + [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], + testSetup.standardTokenMock.address, + otherAvatar.address + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.contributionRewardParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[0]}); + await helpers.increaseTime(periodLength+1); + var arcUtils = await Redeemer.new(); + var redeemRewards = await arcUtils.redeem.call(testSetup.contributionReward.address, + testSetup.contributionRewardParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + assert.equal(redeemRewards[0][1],100); //redeemRewards[0] gpRewards + assert.equal(redeemRewards[0][2],60); + assert.equal(redeemRewards[1][0],0); //daoBountyRewards + assert.equal(redeemRewards[1][1],0); //daoBountyRewards + assert.equal(redeemRewards[2],false); //isExecuted + assert.equal(redeemRewards[3],1); //winningVote + assert.equal(redeemRewards[4],reputationReward); //crReputationReward + assert.equal(redeemRewards[5],nativeTokenReward); //crNativeTokenReward + assert.equal(redeemRewards[6],ethReward); //crEthReward + assert.equal(redeemRewards[7],0); //crExternalTokenReward + + await arcUtils.redeem(testSetup.contributionReward.address, + testSetup.contributionRewardParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + var vault = await otherAvatar.vault(); + var eth = await web3.eth.getBalance(vault); + assert.equal(eth,ethReward); + assert.equal(await testSetup.org.reputation.balanceOf(otherAvatar.address),reputationReward); + assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); + var reputation = await testSetup.org.reputation.balanceOf(accounts[0]); + var reputationGainAsVoter = 0; + var proposingRepRewardConstA=60; + var reputationGainAsProposer = proposingRepRewardConstA; + assert.equal(reputation, 1000+reputationGainAsVoter + reputationGainAsProposer); + }); + + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer before executed", async function() { + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 12; + var ethReward = 12; + var periodLength = 50; + var numberOfPeriods = 1; + //send some ether to the org avatar + var otherAvatar = await Avatar.new(); + await otherAvatar.initialize('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS,accounts[0]); + await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionReward.proposeContributionReward( + web3.utils.asciiToHex("description"), + reputationReward, + [nativeTokenReward,ethReward,0,periodLength,numberOfPeriods], + testSetup.standardTokenMock.address, + otherAvatar.address + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + var arcUtils = await Redeemer.new(); + var redeemRewards = await arcUtils.redeem.call(testSetup.contributionReward.address, + testSetup.contributionRewardParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + assert.equal(redeemRewards[0][1],0); //redeemRewards[0] gpRewards + assert.equal(redeemRewards[0][2],0); + assert.equal(redeemRewards[1][0],0); //daoBountyRewards + assert.equal(redeemRewards[1][1],0); //daoBountyRewards + assert.equal(redeemRewards[2],false); //isExecuted + assert.equal(redeemRewards[3],0); //winningVote + assert.equal(redeemRewards[4],0); //crReputationReward + assert.equal(redeemRewards[5],0); //crNativeTokenReward + assert.equal(redeemRewards[6],0); //crEthReward + assert.equal(redeemRewards[7],0); //crExternalTokenReward + }); + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer + setParameters", async function() { var standardTokenMock = await ERC20Mock.new(accounts[0],1000); var testSetup = await setup(accounts,true,standardTokenMock.address,true); @@ -626,7 +723,7 @@ contract('ContributionReward', accounts => { }); - it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer for un excuted boosted proposal", async function() { + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer for un executed boosted proposal", async function() { var standardTokenMock = await ERC20Mock.new(accounts[0],1000); var testSetup = await setup(accounts,true,standardTokenMock.address); var reputationReward = 12; diff --git a/test/contributionrewardext.js b/test/contributionrewardext.js index b73a4685..e6fdb315 100644 --- a/test/contributionrewardext.js +++ b/test/contributionrewardext.js @@ -16,7 +16,8 @@ const setupContributionRewardExt = async function( genesisProtocol, token, avatarAddress, - rewarderAddress = helpers.NULL_ADDRESS + rewarderAddress = helpers.NULL_ADDRESS, + vmZero=false ) { var contributionRewardParams = new ContributionRewardParams(); if (genesisProtocol === true) { @@ -35,7 +36,7 @@ const setupContributionRewardExt = async function( contributionRewardParams.initdata = await new web3.eth.Contract(registration.contributionRewardExt.abi) .methods .initialize(avatarAddress, - contributionRewardParams.votingMachine.absoluteVote.address, + vmZero ? helpers.NULL_ADDRESS : contributionRewardParams.votingMachine.absoluteVote.address, [1,1,1,1,1,1,1,1,1,1,1], helpers.NULL_ADDRESS, contributionRewardParams.votingMachine.params, @@ -45,7 +46,7 @@ const setupContributionRewardExt = async function( return contributionRewardParams; }; var registration; -const setup = async function (accounts,genesisProtocol = false,tokenAddress=0,service=helpers.NULL_ADDRESS) { +const setup = async function (accounts,genesisProtocol = false,tokenAddress=0,service=helpers.NULL_ADDRESS,vmZero=false) { var testSetup = new helpers.TestSetup(); testSetup.standardTokenMock = await ERC20Mock.new(accounts[1],100000); registration = await helpers.registerImplementation(); @@ -69,7 +70,8 @@ const setup = async function (accounts,genesisProtocol = false,tokenAddress=0,se genesisProtocol, tokenAddress, testSetup.org.avatar.address, - service); + service, + vmZero); var permissions = "0x00000000"; var tx = await registration.daoFactory.setSchemes( @@ -93,6 +95,15 @@ contract('ContributionRewardExt', accounts => { assert.equal(await testSetup.contributionRewardExt.votingMachine(),testSetup.contributionRewardExtParams.votingMachine.absoluteVote.address); }); + it("initialize vm 0", async function() { + try { + await setup(accounts,false,0,helpers.NULL_ADDRESS,true); + assert(false, 'votingMachine cannot be zero'); + } catch (ex) { + // revert + } + }); + it("proposeContributionReward log", async function() { var testSetup = await setup(accounts); var tx = await testSetup.contributionRewardExt.proposeContributionReward( @@ -130,6 +141,36 @@ contract('ContributionRewardExt', accounts => { assert.equal(await helpers.getValueFromLogs(tx, '_beneficiary'),accounts[0]); }); + it("execute proposeContributionReward getProposalReputationReward ", async function() { + var testSetup = await setup(accounts); + var tx = await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + 10, + [0,0,0], + testSetup.standardTokenMock.address, + accounts[0], + helpers.NULL_ADDRESS + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + assert.equal((await testSetup.contributionRewardExt.getProposalReputationReward(proposalId)).toNumber(),10);//acceptedByVotingMachine + }); + + it("execute proposeContributionReward getProposalNativeTokenReward ", async function() { + var testSetup = await setup(accounts); + var tx = await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + 0, + [10,0,0], + testSetup.standardTokenMock.address, + accounts[0], + helpers.NULL_ADDRESS + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + assert.equal((await testSetup.contributionRewardExt.getProposalNativeTokenReward(proposalId)).toNumber(),10);//acceptedByVotingMachine + }); + it("execute proposeContributionReward yes ", async function() { var testSetup = await setup(accounts); var tx = await testSetup.contributionRewardExt.proposeContributionReward( @@ -328,9 +369,11 @@ contract('ContributionRewardExt', accounts => { it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer", async function() { var standardTokenMock = await ERC20Mock.new(accounts[0],1000); var testSetup = await setup(accounts,true,standardTokenMock.address); + await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,30,{from:accounts[1]}); var reputationReward = 12; var nativeTokenReward = 12; var ethReward = 12; + var externalTokenReward = 12; //send some ether to the org avatar @@ -340,7 +383,7 @@ contract('ContributionRewardExt', accounts => { var tx = await testSetup.contributionRewardExt.proposeContributionReward( web3.utils.asciiToHex("description"), reputationReward, - [nativeTokenReward,ethReward,0], + [nativeTokenReward,ethReward,externalTokenReward], testSetup.standardTokenMock.address, otherAvatar.address, helpers.NULL_ADDRESS @@ -363,7 +406,7 @@ contract('ContributionRewardExt', accounts => { assert.equal(redeemRewards[4],reputationReward); //crReputationReward assert.equal(redeemRewards[5],nativeTokenReward); //crNativeTokenReward assert.equal(redeemRewards[6],ethReward); //crEthReward - assert.equal(redeemRewards[7],0); //crExternalTokenReward + assert.equal(redeemRewards[7],externalTokenReward); //crExternalTokenReward await arcUtils.redeemFromCRExt(testSetup.contributionRewardExt.address, testSetup.contributionRewardExtParams.votingMachine.genesisProtocol.address, @@ -374,6 +417,7 @@ contract('ContributionRewardExt', accounts => { assert.equal(eth,ethReward); assert.equal(await testSetup.org.reputation.balanceOf(otherAvatar.address),reputationReward); assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); + assert.equal(await testSetup.standardTokenMock.balanceOf(otherAvatar.address),externalTokenReward); var reputation = await testSetup.org.reputation.balanceOf(accounts[0]); var reputationGainAsVoter = 0; var proposingRepRewardConstA=60; @@ -381,7 +425,103 @@ contract('ContributionRewardExt', accounts => { assert.equal(reputation, 1000+reputationGainAsVoter + reputationGainAsProposer); }); - it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer for un excuted boosted proposal", async function() { + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer before executed", async function() { + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 12; + var ethReward = 12; + + + //send some ether to the org avatar + var otherAvatar = await Avatar.new(); + await otherAvatar.initialize('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS,accounts[0]); + await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + reputationReward, + [nativeTokenReward,ethReward,0], + testSetup.standardTokenMock.address, + otherAvatar.address, + helpers.NULL_ADDRESS + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + + var arcUtils = await Redeemer.new(); + var redeemRewards = await arcUtils.redeemFromCRExt.call(testSetup.contributionRewardExt.address, + testSetup.contributionRewardExtParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + assert.equal(redeemRewards[0][1],0); //redeemRewards[0] gpRewards + assert.equal(redeemRewards[0][2],0); + assert.equal(redeemRewards[1][0],0); //daoBountyRewards + assert.equal(redeemRewards[1][1],0); //daoBountyRewards + assert.equal(redeemRewards[2],false); //isExecuted + assert.equal(redeemRewards[3],0); //winningVote + assert.equal(redeemRewards[4],0); //crReputationReward + assert.equal(redeemRewards[5],0); //crNativeTokenReward + assert.equal(redeemRewards[6],0); //crEthReward + assert.equal(redeemRewards[7],0); //crExternalTokenReward + }); + + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer all 0", async function() { + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,true,standardTokenMock.address); + var reputationReward = 12; + var nativeTokenReward = 0; + var ethReward = 0; + + + //send some ether to the org avatar + var otherAvatar = await Avatar.new(); + await otherAvatar.initialize('otheravatar', helpers.NULL_ADDRESS, helpers.NULL_ADDRESS,accounts[0]); + await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20}); + var tx = await testSetup.contributionRewardExt.proposeContributionReward( + web3.utils.asciiToHex("description"), + reputationReward, + [nativeTokenReward,ethReward,0], + testSetup.standardTokenMock.address, + otherAvatar.address, + helpers.NULL_ADDRESS + ); + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.contributionRewardExtParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[0]}); + + var arcUtils = await Redeemer.new(); + var redeemRewards = await arcUtils.redeemFromCRExt.call(testSetup.contributionRewardExt.address, + testSetup.contributionRewardExtParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + assert.equal(redeemRewards[0][1],100); //redeemRewards[0] gpRewards + assert.equal(redeemRewards[0][2],60); + assert.equal(redeemRewards[1][0],0); //daoBountyRewards + assert.equal(redeemRewards[1][1],0); //daoBountyRewards + assert.equal(redeemRewards[2],false); //isExecuted + assert.equal(redeemRewards[3],1); //winningVote + assert.equal(redeemRewards[4],reputationReward); //crReputationReward + assert.equal(redeemRewards[5],nativeTokenReward); //crNativeTokenReward + assert.equal(redeemRewards[6],ethReward); //crEthReward + assert.equal(redeemRewards[7],0); //crExternalTokenReward + + await arcUtils.redeemFromCRExt(testSetup.contributionRewardExt.address, + testSetup.contributionRewardExtParams.votingMachine.genesisProtocol.address, + proposalId, + accounts[0]); + var vault = await otherAvatar.vault(); + var eth = await web3.eth.getBalance(vault); + assert.equal(eth,ethReward); + assert.equal(await testSetup.org.reputation.balanceOf(otherAvatar.address),reputationReward); + assert.equal(await testSetup.org.token.balanceOf(otherAvatar.address),nativeTokenReward); + var reputation = await testSetup.org.reputation.balanceOf(accounts[0]); + var reputationGainAsVoter = 0; + var proposingRepRewardConstA=60; + var reputationGainAsProposer = proposingRepRewardConstA; + assert.equal(reputation, 1000+reputationGainAsVoter + reputationGainAsProposer); + }); + + it("execute proposeContributionReward via genesisProtocol and redeem using Redeemer for un executed boosted proposal", async function() { var standardTokenMock = await ERC20Mock.new(accounts[0],1000); var testSetup = await setup(accounts,true,standardTokenMock.address); var reputationReward = 12; diff --git a/test/fundingrequest.js b/test/fundingrequest.js index 64098a88..da0f4aac 100644 --- a/test/fundingrequest.js +++ b/test/fundingrequest.js @@ -219,6 +219,22 @@ contract('FundingRequest', accounts => { assert.equal(tx.logs[0].args._descriptionHash, "description-hash"); }); + it("propose log null beneficiary", async function() { + var testSetup = await setup(accounts); + + let tx = await testSetup.fundingRequest.propose( + helpers.NULL_ADDRESS, + testSetup.minFeeToJoin - 1, + "description-hash"); + + assert.equal(tx.logs.length, 1); + assert.equal(tx.logs[0].event, "NewFundingProposal"); + assert.equal(tx.logs[0].args._avatar, testSetup.org.avatar.address); + assert.equal(tx.logs[0].args._beneficiary, accounts[0]); + assert.equal(tx.logs[0].args._amount, testSetup.minFeeToJoin-1); + assert.equal(tx.logs[0].args._descriptionHash, "description-hash"); + }); + it("execute proposal yes", async function() { var testSetup = await setup(accounts); diff --git a/test/joinandquit.js b/test/joinandquit.js index c9207aeb..7c290bdc 100644 --- a/test/joinandquit.js +++ b/test/joinandquit.js @@ -359,6 +359,23 @@ contract('JoinAndQuit', accounts => { } }); + it("reputation redeem memberReputation 0", async function() { + var testSetup = await setup(accounts, false, false, helpers.NULL_ADDRESS, 100, 0); + await testSetup.standardTokenMock.approve(testSetup.joinAndQuit.address,testSetup.minFeeToJoin,{from:accounts[3]}); + var tx = await testSetup.joinAndQuit.proposeToJoin( + "description-hash", + testSetup.minFeeToJoin, + {from:accounts[3]}); + + //Vote with reputation to trigger execution + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + await testSetup.joinAndQuitParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); + tx = await testSetup.joinAndQuit.redeemReputation(proposalId); + assert.equal(tx.logs[0].event, "RedeemReputation"); + assert.equal(tx.logs[0].args._amount, testSetup.minFeeToJoin); + assert.equal(await testSetup.org.reputation.balanceOf(accounts[3]),testSetup.minFeeToJoin); + }); + it("reputation redeem + genesisProtocol", async function() { var testSetup = await setup(accounts,false,true); await testSetup.standardTokenMock.approve(testSetup.joinAndQuit.address,testSetup.minFeeToJoin,{from:accounts[3]}); @@ -401,7 +418,7 @@ contract('JoinAndQuit', accounts => { } }); - it("rageQuit", async function() { + it("rageQuit and redeem", async function() { var testSetup = await setup(accounts); await testSetup.standardTokenMock.approve(testSetup.joinAndQuit.address,testSetup.minFeeToJoin,{from:accounts[3]}); var tx = await testSetup.joinAndQuit.proposeToJoin( @@ -446,7 +463,15 @@ contract('JoinAndQuit', accounts => { await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,100); tx = await testSetup.joinAndQuit.rageQuit({from:accounts[4]}); assert.equal(tx.logs[0].args._refund, 500+100); + + try { + await testSetup.joinAndQuit.redeemReputation(proposalId); + assert(false, 'reputation cannot redeemed after rageQuit'); + } catch (ex) { + helpers.assertVMException(ex); + } }); + it("rageQuit with eth", async function() { var testSetup = await setup(accounts,true); var tx = await testSetup.joinAndQuit.proposeToJoin( diff --git a/test/schemefactory.js b/test/schemefactory.js index 254dd643..529d9101 100644 --- a/test/schemefactory.js +++ b/test/schemefactory.js @@ -98,6 +98,22 @@ contract('SchemeFactory', accounts => { assert.equal(tx.logs[0].event, "NewSchemeProposal"); }); + it("proposeScheme no scheme to un/register", async function() { + var testSetup = await setup(accounts); + + try { + await testSetup.schemeFactory.proposeScheme( + [0,1,0], + '', + testSetup.schemeFactoryParams.initdata, + "0x0000001f", + helpers.NULL_ADDRESS, + helpers.NULL_HASH); + } catch(error) { + helpers.assertVMException(error); + } + }); + it("execute proposeScheme and execute -yes - permissions== 0x0000001f", async function() { var testSetup = await setup(accounts); var tx = await testSetup.schemeFactory.proposeScheme( diff --git a/test/votingmachinecallbacks.js b/test/votingmachinecallbacks.js index 642e9c3f..ced632d3 100644 --- a/test/votingmachinecallbacks.js +++ b/test/votingmachinecallbacks.js @@ -7,7 +7,7 @@ const proposalId = "0x1234000000000000000000000000000000000000000000000000000000 var registration; -const setup = async function (accounts) { +const setup = async function (accounts, avatarZero=false) { var testSetup = new helpers.TestSetup(); registration = await helpers.registerImplementation(); testSetup.proxyAdmin = accounts[5]; @@ -21,7 +21,7 @@ const setup = async function (accounts) { var schemeMockData = await new web3.eth.Contract(registration.arcVotingMachineCallbacksMock.abi) .methods - .initialize(testSetup.org.avatar.address, accounts[0]) + .initialize((avatarZero ? helpers.NULL_ADDRESS : testSetup.org.avatar.address), accounts[0]) .encodeABI(); var permissions = "0x00000000"; @@ -34,15 +34,26 @@ const setup = async function (accounts) { "metaData", {from:testSetup.proxyAdmin}); - testSetup.arcVotingMachineCallbacksMock = await ARCVotingMachineCallbacksMock.at(tx.logs[1].args._scheme); + if (!avatarZero) { + testSetup.arcVotingMachineCallbacksMock = await ARCVotingMachineCallbacksMock.at(tx.logs[1].args._scheme); - await testSetup.arcVotingMachineCallbacksMock.propose(proposalId); - - - return testSetup; + await testSetup.arcVotingMachineCallbacksMock.propose(proposalId); + + + return testSetup; + } }; contract('VotingMachineCallbacks', function(accounts) { + it("avatar address cannot be 0 ", async function() { + try { + await setup(accounts, true); + assert(false, "avatar 0 address should revert"); + } catch(error) { + // revert + } + }); + it("getTotalReputationSupply & reputationOf ", async function() { var testSetup = await setup(accounts); assert.equal(await testSetup.arcVotingMachineCallbacksMock.getTotalReputationSupply(proposalId),1000);