Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can propose only on registered scheme #802

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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