Skip to content

Commit

Permalink
only register scheme can propose and be voted (#805)
Browse files Browse the repository at this point in the history
* only register scheme can propose

* Test

* bump v

Co-authored-by: benk10 <[email protected]>
Co-authored-by: benk10 <[email protected]>
  • Loading branch information
3 people authored Nov 12, 2020
1 parent 0678502 commit d316bd7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
21 changes: 19 additions & 2 deletions contracts/votingMachines/VotingMachineCallbacks.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "../universalSchemes/UniversalScheme.sol";
import "@daostack/infra/contracts/votingMachines/GenesisProtocol.sol";



contract VotingMachineCallbacks is VotingMachineCallbacksInterface {

struct ProposalInfo {
Expand All @@ -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;

Expand Down Expand Up @@ -67,15 +76,23 @@ 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;
}
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;
Expand Down
2 changes: 1 addition & 1 deletion 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.48",
"version": "0.0.1-rc.49",
"description": "A platform for building DAOs",
"files": [
"contracts/",
Expand Down
23 changes: 23 additions & 0 deletions test/schemeregistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d316bd7

Please sign in to comment.