Skip to content

add dictator.sol #752

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

Merged
merged 3 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
36 changes: 36 additions & 0 deletions contracts/schemes/Dictator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pragma solidity ^0.5.17;

import "../controller/Avatar.sol";
import "../controller/Controller.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/ownership/Ownable.sol";

/**
* @title A scheme for register other scheme with full permission.
*/

contract Dictator is Initializable, Ownable {

Avatar public avatar;

/**
* @dev registerScheme
* @param _scheme the scheme to register (with full permission)
*/
function registerScheme(address _scheme) external onlyOwner {
//register a scheme with full permission :)
require(Controller(avatar.owner()).registerScheme(_scheme, 0x0000001f), "Fail to register scheme");
}

/**
* @dev _initialize
* @param _avatar the scheme avatar
* @param _owner the contract owner
*/
function initialize(Avatar _avatar, address _owner) public initializer {
Copy link
Contributor

@ben-kaufman ben-kaufman May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not register the owner as admin right away in the initialize and then unregister self?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the initialize function is called as the process of instance the scheme before the scheme is registered .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right, so nevermind

require(address(_avatar) != address(0), "Scheme must have avatar");
Ownable.initialize(_owner);
avatar = _avatar;
}

}
81 changes: 81 additions & 0 deletions test/dictator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const helpers = require("./helpers");
const Controller = artifacts.require("./Controller.sol");
const Dictator = artifacts.require("./Dictator.sol");


class DictatorParams {
constructor() {
}
}

var registration;
const setupDictator = async function(_avatarAddress,_owner) {
var dictatorParams = new DictatorParams();
dictatorParams.initdata = await new web3.eth.Contract(registration.dictator.abi)
.methods
.initialize(_avatarAddress,_owner)
.encodeABI();

return dictatorParams;
};

const setup = async function (accounts) {
var testSetup = new helpers.TestSetup();
registration = await helpers.registerImplementation();
testSetup.reputationArray = [2000,4000,7000];
testSetup.proxyAdmin = accounts[5];
testSetup.org = await helpers.setupOrganizationWithArraysDAOFactory(testSetup.proxyAdmin,
accounts,
registration,
[accounts[0],
accounts[1],
accounts[2]],
[1000,0,0],
testSetup.reputationArray);
testSetup.owner = accounts[4];
testSetup.dictatorParams= await setupDictator(
testSetup.org.avatar.address,
testSetup.owner
);
var permissions = "0x0000001f";

var tx = await registration.daoFactory.setSchemes(
testSetup.org.avatar.address,
[web3.utils.fromAscii("Dictator")],
testSetup.dictatorParams.initdata,
[helpers.getBytesLength(testSetup.dictatorParams.initdata)],
[permissions],
"metaData",{from:testSetup.proxyAdmin});

testSetup.dictator = await Dictator.at(tx.logs[1].args._scheme);

return testSetup;
};
contract('Dictator', accounts => {

it("register scheme", async function() {
var testSetup = await setup(accounts);
var controllerAddress = await testSetup.org.avatar.owner();
var controller = await Controller.at(controllerAddress);
assert.equal((await controller.schemesPermissions(accounts[3])), "0x00000000");
try {
await testSetup.dictator.registerScheme(accounts[3]);
assert(false, "only owner can register scheme");
} catch(error) {
helpers.assertVMException(error);
}
var tx = await testSetup.dictator.registerScheme(accounts[3],{from:testSetup.owner});

await controller.getPastEvents('RegisterScheme', {
fromBlock: tx.blockNumber,
toBlock: 'latest'
})
.then(function(events){
assert.equal(events[0].event,"RegisterScheme");
assert.equal(events[0].args._scheme,accounts[3]);
});
assert.equal((await controller.schemesPermissions(accounts[3])), "0x0000001f");

});

});
5 changes: 5 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const VoteInOrganization = artifacts.require("./VoteInOrganizationScheme.sol");
const ARCVotingMachineCallbacksMock = artifacts.require("./ARCVotingMachineCallbacksMock.sol");
const JoinAndQuit = artifacts.require("./JoinAndQuit.sol");
const FundingRequest = artifacts.require("./FundingRequest.sol");
const Dictator = artifacts.require("./Dictator.sol");


const MAX_UINT_256 = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';
Expand Down Expand Up @@ -155,6 +156,8 @@ const SOME_ADDRESS = '0x1000000000000000000000000000000000000000';
registration.joinAndQuit = await JoinAndQuit.new();
registration.fundingRequest = await FundingRequest.new();
registration.rewarderMock = await RewarderMock.new();
registration.dictator = await Dictator.new();


await implementationDirectory.setImplementation("DAOToken",registration.daoToken.address);
await implementationDirectory.setImplementation("Reputation",registration.reputation.address);
Expand Down Expand Up @@ -184,6 +187,8 @@ const SOME_ADDRESS = '0x1000000000000000000000000000000000000000';
await implementationDirectory.setImplementation("ARCVotingMachineCallbacksMock",registration.arcVotingMachineCallbacksMock.address);
await implementationDirectory.setImplementation("JoinAndQuit",registration.joinAndQuit.address);
await implementationDirectory.setImplementation("FundingRequest",registration.fundingRequest.address);
await implementationDirectory.setImplementation("Dictator",registration.dictator.address);


registration.implementationDirectory = implementationDirectory;

Expand Down