diff --git a/contracts/schemes/SimpleSchemeConstraints.sol b/contracts/schemes/SimpleSchemeConstraints.sol index e234efb6..da24a128 100644 --- a/contracts/schemes/SimpleSchemeConstraints.sol +++ b/contracts/schemes/SimpleSchemeConstraints.sol @@ -9,6 +9,7 @@ contract SimpleSchemeConstraints is SchemeConstraints { mapping(address=>bool) public contractsWhiteListMap; bool public initialized; + bool public enableWhitelisting; bool public enableSendEth; /* @dev initialize @@ -29,6 +30,7 @@ contract SimpleSchemeConstraints is SchemeConstraints { contractsWhiteList = _contractsWhiteList; descriptionHash = _descriptionHash; enableSendEth = _enableSendEth; + enableWhitelisting = _contractsWhiteList.length > 0; } /* @@ -47,7 +49,7 @@ contract SimpleSchemeConstraints is SchemeConstraints { returns(bool) { for (uint i = 0; i < _contractsToCall.length; i++) { - require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); + require(!enableWhitelisting || contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); if (!enableSendEth) { require(_values[i] == 0, "sending eth is not allowed"); } @@ -70,7 +72,7 @@ contract SimpleSchemeConstraints is SchemeConstraints { returns(bool) { for (uint i = 0; i < _contractsToCall.length; i++) { - require(contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); + require(!enableWhitelisting || contractsWhiteListMap[_contractsToCall[i]], "contract not whitelisted"); if (!enableSendEth) { require(_values[i] == 0, "sending eth is not allowed"); } diff --git a/contracts/utils/GenericSchemeMultiCallFactory.sol b/contracts/utils/GenericSchemeMultiCallFactory.sol index 75878f1b..2cdd8a6d 100644 --- a/contracts/utils/GenericSchemeMultiCallFactory.sol +++ b/contracts/utils/GenericSchemeMultiCallFactory.sol @@ -28,7 +28,7 @@ contract GenericSchemeMultiCallFactory { require(_voteParamsType < 4, "Vote params type specified does not exist"); GenericSchemeMultiCall genericSchemeMultiCall = new GenericSchemeMultiCall(); address simpleSchemeConstraints; - if (_contractsWhiteList.length > 0) { + if (_contractsWhiteList.length > 0 || !_enableSendEth) { simpleSchemeConstraints = address(new SimpleSchemeConstraints()); SimpleSchemeConstraints(simpleSchemeConstraints) .initialize(_contractsWhiteList, _descriptionHash, _enableSendEth); diff --git a/package-lock.json b/package-lock.json index 18b6b0cc..2a503265 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.56", + "version": "0.0.1-rc.57", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -15218,7 +15218,7 @@ } }, "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1ce6a1d64235fabe2aaf827fd606def55693508f", + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "dev": true, "requires": { diff --git a/package.json b/package.json index da17e2aa..4e7706fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.56", + "version": "0.0.1-rc.57", "description": "A platform for building DAOs", "files": [ "contracts/", diff --git a/test/genericschememulticall.js b/test/genericschememulticall.js index 1918c27a..b1e77ae0 100644 --- a/test/genericschememulticall.js +++ b/test/genericschememulticall.js @@ -211,11 +211,11 @@ contract('GenericSchemeMultiCall', function(accounts) { it("propose call siplmeConstraint -positive decision - not whitelisted contract", async function() { var actionMock =await ActionMock.new(); - var testSetup = await setup(accounts,[accounts[1]],0,false,helpers.NULL_ADDRESS,SIMPLE_SCHEME_CONSTRAINT); + var testSetup = await setup(accounts,[],0,false,helpers.NULL_ADDRESS,SIMPLE_SCHEME_CONSTRAINT, false); var callData = await createCallToActionMock(helpers.NULL_ADDRESS,actionMock); try { await testSetup.genericSchemeMultiCall.proposeCalls( - [actionMock.address],[callData],[0],helpers.NULL_HASH); + [accounts[1]],[callData],[1],helpers.NULL_HASH); assert(false, "contractToCall is not whitelisted"); } catch(error) { helpers.assertVMException(error); @@ -347,6 +347,36 @@ contract('GenericSchemeMultiCall', function(accounts) { assert.equal(await web3.eth.getBalance(actionMock.address),0); }); + it("execute proposeVote -positive decision - check action - with simpleSchemeConstraints disableSendEth and no whitelist", async function() { + var actionMock =await ActionMock.new(); + var standardTokenMock = await ERC20Mock.new(accounts[0],1000); + var testSetup = await setup(accounts,[actionMock.address],0,true,standardTokenMock.address,SIMPLE_SCHEME_CONSTRAINT,false); + var value = 50000; + var callData = await createCallToActionMock(testSetup.org.avatar.address,actionMock); + try { + await testSetup.genericSchemeMultiCall.proposeCalls([actionMock.address,actionMock.address],[callData,callData],[value,value],helpers.NULL_HASH); + assert(false, "sendEth is not allowed"); + } catch(error) { + helpers.assertVMException(error); + } + var tx = await testSetup.genericSchemeMultiCall.proposeCalls([actionMock.address,actionMock.address],[callData,callData],[0,0],helpers.NULL_HASH); + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId'); + //transfer some eth to avatar + await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value: web3.utils.toWei('1', "ether")}); + assert.equal(await web3.eth.getBalance(actionMock.address),0); + await testSetup.genericSchemeParams.votingMachine.genesisProtocol.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); + tx = await testSetup.genericSchemeMultiCall.execute(proposalId); + await testSetup.genericSchemeMultiCall.getPastEvents('ProposalExecuted', { + fromBlock: tx.blockNumber, + toBlock: 'latest' + }) + .then(function(events){ + assert.equal(events[0].event,"ProposalExecuted"); + assert.equal(events[0].args._proposalId,proposalId); + }); + assert.equal(await web3.eth.getBalance(actionMock.address),0); + }); + it("redeemer should fail if not executed from votingMachine", async function() { var actionMock =await ActionMock.new(); var standardTokenMock = await ERC20Mock.new(accounts[0],1000); diff --git a/test/genericschememulticallfactory.js b/test/genericschememulticallfactory.js index e16f2715..25f95d93 100644 --- a/test/genericschememulticallfactory.js +++ b/test/genericschememulticallfactory.js @@ -124,4 +124,59 @@ contract('genericSchemeMultiCallFactory', function(accounts) { }); + it('initialize - sendEth disabled', async () => { + let testSetup = await setup(); + let votingMachine = await helpers.setupGenesisProtocol(accounts,helpers.SOME_ADDRESS,0,helpers.NULL_ADDRESS); + + for (let i=0; i < 4; i++) { + let address = await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple.call( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + i, + (i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + helpers.NULL_ADDRESS, + (i === 0 ? [helpers.SOME_ADDRESS] : []), + false, + '0x0' + ); + + await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + i, + (i === 0 ? params[0] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), + helpers.NULL_ADDRESS, + (i === 0 ? [helpers.SOME_ADDRESS] : []), + false, + '0x0' + ); + + let genericSchemeMultiCall = await GenericSchemeMultiCall.at(address); + assert.equal(await genericSchemeMultiCall.avatar(), helpers.SOME_ADDRESS); + assert.equal(await genericSchemeMultiCall.votingMachine(), votingMachine.genesisProtocol.address); + assert.equal( + await genericSchemeMultiCall.voteParams(), + await votingMachine.genesisProtocol.getParametersHash(params[i], helpers.NULL_ADDRESS) + ); + assert.notEqual(await genericSchemeMultiCall.schemeConstraints(), helpers.NULL_ADDRESS); + } + + try { + await testSetup.genericSchemeMultiCallFactory.createGenericSchemeMultiCallSimple( + helpers.SOME_ADDRESS, + votingMachine.genesisProtocol.address, + 4, + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + helpers.NULL_ADDRESS, + [], + true, + '0x0' + ); + assert(false, "Vote params type specified does not exist"); + } catch(error) { + helpers.assertVMException(error); + } + + }); + });