Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbeny committed Sep 13, 2024
1 parent a93e1ee commit 048caad
Show file tree
Hide file tree
Showing 21 changed files with 188 additions and 190 deletions.
15 changes: 15 additions & 0 deletions packages/contracts/.openzeppelin/unknown-51.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@
"address": "0xBbc577aF951d3d219A256b796BBBeB4BdABa4024",
"txHash": "0xd8db386e5443d679b501bae0b284414f65098dfca9b79d97eba4efcaf55485d3",
"kind": "uups"
},
{
"address": "0xC155A078868414bD8277ceC5d247c82A81B1867a",
"txHash": "0xb3d3dc446f5c8ee73fff983471df711d77454e21360a8d7239fb41f60d5c72f1",
"kind": "uups"
},
{
"address": "0x50D82c5F94A8386a949D60F746a1233235Fb9914",
"txHash": "0x712aa65927330fb68b4768288cad3a15831f7065ffa80502a88da50e427f90f4",
"kind": "uups"
},
{
"address": "0x4F450D39e479bB2690AC56A5c26d5a8FAc1c6703",
"txHash": "0xeb0c8c008ca3870b813bb97b81b43b16614307bcddf73bc6999dfde222f393c7",
"kind": "uups"
}
],
"impls": {
Expand Down
75 changes: 0 additions & 75 deletions packages/contracts/deploy/v2/00_deploy_dao/01_create_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,81 +49,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
false
)}`;

const params = [
parseEther(daoParams.amounts),
daoParams.xdcValidatorAddress,
[
[
MasterNodeCommittee,
daoParams.masterNodeVotingSettings.supportThreshold,
daoParams.masterNodeVotingSettings.minParticipation,
],
[
PeoplesHouseCommittee,
daoParams.peoplesHouseVotingSettings.supportThreshold,
daoParams.peoplesHouseVotingSettings.minParticipation,
],
[
JudiciaryCommittee,
daoParams.judiciaryVotingSettings.supportThreshold,
daoParams.judiciaryVotingSettings.minParticipation,
],
],
[
[
MasterNodeCommittee,
daoParams.masterNodeVotingSettings.supportThreshold,
daoParams.masterNodeVotingSettings.minParticipation,
],
[
PeoplesHouseCommittee,
daoParams.peoplesHouseVotingSettings.supportThreshold,
daoParams.peoplesHouseVotingSettings.minParticipation,
],
[
JudiciaryCommittee,
daoParams.judiciaryVotingSettings.supportThreshold,
daoParams.judiciaryVotingSettings.minParticipation,
],
],
[
// 1st
BigNumber.from(Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24),
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 5
),
// 2nd
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 5
),
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 7
),
// 3rd
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 7
),
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 9
),
// 4th
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 9
),
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 11
),
// 5th
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 13
),
BigNumber.from(
Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 15
),
],
daoParams.judiciaryList,
parseEther('1'),
];
console.log(deployer.address);

const daoFactory = await ethers.getContractFactory('DAO');
Expand Down
31 changes: 16 additions & 15 deletions packages/contracts/deploy/v2/01_deploy_plugin/02_create_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
],
],
[
// 1st
1724068800, // GMT: Monday, August 19, 2024 12:00:00 PM
1725278400, // GMT: Monday, September 2, 2024 12:00:00 PM

// 2nd
1726488000, //GMT: Monday, September 16, 2024 12:00:00 PM
1727697600, //GMT: Monday, September 30, 2024 12:00:00 PM

// 3rd
1728907200, //GMT: Monday, October 14, 2024 12:00:00 PM
1730376000, //GMT: Thursday, October 31, 2024 12:00:00 PM

// 4th
1734350400, //GMT: Monday, December 16, 2024 12:00:00 PM
1735560000, //GMT: Monday, December 30, 2024 12:00:00 PM
// 1725437700, // GMT: Wednesday, September 4, 2024 8:15:00 AM
// 1725441300, // GMT: Wednesday, September 4, 2024 9:15:00 AM
// // 1st
// 1724068800, // GMT: Monday, August 19, 2024 12:00:00 PM
// 1725278400, // GMT: Monday, September 2, 2024 12:00:00 PM
// // 2nd
// 1726488000, //GMT: Monday, September 16, 2024 12:00:00 PM
// 1727697600, //GMT: Monday, September 30, 2024 12:00:00 PM
// // 3rd
// 1728907200, //GMT: Monday, October 14, 2024 12:00:00 PM
// 1730376000, //GMT: Thursday, October 31, 2024 12:00:00 PM
// // 4th
// 1734350400, //GMT: Monday, December 16, 2024 12:00:00 PM
// 1735560000, //GMT: Monday, December 30, 2024 12:00:00 PM
],
daoParams.judiciaryList,
parseEther('1'),
Expand Down Expand Up @@ -148,6 +147,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
daoAddress,
hexToBytes(encodePlugin(params, METADATA))
);
console.log({staticCall});

const tx = await daofinFactoryContract.prepareInstallation(
daoAddress,
hexToBytes(encodePlugin(params, METADATA))
Expand Down
7 changes: 7 additions & 0 deletions packages/contracts/deployments-v2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"apothem": {
"daoAddress": "0x9EfD35A5AEe913272195709B5b031894F00EA4e3",
"factory": "0xAC9440D76bc3c5291A7BF21a22520bA30F5C3c0d",
"pluginAddress": "0x254de4BA255735dF91B430c2D3686477A4E93618"
}
}
1 change: 1 addition & 0 deletions packages/contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ const config: HardhatUserConfig = {
},

solidity: {
// compilers: [{version: '0.8.17'}, {version: '0.8.21'}],
version: '0.8.17',
settings: {
metadata: {
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/src/DaofinPlugin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
if (_members[i] == address(0)) revert AddressIsZero();
if (isJudiciaryMember(_members[i])) revert JudiciaryExist();
if (isPeopleHouse(_members[i])) revert InValidAddress();
if (isMasterNodeDelegatee(_members[i])) revert InValidAddress();
if (isXDCValidatorCandidate(_members[i])) revert InValidAddress();

_judiciaryCommitteeCount++;
Expand Down Expand Up @@ -703,7 +704,7 @@ contract DaofinPlugin is BaseDaofinPlugin {
address masterNode = _masterNodeDelegatee.delegateeToMasterNode[delegatee_];
if (masterNode == address(0)) return false;

if (!isXDCValidatorCandidate(masterNode)) return false;
// if (!isXDCValidatorCandidate(masterNode)) return false;

return true;
}
Expand Down
55 changes: 41 additions & 14 deletions packages/contracts/src/test/mock/XDCValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,59 @@
pragma solidity 0.8.17;

contract XDCValidator {
mapping(address => bool) validators;
uint256 public candidateCount;
struct ValidatorState {
address owner;
bool isCandidate;
}
mapping(address => ValidatorState) public validatorsState;
mapping(address => address[]) ownerToCandidate;
mapping(address => uint256) public ownerWeights;
address[] public _owners;
address[] public candidates;

uint256 public _candidateCount;

function addCandidate(address candidate) external {
validators[candidate] = true;
candidateCount++;
}
if (validatorsState[candidate].isCandidate) {
revert();
}
if (ownerToCandidate[msg.sender].length == 0) {
_owners.push(msg.sender);
}
validatorsState[candidate].isCandidate = true;
validatorsState[candidate].owner = msg.sender;

function removeCandidate(address candidate) external {
delete validators[candidate];
candidateCount--;
}
ownerToCandidate[msg.sender].push(candidate);

function isCandidate(address _candidate) external view returns (bool) {
return validators[_candidate];
candidates.push(candidate);
_candidateCount++;
}

function getRealCandidates() external pure returns (uint256) {
return 420;
}

function getCandidates() external view returns (uint256) {
return candidateCount;
function getCandidates() external view returns (address[] memory) {
return candidates;
}

function owners(uint256 _index) external view returns (address) {
return _owners[_index];
}

function getOwnerCount() external view returns (uint256) {
return _owners.length;
}

function getCandidateOwner(address _candidate) public view returns (address) {
return validatorsState[_candidate].owner;
}

function candidateCount() external view returns (uint256) {
return _candidateCount;
}

function reset() external {
candidateCount = 0;
_candidateCount = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe(PLUGIN_CONTRACT_NAME, function () {
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;
Expand Down Expand Up @@ -114,10 +113,10 @@ describe(PLUGIN_CONTRACT_NAME, function () {
],
[
BigNumber.from(now + 60 * 60 * 24 * 3),
BigNumber.from(now + 60 * 60 * 24 * 5),
BigNumber.from(now + 60 * 60 * 24 * 11),
],
[Alice.address],
parseEther('1'),
'1',
];
await daofinPlugin.initialize(...initializeParams);
});
Expand All @@ -132,7 +131,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {

await dao.grant(
daofinPlugin.address,
Alice.address,
daoTreasury.address,
UPDATE_JUDICIARY_MAPPING_PERMISSION_ID
);
await expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ describe(PLUGIN_CONTRACT_NAME, function () {
],
[
BigNumber.from(now + 60 * 60 * 24 * 3),
BigNumber.from(now + 60 * 60 * 24 * 5),
BigNumber.from(now + 60 * 60 * 24 * 6),
BigNumber.from(now + 60 * 60 * 24 * 8),
BigNumber.from(now + 60 * 60 * 24 * 11),
],
[Alice.address],
'1',
Expand Down Expand Up @@ -155,8 +153,8 @@ describe(PLUGIN_CONTRACT_NAME, function () {
createPropsalParams = createProposalParams(
'0x00',
[],
'1',
'1',
'0',
'0',
'0',
'0'
);
Expand All @@ -165,19 +163,20 @@ describe(PLUGIN_CONTRACT_NAME, function () {
const proposalId = await daofinPlugin.callStatic.createProposal(
...createPropsalParams
);

await expect(daofinPlugin.createProposal(...createPropsalParams)).to.not
.reverted;
expect(
(await daofinPlugin.getProposal(proposalId)).proposalTypeId
).to.be.eq('1');
).to.be.eq('0');
expect(await daofinPlugin.proposalCount()).to.be.eq('1');
});
it('proposalCost must be charged', async () => {
createPropsalParams = createProposalParams(
'0x00',
[],
'1',
'1',
'0',
'0',
'0',
'0'
);
Expand Down
Loading

0 comments on commit 048caad

Please sign in to comment.