Skip to content

Commit

Permalink
update unit-tests & added edit-proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed May 13, 2024
1 parent 6d2d0e5 commit 07e8909
Show file tree
Hide file tree
Showing 13 changed files with 696 additions and 30 deletions.
3 changes: 1 addition & 2 deletions packages/contracts/test/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export function createCommitteeVotingSettings(
name: PromiseOrValue<BytesLike>,
qourum: BigNumberish,
threshold: BigNumberish,
votingPower: BigNumberish
_: BigNumberish
): BaseDaofinPlugin.CommitteeVotingSettingsStruct {
return {
name,
minParticipation: qourum,
supportThreshold: threshold,
minVotingPower: votingPower,
};
}

Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/test/unit-testing/daofin-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export const EXECUTE_PERMISSION_ID = ethers.utils.id('EXECUTE_PERMISSION');
export const CREATE_PROPOSAL_TYPE_PERMISSION_ID = ethers.utils.id(
'CREATE_PROPOSAL_TYPE_PERMISSION'
);
export const MODIFY_PROPOSAL_TYPE_PERMISSION_ID = ethers.utils.id(
'MODIFY_PROPOSAL_TYPE_PERMISSION'
);
export const UPDATE_PROPOSAL_COSTS_PERMISSION_ID = ethers.utils.id(
'UPDATE_PROPOSAL_COSTS_PERMISSION'
);
Expand Down
5 changes: 2 additions & 3 deletions packages/contracts/test/unit-testing/daofin-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
UPDATE_PROPOSAL_COSTS_PERMISSION_ID,
abiCoder,
UPDATE_ELECTION_PERIOD_PERMISSION_ID,
MODIFY_PROPOSAL_TYPE_PERMISSION_ID,
} from './daofin-common';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {expect} from 'chai';
Expand All @@ -38,8 +39,6 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
let dao: DAO;
let initializeParams: Parameters<DaofinPlugin['initialize']>;
let initData: string;
let Alice: SignerWithAddress;
let xdcValidatorMock: XDCValidator;

before(async () => {
signers = await ethers.getSigners();
Expand All @@ -52,7 +51,6 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
dao = await deployTestDao(Alice);

const now = Math.floor(new Date().getTime() / 1000);

initializeParams = [
dao.address,
parseEther('1'),
Expand Down Expand Up @@ -112,6 +110,7 @@ describe(PLUGIN_SETUP_CONTRACT_NAME, function () {
EXECUTE_PERMISSION_ID,
CREATE_PROPOSAL_TYPE_PERMISSION_ID,
UPDATE_PROPOSAL_COSTS_PERMISSION_ID,
MODIFY_PROPOSAL_TYPE_PERMISSION_ID,
];
expect(preparedData.preparedSetupData.permissions.length).be.eq(
allPermissions.length
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import {DaofinPluginSetupParams} from '../../../plugin-settings';
import {
DaofinPlugin,
DaofinPlugin__factory,
XDCValidator,
} from '../../../typechain';
import {deployWithProxy} from '../../../utils/helpers';
import {deployTestDao} from '../../helpers/test-dao';
import {deployXDCValidator} from '../../helpers/test-xdc-validator';
import {
advanceTime,
convertDaysToSeconds,
createCommitteeVotingSettings,
createProposalParams,
} from '../../helpers/utils';
import {
ADDRESS_ONE,
ADDRESS_ZERO,
CREATE_PROPOSAL_TYPE_PERMISSION_ID,
JudiciaryCommittee,
MODIFY_PROPOSAL_TYPE_PERMISSION_ID,
MasterNodeCommittee,
PeoplesHouseCommittee,
UPDATE_JUDICIARY_MAPPING_PERMISSION_ID,
XdcValidator,
} from '../daofin-common';
import {SignerWithAddress} from '@nomiclabs/hardhat-ethers/signers';
import {DAO, RatioTest, RatioTest__factory} from '@xinfin/osx-ethers';
import {expect} from 'chai';
import {BigNumber} from 'ethers';
import {parseEther} from 'ethers/lib/utils';
import {ethers, network} from 'hardhat';

const {PLUGIN_CONTRACT_NAME} = DaofinPluginSetupParams;

describe(PLUGIN_CONTRACT_NAME, function () {
let signers: SignerWithAddress[];
let dao: DAO;
let DaofinPlugin: DaofinPlugin__factory;
let daofinPlugin: DaofinPlugin;
let initializeParams: Parameters<DaofinPlugin['initialize']>;
let createPropsalParams: Parameters<DaofinPlugin['createProposal']>;
let Alice: SignerWithAddress;
let Bob: SignerWithAddress;
let Mike: SignerWithAddress;
let John: SignerWithAddress;
let Beny: SignerWithAddress;
let xdcValidatorMock: XDCValidator;
let ratio: RatioTest;
before(async () => {
signers = await ethers.getSigners();
Alice = signers[0];
Bob = signers[1];
Mike = signers[2];
John = signers[3];
Beny = signers[4];

dao = await deployTestDao(Alice);

DaofinPlugin = new DaofinPlugin__factory(Alice);

const RatioTest = new RatioTest__factory(Alice);
ratio = await RatioTest.deploy();

xdcValidatorMock = await deployXDCValidator(Alice);

await xdcValidatorMock.addCandidate(Bob.address);
await xdcValidatorMock.addCandidate(Mike.address);
});

beforeEach(async () => {
daofinPlugin = await deployWithProxy<DaofinPlugin>(DaofinPlugin);
const now = Math.floor(new Date().getTime() / 1000);

initializeParams = [
dao.address,
parseEther('1'),
xdcValidatorMock.address,
[
createCommitteeVotingSettings(
MasterNodeCommittee,
'400000',
'200000',
parseEther('1')
),
createCommitteeVotingSettings(
PeoplesHouseCommittee,
'900000',
'400000',
parseEther('1')
),
createCommitteeVotingSettings(
JudiciaryCommittee,
'700000',
'300000',
parseEther('1')
),
],
[
createCommitteeVotingSettings(
MasterNodeCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
PeoplesHouseCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
JudiciaryCommittee,
'100000',
'100000',
parseEther('1')
),
],
[
BigNumber.from(now + 60 * 60 * 24 * 3),
BigNumber.from(now + 60 * 60 * 24 * 5),
],
[Bob.address],
parseEther('1'),
];
await daofinPlugin.initialize(...initializeParams);
await dao.grant(
daofinPlugin.address,
Alice.address,
CREATE_PROPOSAL_TYPE_PERMISSION_ID
);
await dao.grant(
daofinPlugin.address,
Alice.address,
MODIFY_PROPOSAL_TYPE_PERMISSION_ID
);
});
describe('Create ProposalType', async () => {
it('proposal type count', async () => {
const before = await daofinPlugin.proposalTypeCount();
await expect(
daofinPlugin.createProposalType([
createCommitteeVotingSettings(
MasterNodeCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
PeoplesHouseCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
JudiciaryCommittee,
'100000',
'100000',
parseEther('1')
),
])
).to.not.reverted;
const after = await daofinPlugin.proposalTypeCount();

expect(before.add(1)).eq(after);
});
it('create Proposal Type', async () => {
const before = await daofinPlugin.proposalTypeCount();
await expect(
daofinPlugin.createProposalType([
createCommitteeVotingSettings(
MasterNodeCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
PeoplesHouseCommittee,
'100000',
'100000',
parseEther('1')
),
createCommitteeVotingSettings(
JudiciaryCommittee,
'100000',
'100000',
parseEther('1')
),
])
).to.not.reverted;
const after = await daofinPlugin.proposalTypeCount();

expect(before.add(1)).eq(after);
});
});
describe('Modify ProposalType', async () => {
it('Modify Proposal Type', async () => {
const before = await daofinPlugin.proposalTypeCount();
const proposalType = '1';

await expect(
daofinPlugin.modifyProposalType(proposalType, [
createCommitteeVotingSettings(
MasterNodeCommittee,
'500000',
'600000',
parseEther('1')
),
createCommitteeVotingSettings(
PeoplesHouseCommittee,
'700000',
'900000',
parseEther('1')
),
createCommitteeVotingSettings(
JudiciaryCommittee,
'300000',
'200000',
parseEther('1')
),
])
).not.reverted;

const after = await daofinPlugin.proposalTypeCount();
expect(before).eq(after);

const jurySettingsAfter =
await daofinPlugin.getCommitteesToVotingSettings(
proposalType,
JudiciaryCommittee
);
expect(jurySettingsAfter.minParticipation).equal(300000);
expect(jurySettingsAfter.supportThreshold).equal(200000);

const mnSettingsAfter = await daofinPlugin.getCommitteesToVotingSettings(
proposalType,
MasterNodeCommittee
);
expect(mnSettingsAfter.minParticipation).equal(500000);
expect(mnSettingsAfter.supportThreshold).equal(600000);

const peopleSettingsAfter =
await daofinPlugin.getCommitteesToVotingSettings(
proposalType,
PeoplesHouseCommittee
);
expect(peopleSettingsAfter.minParticipation).equal(700000);
expect(peopleSettingsAfter.supportThreshold).equal(900000);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import {DaofinPluginSetupParams} from '../../../plugin-settings';
import {
DaofinPlugin,
DaofinPlugin__factory,
MockTimestampOracle,
MockTimestampOracle__factory,
XDCValidator,
} from '../../../typechain';
import {deployWithProxy} from '../../../utils/helpers';
Expand Down Expand Up @@ -43,6 +45,8 @@ describe(PLUGIN_CONTRACT_NAME, function () {
let Beny: SignerWithAddress;
let xdcValidatorMock: XDCValidator;
let ratio: RatioTest;
let MockTimestampOracle: MockTimestampOracle__factory;
let mockTimestampOracle: MockTimestampOracle;
before(async () => {
signers = await ethers.getSigners();
Alice = signers[0];
Expand All @@ -58,16 +62,18 @@ describe(PLUGIN_CONTRACT_NAME, function () {
ratio = await RatioTest.deploy();

xdcValidatorMock = await deployXDCValidator(Alice);
MockTimestampOracle = new MockTimestampOracle__factory(Alice);
mockTimestampOracle = await MockTimestampOracle.deploy();
});

beforeEach(async () => {
daofinPlugin = await deployWithProxy<DaofinPlugin>(DaofinPlugin);
const now = Math.floor(new Date().getTime() / 1000);
const now = (await mockTimestampOracle.getUint64Timestamp()).toNumber();

initializeParams = [
dao.address,
parseEther('1'),
XdcValidator,
xdcValidatorMock.address,
[
createCommitteeVotingSettings(
MasterNodeCommittee,
Expand Down Expand Up @@ -114,7 +120,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
BigNumber.from(now + 60 * 60 * 24 * 6),
BigNumber.from(now + 60 * 60 * 24 * 8),
],
[ADDRESS_ONE],
[Alice.address],
'1',
];
await daofinPlugin.initialize(...initializeParams);
Expand Down
Loading

0 comments on commit 07e8909

Please sign in to comment.