Add Governor module for governance-settable parameters (#2904)
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
This commit is contained in:
@ -822,4 +822,125 @@ contract('Governor', function (accounts) {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Settings update', function () {
|
||||
describe('setVotingDelay', function () {
|
||||
beforeEach(async function () {
|
||||
this.settings = {
|
||||
proposal: [
|
||||
[ this.mock.address ],
|
||||
[ web3.utils.toWei('0') ],
|
||||
[ this.mock.contract.methods.setVotingDelay('0').encodeABI() ],
|
||||
'<proposal description>',
|
||||
],
|
||||
tokenHolder: owner,
|
||||
voters: [
|
||||
{ voter: voter1, weight: web3.utils.toWei('10'), support: Enums.VoteType.For },
|
||||
],
|
||||
};
|
||||
});
|
||||
afterEach(async function () {
|
||||
expect(await this.mock.votingDelay()).to.be.bignumber.equal('0');
|
||||
|
||||
expectEvent(
|
||||
this.receipts.execute,
|
||||
'VotingDelaySet',
|
||||
{ oldVotingDelay: '4', newVotingDelay: '0' },
|
||||
);
|
||||
});
|
||||
runGovernorWorkflow();
|
||||
});
|
||||
|
||||
describe('setVotingPeriod', function () {
|
||||
beforeEach(async function () {
|
||||
this.settings = {
|
||||
proposal: [
|
||||
[ this.mock.address ],
|
||||
[ web3.utils.toWei('0') ],
|
||||
[ this.mock.contract.methods.setVotingPeriod('32').encodeABI() ],
|
||||
'<proposal description>',
|
||||
],
|
||||
tokenHolder: owner,
|
||||
voters: [
|
||||
{ voter: voter1, weight: web3.utils.toWei('10'), support: Enums.VoteType.For },
|
||||
],
|
||||
};
|
||||
});
|
||||
afterEach(async function () {
|
||||
expect(await this.mock.votingPeriod()).to.be.bignumber.equal('32');
|
||||
|
||||
expectEvent(
|
||||
this.receipts.execute,
|
||||
'VotingPeriodSet',
|
||||
{ oldVotingPeriod: '16', newVotingPeriod: '32' },
|
||||
);
|
||||
});
|
||||
runGovernorWorkflow();
|
||||
});
|
||||
|
||||
describe('setVotingPeriod to 0', function () {
|
||||
beforeEach(async function () {
|
||||
this.settings = {
|
||||
proposal: [
|
||||
[ this.mock.address ],
|
||||
[ web3.utils.toWei('0') ],
|
||||
[ this.mock.contract.methods.setVotingPeriod('0').encodeABI() ],
|
||||
'<proposal description>',
|
||||
],
|
||||
tokenHolder: owner,
|
||||
voters: [
|
||||
{ voter: voter1, weight: web3.utils.toWei('10'), support: Enums.VoteType.For },
|
||||
],
|
||||
steps: {
|
||||
execute: { error: 'GovernorSettings: voting period too low' },
|
||||
},
|
||||
};
|
||||
});
|
||||
afterEach(async function () {
|
||||
expect(await this.mock.votingPeriod()).to.be.bignumber.equal('16');
|
||||
});
|
||||
runGovernorWorkflow();
|
||||
});
|
||||
|
||||
describe('setProposalThreshold', function () {
|
||||
beforeEach(async function () {
|
||||
this.settings = {
|
||||
proposal: [
|
||||
[ this.mock.address ],
|
||||
[ web3.utils.toWei('0') ],
|
||||
[ this.mock.contract.methods.setProposalThreshold('1000000000000000000').encodeABI() ],
|
||||
'<proposal description>',
|
||||
],
|
||||
tokenHolder: owner,
|
||||
voters: [
|
||||
{ voter: voter1, weight: web3.utils.toWei('10'), support: Enums.VoteType.For },
|
||||
],
|
||||
};
|
||||
});
|
||||
afterEach(async function () {
|
||||
expect(await this.mock.proposalThreshold()).to.be.bignumber.equal('1000000000000000000');
|
||||
|
||||
expectEvent(
|
||||
this.receipts.execute,
|
||||
'ProposalThresholdSet',
|
||||
{ oldProposalThreshold: '0', newProposalThreshold: '1000000000000000000' },
|
||||
);
|
||||
});
|
||||
runGovernorWorkflow();
|
||||
});
|
||||
|
||||
describe('update protected', function () {
|
||||
it('setVotingDelay', async function () {
|
||||
await expectRevert(this.mock.setVotingDelay('0'), 'Governor: onlyGovernance');
|
||||
});
|
||||
|
||||
it('setVotingPeriod', async function () {
|
||||
await expectRevert(this.mock.setVotingPeriod('32'), 'Governor: onlyGovernance');
|
||||
});
|
||||
|
||||
it('setProposalThreshold', async function () {
|
||||
await expectRevert(this.mock.setProposalThreshold('1000000000000000000'), 'Governor: onlyGovernance');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -21,7 +21,7 @@ contract('GovernorComp', function (accounts) {
|
||||
beforeEach(async function () {
|
||||
this.owner = owner;
|
||||
this.token = await Token.new(tokenName, tokenSymbol);
|
||||
this.mock = await Governor.new(name, this.token.address, 4, 16);
|
||||
this.mock = await Governor.new(name, this.token.address);
|
||||
this.receiver = await CallReceiver.new();
|
||||
await this.token.mint(owner, tokenSupply);
|
||||
await this.token.delegate(voter1, { from: voter1 });
|
||||
|
||||
@ -51,6 +51,10 @@ contract('GovernorTimelockCompound', function (accounts) {
|
||||
'GovernorTimelock',
|
||||
]);
|
||||
|
||||
it('doesn\'t accept ether transfers', async function () {
|
||||
await expectRevert.unspecified(web3.eth.sendTransaction({ from: voter, to: this.mock.address, value: 1 }));
|
||||
});
|
||||
|
||||
it('post deployment check', async function () {
|
||||
expect(await this.mock.name()).to.be.equal(name);
|
||||
expect(await this.mock.token()).to.be.equal(this.token.address);
|
||||
|
||||
@ -45,6 +45,10 @@ contract('GovernorTimelockControl', function (accounts) {
|
||||
'GovernorTimelock',
|
||||
]);
|
||||
|
||||
it('doesn\'t accept ether transfers', async function () {
|
||||
await expectRevert.unspecified(web3.eth.sendTransaction({ from: voter, to: this.mock.address, value: 1 }));
|
||||
});
|
||||
|
||||
it('post deployment check', async function () {
|
||||
expect(await this.mock.name()).to.be.equal(name);
|
||||
expect(await this.mock.token()).to.be.equal(this.token.address);
|
||||
|
||||
Reference in New Issue
Block a user