Skip to content

Commit

Permalink
DPX-18, DPF-01, DXO-01
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed Jun 10, 2024
1 parent 560fd8f commit 61847df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
16 changes: 5 additions & 11 deletions packages/contracts/src/DaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
uint256 _electionPeriodIndex,
uint256 _proposalType,
uint256 _allowFailureMap,
VoteOption _voteOption
VoteOption
) external payable returns (uint256 _proposalId) {
// Cache msg.sender
address proposer = _msgSender();
Expand Down Expand Up @@ -179,11 +179,6 @@ contract DaofinPlugin is BaseDaofinPlugin {
// Map proposal ID to PropsalType ID
_proposals[_proposalId].proposalTypeId = _proposalType;
emit ProposalIdToProposalTypeIdAttached(_proposalId, _proposalType);

// Checks the proposer address
// if a valid voter comes, stores vote info,
// otherwise reverts.
_updateVote(_proposalId, proposer, _voteOption);
}

function _createProposal(
Expand Down Expand Up @@ -239,7 +234,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
TallyDatails memory td = getProposalTallyDetails(proposalId_, committee);

uint256 votingPower = 1;

td.name = committee;
// Exception for House
if (committee == PeoplesHouseCommittee) {
votingPower = _voterToLockedAmounts[voter_].amount / (10 ** 18);
Expand Down Expand Up @@ -450,7 +445,6 @@ contract DaofinPlugin is BaseDaofinPlugin {
_createProposalTypeId(),
_committeesVotingSettings
);
emit ProposalTypeCreated(proposalTypeId, _committeesVotingSettings);
}

function modifyProposalType(
Expand All @@ -460,7 +454,6 @@ contract DaofinPlugin is BaseDaofinPlugin {
require(proposalTypeCount() > _proposalTypeId, "Invalid PT");

proposalTypeId = _createOrModifyProposalType(_proposalTypeId, _committeesVotingSettings);
emit ProposalTypeCreated(proposalTypeId, _committeesVotingSettings);
}

function _createOrModifyProposalType(
Expand All @@ -481,6 +474,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
committeeName
] = _committeesVotingSettings[i];
}
emit ProposalTypeCreated(_proposalTypeId, _committeesVotingSettings);
return _proposalTypeId;
}

Expand Down Expand Up @@ -630,7 +624,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
(, bool executed, address proposer, ) = getProposal(_proposalId);

// Proposal must be before election its attached election period.
if (block.timestamp > _proposals[_proposalId].startDate || executed) revert InValidTime();
if (block.timestamp > _proposals[_proposalId].startDate) revert InValidTime();

// Only proposer address is able to modify metadata.
if (proposer != _msgSender()) revert InValidAddress();
Expand Down Expand Up @@ -738,7 +732,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
yesVotes >=
_applyRatioCeiled(getTotalNumberOfMembersByCommittee(committee), supportThreshold);
if (!isValid) return false;
if (yesVotes < noVotes) return false;
if (noVotes != 0 && noVotes >= yesVotes) return false;
}
return true;
}
Expand Down
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 @@ -47,6 +49,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 @@ -63,11 +67,13 @@ 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(); //Math.floor(Date.now() / 1000);

initializeParams = [
dao.address,
Expand Down Expand Up @@ -158,7 +164,6 @@ describe(PLUGIN_CONTRACT_NAME, function () {
])
).to.not.reverted;
const after = await daofinPlugin.proposalTypeCount();

expect(before.add(1)).eq(after);
});
it('must revert due to un-ordered committee settings list', async () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/contracts/test/unit-testing/daofin/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
createCommitteeVotingSettings(PeoplesHouseCommittee, '0', '0', '1'),
createCommitteeVotingSettings(
JudiciaryCommittee,
'200000',
'500000',
'400000',
'1'
),
Expand Down Expand Up @@ -274,15 +274,15 @@ describe(PLUGIN_CONTRACT_NAME, function () {

await daofinPlugin.connect(Bob).vote(proposalId, '2', false);

await expect(daofinPlugin.execute(proposalId)).to.reverted;
await expect(daofinPlugin.execute(proposalId)).reverted;

await daofinPlugin.connect(John).vote(proposalId, '2', false);
await daofinPlugin.connect(Alice).vote(proposalId, '2', false);
await daofinPlugin.connect(Mike).vote(proposalId, '2', false);

await advanceTime(ethers, convertDaysToSeconds(4));

await expect(daofinPlugin.execute(proposalId)).not.be.reverted;
await expect(daofinPlugin.execute(proposalId)).not.reverted;
});
it('must not be able to execute due to lack of YES votes', async () => {
await dao.grant(dao.address, daofinPlugin.address, EXECUTE_PERMISSION_ID);
Expand All @@ -294,7 +294,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

await advanceTime(ethers, convertDaysToSeconds(4));

await expect(daofinPlugin.execute(proposalId)).to.reverted;
await expect(daofinPlugin.execute(proposalId)).reverted;
});
});
describe('Execute only for Senate', async () => {
Expand Down Expand Up @@ -393,17 +393,17 @@ describe(PLUGIN_CONTRACT_NAME, function () {

await advanceTime(ethers, convertDaysToSeconds(4));

await expect(daofinPlugin.execute(proposalId)).not.be.reverted;
await expect(daofinPlugin.execute(proposalId)).not.reverted;
});
it('must not be able to execute due to lack of YES votes', async () => {
await dao.grant(dao.address, daofinPlugin.address, EXECUTE_PERMISSION_ID);

await daofinPlugin.connect(Tony).vote(proposalId, '2', false);
await daofinPlugin.connect(John).vote(proposalId, '1', false);
await daofinPlugin.connect(Tony).vote(proposalId, '1', false);
await daofinPlugin.connect(John).vote(proposalId, '3', false);

await advanceTime(ethers, convertDaysToSeconds(4));

await expect(daofinPlugin.execute(proposalId)).not.be.reverted;
await expect(daofinPlugin.execute(proposalId)).reverted;
});
});
});

0 comments on commit 61847df

Please sign in to comment.