Skip to content

Commit

Permalink
can propose only on registered scheme (#802)
Browse files Browse the repository at this point in the history
* only registered scheme can propose

* tests

* Update schemefactory.js
  • Loading branch information
orenyodfat authored Oct 28, 2020
1 parent 2080f9e commit b89ba5c
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/schemes/ContributionReward.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ contract ContributionReward is
address payable _beneficiary
)
public
onlyRegisteredScheme
returns(bytes32)
{
validateProposalParams(_reputationChange, _rewards);
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/ContributionRewardExt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ contract ContributionRewardExt is VotingMachineCallbacks, ProposalExecuteInterfa
address _proposer
)
public
onlyRegisteredScheme
returns(bytes32 proposalId)
{
address proposer = _proposer;
Expand Down
2 changes: 2 additions & 0 deletions contracts/schemes/ControllerUpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
*/
function proposeUpgrade(address _newController, string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
Expand Down Expand Up @@ -138,6 +139,7 @@ contract ControllerUpgradeScheme is VotingMachineCallbacks, ProposalExecuteInter
string memory _descriptionHash
)
public
onlyRegisteredScheme
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/GenericScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ contract GenericScheme is VotingMachineCallbacks, ProposalExecuteInterface {
*/
function proposeCall(bytes memory _callData, uint256 _value, string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/GlobalConstraintRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ contract GlobalConstraintRegistrar is VotingMachineCallbacks, ProposalExecuteInt
bytes32 _voteToRemoveParams,
string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
bytes32 proposalId = votingMachine.propose(2, voteParamsHash, msg.sender, address(avatar));
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/Join.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ contract Join is
uint256 _feeAmount
)
public
onlyRegisteredScheme
payable
returns(bytes32)
{
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/SchemeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ contract SchemeFactory is VotingMachineCallbacks, ProposalExecuteInterface {
string memory _descriptionHash
)
public
onlyRegisteredScheme
returns(bytes32)
{
if (bytes(_schemeName).length > 0) {
Expand Down
2 changes: 2 additions & 0 deletions contracts/schemes/SchemeRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ contract SchemeRegistrar is VotingMachineCallbacks, ProposalExecuteInterface {
string memory _descriptionHash
)
public
onlyRegisteredScheme
returns(bytes32)
{
// propose
Expand Down Expand Up @@ -184,6 +185,7 @@ contract SchemeRegistrar is VotingMachineCallbacks, ProposalExecuteInterface {
*/
function proposeToRemoveScheme(address _scheme, string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
require(_scheme != address(0), "scheme cannot be zero");
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/SignalScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract SignalScheme is VotingMachineCallbacks, ProposalExecuteInterface {
string calldata _descriptionHash
)
external
onlyRegisteredScheme
returns(bytes32)
{
require(Controller(avatar.owner()).isSchemeRegistered(address(this)),
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/TokenTrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ contract TokenTrade is VotingMachineCallbacks, ProposalExecuteInterface {
string memory _descriptionHash
)
public
onlyRegisteredScheme
returns(bytes32 proposalId)
{
require(
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/UpgradeScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ contract UpgradeScheme is VotingMachineCallbacks, ProposalExecuteInterface {
address[] memory _contractsToUpgrade,
string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
require(_contractsNames.length <= 60, "can upgrade up to 60 contracts at a time");
Expand Down
1 change: 1 addition & 0 deletions contracts/schemes/VoteInOrganizationScheme.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ contract VoteInOrganizationScheme is VotingMachineCallbacks, ProposalExecuteInte
uint256 _vote,
string memory _descriptionHash)
public
onlyRegisteredScheme
returns(bytes32)
{
(uint256 minVote, uint256 maxVote) = _originalIntVote.getAllowedRangeOfChoices();
Expand Down
9 changes: 8 additions & 1 deletion contracts/votingMachines/VotingMachineCallbacks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ contract VotingMachineCallbacks is VotingMachineCallbacksInterface, ArcScheme {
_;
}

modifier onlyRegisteredScheme() {
require(Controller(avatar.owner()).isSchemeRegistered(address(this)),
"scheme is not registered"
);
_;
}

// proposalId -> blockNumber
mapping(bytes32 => uint256) public proposalsBlockNumber;

Expand Down Expand Up @@ -55,7 +62,7 @@ contract VotingMachineCallbacks is VotingMachineCallbacksInterface, ArcScheme {
}

function getTotalReputationSupply(bytes32 _proposalId)
external view onlyVotingMachine(_proposalId) override returns(uint256)
external view onlyVotingMachine(_proposalId) onlyRegisteredScheme override returns(uint256)
{
return avatar.nativeReputation().totalSupplyAt(proposalsBlockNumber[_proposalId]);
}
Expand Down
43 changes: 43 additions & 0 deletions test/schemefactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,53 @@ contract('SchemeFactory', accounts => {
var proposalId = await helpers.getValueFromLogs(tx, '_proposalId',1);
var controller = await Controller.at(await testSetup.org.avatar.owner());
assert.equal(await controller.isSchemeRegistered(testSetup.schemeFactory.address),true);
//can propose another proposal..
var initdata = await new web3.eth.Contract(registration.genericScheme.abi)
.methods
.initialize(testSetup.org.avatar.address,
testSetup.schemeFactoryParams.votingMachine.absoluteVote.address,
[0,0,0,0,0,0,0,0,0,0,0],
helpers.NULL_ADDRESS,
testSetup.schemeFactoryParams.votingMachine.params,
testSetup.org.token.address)
.encodeABI();

tx = await testSetup.schemeFactory.proposeScheme(
[0,1,0],
'GenericScheme',
initdata,
"0x0000001f",
helpers.NULL_ADDRESS,
helpers.NULL_HASH);
var proposalId2 = await helpers.getValueFromLogs(tx, '_proposalId',1);
//can vote..
await testSetup.schemeFactoryParams.votingMachine.absoluteVote.vote(proposalId2,1,0,helpers.NULL_ADDRESS,{from:accounts[0]});

tx = await testSetup.schemeFactoryParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
let proxyEvents = await registration.daoFactory.getPastEvents("ProxyCreated", {fromBlock: tx.receipt.blockNumber, toBlock: tx.receipt.blockNumber});
assert.equal(proxyEvents.length,0);
assert.equal(await controller.isSchemeRegistered(testSetup.schemeFactory.address),false);
//test if can propose on unregisted scheme -- it should not be allowed
try {
await testSetup.schemeFactory.proposeScheme(
[0,1,0],
'GenericScheme',
initdata,
"0x0000001f",
helpers.NULL_ADDRESS,
helpers.NULL_HASH);
assert(false, "cannot propose on unregisted scheme");
} catch(error) {
helpers.assertVMException(error);
}
//check that a propsoal on unregister scheme cannot be voted.
try {
await testSetup.schemeFactoryParams.votingMachine.absoluteVote.vote(proposalId2,1,0,helpers.NULL_ADDRESS,{from:accounts[0]});
assert(false, "cannot vote on a proposal for scheme which is unregistered");
} catch(error) {
helpers.assertVMException(error);
}

});

it("execute proposeScheme - no decision - proposal data delete", async function() {
Expand Down

0 comments on commit b89ba5c

Please sign in to comment.