Skip to content

Commit

Permalink
#65 fixed voting bug in DevZenDao
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzhak committed Oct 23, 2018
1 parent 9d0f77c commit f05480b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
7 changes: 4 additions & 3 deletions contracts/3-DevZenDao/DevZenDaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.4.22;
// to enable Params passing to constructor and method
pragma experimental ABIEncoderV2;

import "@thetta/core/contracts/DaoBase.sol";
import "@thetta/core/contracts/DaoBaseWithUnpackers.sol";
import "@thetta/core/contracts/IDaoBase.sol";
import "@thetta/core/contracts/DaoStorage.sol";
import "@thetta/core/contracts/DaoBaseAuto.sol";
Expand All @@ -26,7 +26,7 @@ import "./DevZenDaoWithUnpackers.sol";

contract DevZenDaoFactory {
DevZenDaoWithUnpackers public devZenDao;
DaoBase public daoBase;
DaoBaseWithUnpackers public daoBase;
DaoStorage store;
DevZenDaoAuto public devZenDaoAuto;

Expand All @@ -44,7 +44,7 @@ contract DevZenDaoFactory {
tokens.push(address(devZenToken));
tokens.push(address(repToken));
store = new DaoStorage(tokens);
daoBase = new DaoBase(store);
daoBase = new DaoBaseWithUnpackers(store);

createNewContract(IDaoBase(daoBase), tokens);

Expand Down Expand Up @@ -115,6 +115,7 @@ contract DevZenDaoFactory {

uint VOTING_TYPE_1P1V = 1;
devZenDaoAuto.setVotingParams(daoBase.MANAGE_GROUPS(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(daoBase.REMOVE_GROUP_MEMBER(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(daoBase.UPGRADE_DAO_CONTRACT(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(devZenDao.DEV_ZEN_UPDATE_DAO_PARAMS(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(devZenDao.DEV_ZEN_WITHDRAW_ETHER(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
Expand Down
6 changes: 4 additions & 2 deletions contracts/3-DevZenDao/DevZenDaoFactoryTestable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

import "@thetta/core/contracts/IDaoBase.sol";
import "@thetta/core/contracts/DaoBaseWithUnpackers.sol";

import "./DevZenDaoFactory.sol";
import "./DevZenDaoTestable.sol";
Expand All @@ -13,7 +14,7 @@ import "./DevZenDaoCore.sol";

contract DevZenDaoFactoryTestable {
DevZenDaoWithUnpackersTestable public devZenDao;
DaoBase public daoBase;
DaoBaseWithUnpackers public daoBase;
DaoStorage store;
DevZenDaoAutoTestable public devZenDaoAuto;

Expand All @@ -31,7 +32,7 @@ contract DevZenDaoFactoryTestable {
tokens.push(address(devZenToken));
tokens.push(address(repToken));
store = new DaoStorage(tokens);
daoBase = new DaoBase(store);
daoBase = new DaoBaseWithUnpackers(store);

createNewContract(IDaoBase(daoBase), tokens);

Expand Down Expand Up @@ -101,6 +102,7 @@ contract DevZenDaoFactoryTestable {

uint VOTING_TYPE_1P1V = 1;
devZenDaoAuto.setVotingParams(daoBase.MANAGE_GROUPS(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(daoBase.REMOVE_GROUP_MEMBER(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(daoBase.UPGRADE_DAO_CONTRACT(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(devZenDao.DEV_ZEN_UPDATE_DAO_PARAMS(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
devZenDaoAuto.setVotingParams(devZenDao.DEV_ZEN_WITHDRAW_ETHER(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("DevZenTeam"), bytes32(65), bytes32(65), 0);
Expand Down
11 changes: 6 additions & 5 deletions migrations/3_deploy_devZenDao.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var DevZenDaoFactory = artifacts.require("DevZenDaoFactory");
var StdDaoToken = artifacts.require("StdDaoToken");
var DaoStorage = artifacts.require("DaoStorage");
var DaoBase = artifacts.require("DaoBase");
var DaoBaseWithUnpackers = artifacts.require("DaoBaseWithUnpackers");
var IDaoBase = artifacts.require("IDaoBase");
var DaoBaseAuto = artifacts.require("DaoBaseAuto");
var DevZenDao = artifacts.require("DevZenDao");
Expand All @@ -10,16 +10,16 @@ var DevZenDaoCore = artifacts.require("DevZenDaoCore");
var DevZenDaoWithUnpackers = artifacts.require("DevZenDaoWithUnpackers");
const { uintToBytes32, padToBytes, fromUtf8 } = require("../test/utils/helpers");

let emp1 = '0xfac20ad5f3bfc1748235edf919d473272ca0fd55';
let emp2 = '0x38ed1a11e4f2fd85995a058e1f65d41a483a662a';
let emp3 = '0x92bc71cd9a9a6ad3a1dcacc2b8c9eab13f4d547e';
let emp1 = '0x7EaD9f71ef8a32D351ce1966b281300114bF2eab';
let emp2 = '0x1f27a8F4a8A50898C5735221982eefA80c070073';
let emp3 = '0xC86d4De6dC26d73BE76a526D951d194BF13C605c';

module.exports = function(deployer, network, accounts) {
return deployer.then(async () => {
let devZenToken = await deployer.deploy(StdDaoToken, "DevZenToken", "DZT", 18, true, true, 100000000000000000000);
let repToken = await deployer.deploy(StdDaoToken, "DevZenRepToken", "DZTREP", 18, true, true, 100000000000000000000);
let store = await deployer.deploy(DaoStorage, [devZenToken.address, repToken.address]);
let daoBase = await deployer.deploy(DaoBase, store.address);
let daoBase = await deployer.deploy(DaoBaseWithUnpackers, store.address);
let devZenDao = await deployer.deploy(DevZenDaoWithUnpackers, daoBase.address, [devZenToken.address, repToken.address]);

await store.allowActionByAddress(await daoBase.MANAGE_GROUPS(),accounts[0]);
Expand Down Expand Up @@ -76,6 +76,7 @@ module.exports = function(deployer, network, accounts) {

let VOTING_TYPE_1P1V = 1;
await devZenDaoAuto.setVotingParams(await daoBase.MANAGE_GROUPS(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("DevZenTeam"), uintToBytes32(65), uintToBytes32(65), 0);
await devZenDaoAuto.setVotingParams(await daoBase.REMOVE_GROUP_MEMBER(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("DevZenTeam"), uintToBytes32(65), uintToBytes32(65), 0);
await devZenDaoAuto.setVotingParams(await daoBase.UPGRADE_DAO_CONTRACT(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("DevZenTeam"), uintToBytes32(65), uintToBytes32(65), 0);
await devZenDaoAuto.setVotingParams(await devZenDao.DEV_ZEN_UPDATE_DAO_PARAMS(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("DevZenTeam"), uintToBytes32(65), uintToBytes32(65), 0);
await devZenDaoAuto.setVotingParams(await devZenDao.DEV_ZEN_WITHDRAW_ETHER(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("DevZenTeam"), uintToBytes32(65), uintToBytes32(65), 0);
Expand Down
57 changes: 57 additions & 0 deletions test/DevZenDao.functional.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ contract("DevZenDaoAuto", (accounts) => {
devZenDaoAuto = DevZenDaoAuto.at(await devZenDaoFactory.devZenDaoAuto());
});

describe("addGroupMemberAuto", () => {
it("should add a new group member on successful voting", async() => {
await devZenDaoAuto.addGroupMemberAuto("DevZenTeam", guest1, {from: boss}).should.be.fulfilled;
const voting = await getVoting(daoBase, 0);

const membersBefore = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersBefore.length, 3);

await voting.vote(true, {from: teamMember1}).should.be.fulfilled;

const membersAfter = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersAfter.length, 4);
assert.equal(membersAfter[3], guest1);
});

it("should not add a new group member on failed voting", async() => {
await devZenDaoAuto.addGroupMemberAuto("DevZenTeam", guest1, {from: boss}).should.be.fulfilled;
const voting = await getVoting(daoBase, 0);

const membersBefore = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersBefore.length, 3);

await voting.vote(false, {from: teamMember1}).should.be.fulfilled;

const membersAfter = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersAfter.length, 3);
});
});

describe("withdrawEtherAuto", () => {
it("should withdraw ether to specified address", async() => {
await devZenDao.moveToNextEpisode(false, {from:boss}).should.be.fulfilled;
Expand Down Expand Up @@ -247,6 +276,34 @@ contract("DevZenDaoAuto", (accounts) => {
});
});

describe("removeGroupMemberAuto", () => {
it("should remove group member on successful voting", async() => {
await devZenDaoAuto.removeGroupMemberAuto("DevZenTeam", teamMember2, {from: boss}).should.be.fulfilled;
const voting = await getVoting(daoBase, 0);

const membersBefore = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersBefore.length, 3);

await voting.vote(true, {from: teamMember1}).should.be.fulfilled;

const membersAfter = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersAfter.length, 2);
});

it("should not remove group member on failed voting", async() => {
await devZenDaoAuto.removeGroupMemberAuto("DevZenTeam", teamMember2, {from: boss}).should.be.fulfilled;
const voting = await getVoting(daoBase, 0);

const membersBefore = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersBefore.length, 3);

await voting.vote(false, {from: teamMember1}).should.be.fulfilled;

const membersAfter = await daoBase.getGroupMembers("DevZenTeam");
assert.equal(membersAfter.length, 3);
});
});

describe("updateDaoParamsAuto", () => {
it("should update param", async() => {
let paramHash = await devZenDao.MINT_TOKENS_PER_WEEK_AMOUNT();
Expand Down

0 comments on commit f05480b

Please sign in to comment.