Skip to content
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

Fix tests #320

Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 9 additions & 36 deletions test/dao/DAOController.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
const { expectRevert, expectEvent, BN } = require("@openzeppelin/test-helpers");
const ERC20Mock = artifacts.require("./ERC20Mock.sol");
const DAOReputation = artifacts.require("./DAOReputation.sol");
const DAOController = artifacts.require("./DAOController.sol");
const DAOAvatar = artifacts.require("./DAOAvatar.sol");
const VotingMachine = artifacts.require("./VotingMachine.sol");
const ActionMock = artifacts.require("./ActionMock.sol");
import * as helpers from "../helpers";

contract("DAOController", function (accounts) {
let reputation,
controller,
avatar,
defaultParamsHash,
repHolders,
standardTokenMock,
actionMock;
let reputation, controller, avatar, defaultParamsHash, repHolders, actionMock;

const schemeAddress = accounts[0];

Expand All @@ -26,31 +16,14 @@ contract("DAOController", function (accounts) {
{ address: accounts[2], amount: 70000 },
];

reputation = await DAOReputation.new();
await reputation.initialize("DXDaoReputation", "DXRep");

controller = await DAOController.new();

avatar = await DAOAvatar.new();
await avatar.initialize(controller.address);

for (let { address, amount } of repHolders) {
await reputation.mint(address, amount);
}

await reputation.transferOwnership(controller.address);

standardTokenMock = await ERC20Mock.new("", "", 1000, accounts[1]);

const votingMachine = await VotingMachine.new(standardTokenMock.address);

defaultParamsHash = await helpers.setDefaultParameters(votingMachine);

await controller.initialize(
schemeAddress,
reputation.address,
defaultParamsHash
);
const org = await helpers.deployDaoV2({
owner: accounts[0],
repHolders,
});
controller = org.controller;
avatar = org.avatar;
defaultParamsHash = org.defaultParamsHash;
reputation = org.reputation;
});
it("Should fail with 'Initializable: contract is already initialized'", async () => {
await expectRevert(
Expand Down
3 changes: 2 additions & 1 deletion test/dao/dxdao.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract("DXdao", function (accounts) {
beforeEach(async function () {
votingMachineToken = await ERC20Mock.new("DXDao", "DXD", 1000, accounts[0]);

dxDao = await helpers.deployDao({
dxDao = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: votingMachineToken.address,
repHolders: [
Expand Down Expand Up @@ -60,6 +60,7 @@ contract("DXdao", function (accounts) {
dxDao.votingMachine.address,
dxDao.controller.address,
permissionRegistry.address,
dxDao.votingPowerToken.address,
"Master Scheme",
5
);
Expand Down
23 changes: 9 additions & 14 deletions test/dao/schemes/AvatarScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,15 @@ contract("AvatarScheme", function (accounts) {
actionMock = await ActionMock.new();
standardTokenMock = await ERC20Mock.new("", "", 1000, accounts[1]);

org = await helpers.deployDaoV2(
Object.assign(
{
owner: accounts[0],
votingMachineToken: standardTokenMock.address,
repHolders: [
{ address: accounts[0], amount: 20000 },
{ address: accounts[1], amount: 10000 },
{ address: accounts[2], amount: 70000 },
],
},
constants.GOVERNANCE_V2_CONFIG(web3)
)
);
org = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: standardTokenMock.address,
repHolders: [
{ address: accounts[0], amount: 20000 },
{ address: accounts[1], amount: 10000 },
{ address: accounts[2], amount: 70000 },
],
});

const defaultParamsHash = await helpers.setDefaultParameters(
org.votingMachine
Expand Down
9 changes: 8 additions & 1 deletion test/dao/schemes/WalletScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract("WalletScheme", function (accounts) {
testToken = await ERC20Mock.new("", "", 1000, accounts[1]);
standardTokenMock = await ERC20Mock.new("", "", 1000, accounts[1]);

org = await helpers.deployDao({
org = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: standardTokenMock.address,
repHolders: [
Expand All @@ -51,6 +51,7 @@ contract("WalletScheme", function (accounts) {
org.votingMachine.address,
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"Wallet Scheme Registrar",
0
);
Expand All @@ -61,6 +62,7 @@ contract("WalletScheme", function (accounts) {
org.votingMachine.address,
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"Master Wallet",
5
);
Expand All @@ -71,6 +73,7 @@ contract("WalletScheme", function (accounts) {
org.votingMachine.address,
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"Quick Wallet",
1
);
Expand Down Expand Up @@ -234,6 +237,7 @@ contract("WalletScheme", function (accounts) {
org.votingMachine.address,
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"New Wallet Scheme",
0
);
Expand Down Expand Up @@ -472,6 +476,7 @@ contract("WalletScheme", function (accounts) {
org.votingMachine.address,
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"New Wallet",
5
);
Expand Down Expand Up @@ -1326,6 +1331,7 @@ contract("WalletScheme", function (accounts) {
accounts[0],
constants.ZERO_ADDRESS,
permissionRegistry.address,
org.votingPowerToken.address,
"Master Wallet",
5
),
Expand All @@ -1340,6 +1346,7 @@ contract("WalletScheme", function (accounts) {
accounts[0],
org.controller.address,
permissionRegistry.address,
org.votingPowerToken.address,
"Master Wallet",
5
),
Expand Down
40 changes: 15 additions & 25 deletions test/dao/votingMachines/VotingMachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,16 @@ contract("VotingMachine", function (accounts) {
accounts[1]
);

org = await helpers.deployDaoV2(
Object.assign(
{
owner: accounts[0],
votingMachineToken: stakingToken.address,
repHolders: [
{ address: accounts[0], amount: 10000 },
{ address: accounts[1], amount: 10000 },
{ address: accounts[2], amount: 10000 },
{ address: accounts[3], amount: 70000 },
],
},
constants.GOVERNANCE_V2_CONFIG(web3)
)
);
org = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: stakingToken.address,
repHolders: [
{ address: accounts[0], amount: 10000 },
{ address: accounts[1], amount: 10000 },
{ address: accounts[2], amount: 10000 },
{ address: accounts[3], amount: 70000 },
],
});

dxdVotingMachine = org.votingMachine;

Expand Down Expand Up @@ -1094,16 +1089,11 @@ contract("VotingMachine", function (accounts) {
constants.MAX_UINT_256,
{ from: accounts[9] }
);
const fakeOrg = await helpers.deployDaoV2(
Object.assign(
{
owner: accounts[9],
votingMachineToken: stakingToken.address,
repHolders: [{ address: accounts[9], amount: 10000 }],
},
constants.GOVERNANCE_V2_CONFIG(web3)
)
);
const fakeOrg = await helpers.deployDaoV2({
owner: accounts[9],
votingMachineToken: stakingToken.address,
repHolders: [{ address: accounts[9], amount: 10000 }],
});
const fakePermissionRegistry = await PermissionRegistry.new(
accounts[9],
1
Expand Down
10 changes: 3 additions & 7 deletions test/erc20guild/implementations/DXDGuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ contract("DXDGuild", function (accounts) {
[0, 50, 100, 100, 250]
);
dxdGuild = await DXDGuild.new();

const votingMachineToken = await ERC20Mock.new(
"DXDao",
"DXD",
1000,
accounts[0]
);

dxDao = await helpers.deployDao({
dxDao = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: votingMachineToken.address,
repHolders: [
Expand All @@ -56,10 +55,6 @@ contract("DXDGuild", function (accounts) {
],
});

const defaultParamsHash = await helpers.setDefaultParameters(
dxDao.votingMachine
);

const permissionRegistry = await PermissionRegistry.new(accounts[0], 10);
await permissionRegistry.initialize();

Expand All @@ -70,13 +65,14 @@ contract("DXDGuild", function (accounts) {
dxDao.votingMachine.address,
dxDao.controller.address,
permissionRegistry.address,
dxDao.votingPowerToken.address,
"Master Scheme",
5
);

await dxDao.controller.registerScheme(
masterAvatarScheme.address,
defaultParamsHash,
dxDao.defaultParamsHash,
true,
true,
true
Expand Down
23 changes: 12 additions & 11 deletions test/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@ export const NO_OPTION = "1";
const lf = 0.025;
const ef = 0;
const exp = 1;
export const GOVERNANCE_V2_CONFIG = web3 => {
return {
repTokenWeight: 50,
stakeTokenWeight: 50,
minStakingTokensLocked: 100,
maxTimeCommitment: 1000,
linearFactor: web3.utils.toWei(lf.toString(), "ether"),
exponentialFactor: web3.utils.toWei(ef.toString(), "ether"),
exponent: web3.utils.toWei(exp.toString(), "ether"),
};
};

export const GOVERNANCE_V2_CONFIG = web3 => ({
repTokenWeight: 50,
stakeTokenWeight: 50,
minStakingTokensLocked: 100,
maxTimeCommitment: 1000,
linearFactor: web3.utils.toWei(lf.toString(), "ether"),
exponentialFactor: web3.utils.toWei(ef.toString(), "ether"),
exponent: web3.utils.toWei(exp.toString(), "ether"),
repHolders: [],
votingMachineToken: SOME_ADDRESS,
});

export const WALLET_SCHEME_PROPOSAL_STATES = {
none: "0",
Expand Down
11 changes: 10 additions & 1 deletion test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,15 @@ export const deployDao = async function (deployConfig) {
return { controller, avatar, reputation, votingMachine };
};

export const deployDaoV2 = async function (deployConfig) {
export const deployDaoV2 = async function (config) {
if (!Object.keys(config).includes("owner")) {
throw new Error("deployDaoV2: Invalid config. Config.owner missing");
}
const deployConfig = Object.assign(
constants.GOVERNANCE_V2_CONFIG(web3),
config
);

const reputation = await DAOReputation.new();

const dxdStake = await DXDStake.new();
Expand Down Expand Up @@ -179,6 +187,7 @@ export const deployDaoV2 = async function (deployConfig) {
dxdStake,
dxdInfluence,
votingPowerToken,
defaultParamsHash,
};
};

Expand Down
4 changes: 3 additions & 1 deletion test/utils/PermissionRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract("PermissionRegistry", function (accounts) {
actionMock = await ActionMock.new();
const votingMachineToken = await ERC20Mock.new("", "", 1000, accounts[1]);

dao = await helpers.deployDao({
dao = await helpers.deployDaoV2({
owner: accounts[0],
votingMachineToken: votingMachineToken.address,
repHolders: [
Expand All @@ -48,6 +48,7 @@ contract("PermissionRegistry", function (accounts) {
dao.votingMachine.address,
dao.controller.address,
permissionRegistry.address,
dao.votingPowerToken.address,
"Master Wallet",
5
);
Expand All @@ -58,6 +59,7 @@ contract("PermissionRegistry", function (accounts) {
dao.votingMachine.address,
dao.controller.address,
permissionRegistry.address,
dao.votingPowerToken.address,
"Quick Wallet",
0
);
Expand Down