From 42d4752d58f4192ca1fd2416ae68bc6e9ca29733 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 8 Jul 2019 11:15:40 +0100 Subject: [PATCH] fix indentation --- .eslintrc.js | 1 + apps/contributor/test/contributor.js | 296 +++++++++++++-------------- 2 files changed, 149 insertions(+), 148 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4fcc035..b977257 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -28,5 +28,6 @@ module.exports = { named: 'always', asyncArrow: 'always', }], + 'indent': ['error', 2] } } diff --git a/apps/contributor/test/contributor.js b/apps/contributor/test/contributor.js index cd92fc0..a7812c6 100644 --- a/apps/contributor/test/contributor.js +++ b/apps/contributor/test/contributor.js @@ -10,161 +10,161 @@ const { assertRevert } = require('@aragon/test-helpers/assertThrow'); const ZERO_ADDR = '0x0000000000000000000000000000000000000000'; contract('Contributor app', (accounts) => { - let kernelBase, aclBase, daoFactory, r, dao, acl, contributor; - - const root = accounts[0]; - const member1 = accounts[1]; + let kernelBase, aclBase, daoFactory, r, dao, acl, contributor; + + const root = accounts[0]; + const member1 = accounts[1]; + + // eslint-disable-next-line no-undef + before(async () => { + kernelBase = await getContract('Kernel').new(true); // petrify immediately + aclBase = await getContract('ACL').new(); + daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR); + r = await daoFactory.newDAO(root); + dao = getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao); + acl = getContract('ACL').at(await dao.acl()); + + //create dao mamnager permission for coin owner + await acl.createPermission( + root, + dao.address, + await dao.APP_MANAGER_ROLE(), + root, + { from: root } + ); + + //get new app instance from DAO + const receipt = await dao.newAppInstance( + '0x1234', + (await Contributor.new()).address, + 0x0, + false, + { from: root } + ); + contributor = Contributor.at( + receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy + ); + + //apps id + let appsId = []; + appsId[0] = namehash("kredits-contribution"); + appsId[1] = namehash("kredits-contributor"); + appsId[2] = namehash("kredits-proposal"); + appsId[3] = namehash("kredits-token"); + + //init contributor (app) + await contributor.initialize(root, appsId); + + //create manage contributors role + await acl.createPermission( + root, + contributor.address, + await contributor.MANAGE_CONTRIBUTORS_ROLE(), + root, + { from: root } + ); + }); + + describe("Owner default space permissions", async () => { + it('check owner is token issuer', async () => { + let manageContributorPermission = await acl.hasPermission(root, contributor.address, await contributor.MANAGE_CONTRIBUTORS_ROLE()); + // eslint-disable-next-line no-undef + assert.equal(manageContributorPermission, true); + }); + }); + + describe("Add contributor", async () => { + let account = root; + let hashDigest = '0x0'; + let hashFunction = 0; + let hashSize = 0; + + it("should revert when add contributor from an address that does not have permission", async () => { + return assertRevert(async () => { + await contributor.addContributor(account, hashDigest, hashFunction, hashSize, { from: member1}); + 'sender does not have permission'; + }); + }); + + it('add contributor', async () => { + let contributorCount = await contributor.coreContributorsCount(); + await contributor.addContributor(account, hashDigest, hashFunction, hashSize); + // eslint-disable-next-line no-undef + assert.equal(await contributor.addressExists(account), true); + let contributorCountAfter = await contributor.coreContributorsCount(); + // eslint-disable-next-line no-undef + assert.equal(await contributorCountAfter.toNumber(), parseInt(contributorCount)+1); + }); + + it("should revert when add contributor with an address that already exist", async () => { + return assertRevert(async () => { + await contributor.addContributor(account, hashDigest, hashFunction, hashSize, { from: member1}); + 'address already exist'; + }); + }); + }); + + describe("Update contributor", async () => { + let id; + let oldAccount; + let newAccount; + let hashDigest; + let hashFunction; + let hashSize; + // eslint-disable-next-line no-undef - before(async () => { - kernelBase = await getContract('Kernel').new(true); // petrify immediately - aclBase = await getContract('ACL').new(); - daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR); - r = await daoFactory.newDAO(root); - dao = getContract('Kernel').at(r.logs.filter(l => l.event == 'DeployDAO')[0].args.dao); - acl = getContract('ACL').at(await dao.acl()); - - //create dao mamnager permission for coin owner - await acl.createPermission( - root, - dao.address, - await dao.APP_MANAGER_ROLE(), - root, - { from: root } - ); - - //get new app instance from DAO - const receipt = await dao.newAppInstance( - '0x1234', - (await Contributor.new()).address, - 0x0, - false, - { from: root } - ); - contributor = Contributor.at( - receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy - ); - - //apps id - let appsId = []; - appsId[0] = namehash("kredits-contribution"); - appsId[1] = namehash("kredits-contributor"); - appsId[2] = namehash("kredits-proposal"); - appsId[3] = namehash("kredits-token"); - - //init contributor (app) - await contributor.initialize(root, appsId); - - //create manage contributors role - await acl.createPermission( - root, - contributor.address, - await contributor.MANAGE_CONTRIBUTORS_ROLE(), - root, - { from: root } - ); - + before(async () => { + id = await contributor.coreContributorsCount(); + oldAccount = root; + newAccount = member1; + hashDigest = '0x1000000000000000000000000000000000000000000000000000000000000000'; + hashFunction = 1; + hashSize = 1; }); - describe("Owner default space permissions", async () => { - it('check owner is token issuer', async () => { - let manageContributorPermission = await acl.hasPermission(root, contributor.address, await contributor.MANAGE_CONTRIBUTORS_ROLE()); - // eslint-disable-next-line no-undef - assert.equal(manageContributorPermission, true); - }); + it('update contributor account', async () => { + await contributor.updateContributorAccount(id.toNumber(), oldAccount, newAccount); + let contributorId = await contributor.getContributorIdByAddress(oldAccount); + // eslint-disable-next-line no-undef + assert.equal(contributorId.toNumber(), 0); }); - describe("Add contributor", async () => { - let account = root; - let hashDigest = '0x0'; - let hashFunction = 0; - let hashSize = 0; - - it("should revert when add contributor from an address that does not have permission", async () => { - return assertRevert(async () => { - await contributor.addContributor(account, hashDigest, hashFunction, hashSize, { from: member1}); - 'sender does not have permission'; - }); - }); - - it('add contributor', async () => { - let contributorCount = await contributor.coreContributorsCount(); - await contributor.addContributor(account, hashDigest, hashFunction, hashSize); - // eslint-disable-next-line no-undef - assert.equal(await contributor.addressExists(account), true); - let contributorCountAfter = await contributor.coreContributorsCount(); - // eslint-disable-next-line no-undef - assert.equal(await contributorCountAfter.toNumber(), parseInt(contributorCount)+1); - }); - - it("should revert when add contributor with an address that already exist", async () => { - return assertRevert(async () => { - await contributor.addContributor(account, hashDigest, hashFunction, hashSize, { from: member1}); - 'address already exist'; - }); - }); + it("should revert when update contributor account from address that does not have permission", async () => { + return assertRevert(async () => { + await contributor.updateContributorAccount(id.toNumber(), oldAccount, newAccount, {from: member1}); + 'sender does not have permission'; + }); }); - describe("Update contributor", async () => { - let id; - let oldAccount; - let newAccount; - let hashDigest; - let hashFunction; - let hashSize; - - // eslint-disable-next-line no-undef - before(async () => { - id = await contributor.coreContributorsCount(); - oldAccount = root; - newAccount = member1; - hashDigest = '0x1000000000000000000000000000000000000000000000000000000000000000'; - hashFunction = 1; - hashSize = 1; - }); - - it('update contributor account', async () => { - await contributor.updateContributorAccount(id.toNumber(), oldAccount, newAccount); - let contributorId = await contributor.getContributorIdByAddress(oldAccount); - // eslint-disable-next-line no-undef - assert.equal(contributorId.toNumber(), 0); - }); - - it("should revert when update contributor account from address that does not have permission", async () => { - return assertRevert(async () => { - await contributor.updateContributorAccount(id.toNumber(), oldAccount, newAccount, {from: member1}); - 'sender does not have permission'; - }); - }); - - it("should revert when update contributor account that does not exist", async () => { - return assertRevert(async () => { - await contributor.updateContributorAccount(id.toNumber(), accounts[3], newAccount); - 'contributor does not exist'; - }); - }); - - it("should revert when update contributor account with address(0)", async () => { - return assertRevert(async () => { - await contributor.updateContributorAccount(id.toNumber(), oldAccount, ZERO_ADDR); - 'contributor does not exist'; - }); - }); - - it('update contributor profile hash', async () => { - await contributor.updateContributorProfileHash(id.toNumber(), hashDigest, hashFunction, hashSize); - let contributorProfile = await contributor.contributors(id.toNumber()); - assert.equal(hashDigest, contributorProfile[1]); // eslint-disable-line no-undef - assert.equal(hashFunction, contributorProfile[2].toNumber()); // eslint-disable-line no-undef - assert.equal(hashSize, contributorProfile[3].toNumber()); // eslint-disable-line no-undef - }); - - it("should revert when update contributor profile hash from address that does not have permission", async () => { - return assertRevert(async () => { - await contributor.updateContributorProfileHash(id.toNumber(), hashDigest, hashFunction, hashSize, {from: member1}); - 'sender does not have permission'; - }); - }); - + it("should revert when update contributor account that does not exist", async () => { + return assertRevert(async () => { + await contributor.updateContributorAccount(id.toNumber(), accounts[3], newAccount); + 'contributor does not exist'; + }); }); + + it("should revert when update contributor account with address(0)", async () => { + return assertRevert(async () => { + await contributor.updateContributorAccount(id.toNumber(), oldAccount, ZERO_ADDR); + 'contributor does not exist'; + }); + }); + + it('update contributor profile hash', async () => { + await contributor.updateContributorProfileHash(id.toNumber(), hashDigest, hashFunction, hashSize); + let contributorProfile = await contributor.contributors(id.toNumber()); + assert.equal(hashDigest, contributorProfile[1]); // eslint-disable-line no-undef + assert.equal(hashFunction, contributorProfile[2].toNumber()); // eslint-disable-line no-undef + assert.equal(hashSize, contributorProfile[3].toNumber()); // eslint-disable-line no-undef + }); + + it("should revert when update contributor profile hash from address that does not have permission", async () => { + return assertRevert(async () => { + await contributor.updateContributorProfileHash(id.toNumber(), hashDigest, hashFunction, hashSize, {from: member1}); + 'sender does not have permission'; + }); + }); + + }); });