Skip to content

Commit

Permalink
Support GSMC factory no whitelist and ETH disabled (#820)
Browse files Browse the repository at this point in the history
* Support GSMC factory no whitelist and ETH disabled

* Bump version
  • Loading branch information
ben-kaufman authored Apr 8, 2021
1 parent 7708b4f commit 532183b
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 8 deletions.
6 changes: 4 additions & 2 deletions contracts/schemes/SimpleSchemeConstraints.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ contract SimpleSchemeConstraints is SchemeConstraints {

mapping(address=>bool) public contractsWhiteListMap;
bool public initialized;
bool public enableWhitelisting;
bool public enableSendEth;

/* @dev initialize
Expand All @@ -29,6 +30,7 @@ contract SimpleSchemeConstraints is SchemeConstraints {
contractsWhiteList = _contractsWhiteList;
descriptionHash = _descriptionHash;
enableSendEth = _enableSendEth;
enableWhitelisting = _contractsWhiteList.length > 0;
}

/*
Expand All @@ -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");
}
Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/GenericSchemeMultiCallFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
34 changes: 32 additions & 2 deletions test/genericschememulticall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
55 changes: 55 additions & 0 deletions test/genericschememulticallfactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

});

});

0 comments on commit 532183b

Please sign in to comment.