From d316bd768e69fc52751a20af2504ed242a47b7b9 Mon Sep 17 00:00:00 2001 From: orenyodfat Date: Thu, 12 Nov 2020 19:25:28 +0200 Subject: [PATCH] only register scheme can propose and be voted (#805) * only register scheme can propose * Test * bump v Co-authored-by: benk10 Co-authored-by: benk10 --- .../votingMachines/VotingMachineCallbacks.sol | 21 +++++++++++++++-- package-lock.json | 2 +- package.json | 2 +- test/schemeregistrar.js | 23 +++++++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/contracts/votingMachines/VotingMachineCallbacks.sol b/contracts/votingMachines/VotingMachineCallbacks.sol index 99d4dcfb..499c0976 100644 --- a/contracts/votingMachines/VotingMachineCallbacks.sol +++ b/contracts/votingMachines/VotingMachineCallbacks.sol @@ -4,6 +4,7 @@ import "../universalSchemes/UniversalScheme.sol"; import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol"; + contract VotingMachineCallbacks is VotingMachineCallbacksInterface { struct ProposalInfo { @@ -16,6 +17,14 @@ contract VotingMachineCallbacks is VotingMachineCallbacksInterface { _; } + modifier onlyRegisteredScheme(bytes32 _proposalId) { + Avatar avatar = proposalsInfo[msg.sender][_proposalId].avatar; + require(Controller(avatar.owner()).isSchemeRegistered(address(this), address(avatar)), + "scheme is not registered" + ); + _; + } + // VotingMaching -> proposalId -> ProposalInfo mapping(address => mapping(bytes32 => ProposalInfo)) public proposalsInfo; @@ -67,7 +76,11 @@ contract VotingMachineCallbacks is VotingMachineCallbacksInterface { return _stakingToken.balanceOf(address(avatar)); } - function getTotalReputationSupply(bytes32 _proposalId) external view returns(uint256) { + function getTotalReputationSupply(bytes32 _proposalId) + external + view + onlyRegisteredScheme(_proposalId) + returns(uint256) { ProposalInfo memory proposal = proposalsInfo[msg.sender][_proposalId]; if (proposal.avatar == Avatar(0)) { return 0; @@ -75,7 +88,11 @@ contract VotingMachineCallbacks is VotingMachineCallbacksInterface { return proposal.avatar.nativeReputation().totalSupplyAt(proposal.blockNumber); } - function reputationOf(address _owner, bytes32 _proposalId) external view returns(uint256) { + function reputationOf(address _owner, bytes32 _proposalId) + external + view + onlyRegisteredScheme(_proposalId) + returns(uint256) { ProposalInfo memory proposal = proposalsInfo[msg.sender][_proposalId]; if (proposal.avatar == Avatar(0)) { return 0; diff --git a/package-lock.json b/package-lock.json index dfe2b937..0361a2ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.48", + "version": "0.0.1-rc.49", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f3c46468..bb30fcc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc", - "version": "0.0.1-rc.48", + "version": "0.0.1-rc.49", "description": "A platform for building DAOs", "files": [ "contracts/", diff --git a/test/schemeregistrar.js b/test/schemeregistrar.js index e5cfc469..c1a66b05 100644 --- a/test/schemeregistrar.js +++ b/test/schemeregistrar.js @@ -195,6 +195,29 @@ contract('SchemeRegistrar', accounts => { var organizationProposal = await testSetup.schemeRegistrar.organizationsProposals(testSetup.org.avatar.address,proposalId); assert.equal(organizationProposal[2],0);//proposalType }); + + it("cannot propose in removed scheme", async function() { + var testSetup = await setup(accounts); + + var tx = await testSetup.schemeRegistrar.proposeToRemoveScheme(testSetup.org.avatar.address,testSetup.schemeRegistrar.address,helpers.NULL_HASH); + var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1); + var controller = await Controller.at(await testSetup.org.avatar.owner()); + assert.equal(await controller.isSchemeRegistered(testSetup.schemeRegistrar.address,testSetup.org.avatar.address),true); + //Vote with reputation to trigger execution + await testSetup.schemeRegistrarParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]}); + assert.equal(await controller.isSchemeRegistered(testSetup.schemeRegistrar.address,testSetup.org.avatar.address),false); + //check organizationsProposals after execution + var organizationProposal = await testSetup.schemeRegistrar.organizationsProposals(testSetup.org.avatar.address,proposalId); + assert.equal(organizationProposal[2],0);//proposalType + + try { + await testSetup.schemeRegistrar.proposeToRemoveScheme(testSetup.org.avatar.address,testSetup.schemeRegistrar.address,helpers.NULL_HASH); + assert(false, "should fail to propose to unregistered scheme"); + } catch(ex){ + helpers.assertVMException(ex); + } + }); + it("execute proposeScheme and execute -yes - autoRegisterOrganization==TRUE arc scheme", async function() { var testSetup = await setup(accounts);