From 3e7f00b088f279d62691be56c74492e86a35721e Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 23 Sep 2019 01:17:10 +0100 Subject: [PATCH] kit tests --- contracts/test/Spoof.sol | 16 ++++++++ package.json | 3 +- test/kreditskit.js | 88 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 contracts/test/Spoof.sol create mode 100644 test/kreditskit.js diff --git a/contracts/test/Spoof.sol b/contracts/test/Spoof.sol new file mode 100644 index 0000000..1c29c7e --- /dev/null +++ b/contracts/test/Spoof.sol @@ -0,0 +1,16 @@ +pragma solidity ^0.4.24; + +import "@aragon/os/contracts/acl/ACL.sol"; +import "@aragon/os/contracts/kernel/Kernel.sol"; +import "@aragon/os/contracts/factory/DAOFactory.sol"; + +// You might think this file is a bit odd, but let me explain. +// We only use for now those imported contracts in our tests, which +// means Truffle will not compile them for us, because they are from +// an external dependency. + + +// solium-disable-next-line no-empty-blocks +contract Spoof { + // ... +} diff --git a/package.json b/package.json index 5c02c72..2dbcab0 100644 --- a/package.json +++ b/package.json @@ -24,11 +24,12 @@ "lint:contracts": "solhint \"contracts/**/*.sol\" \"apps/*/contracts/**/*.sol\"", "lint:contract-tests": "eslint apps/*/test", "lint:wrapper": "eslint lib/", - "test": "npm run test:token && npm run test:contributor && npm run test:contribution && npm run test:proposal", + "test": "npm run test:token && npm run test:contributor && npm run test:contribution && npm run test:proposal && npm run test:kit", "test:token": "cd apps/token && npm run test", "test:contributor": "cd apps/contributor && npm run test", "test:contribution": "cd apps/contribution && npm run test", "test:proposal": "cd apps/proposal && npm run test", + "test:kit": "aragon contracts test", "setup-git-hooks": "sh scripts/git-hooks/install" }, "repository": { diff --git a/test/kreditskit.js b/test/kreditskit.js new file mode 100644 index 0000000..06c8580 --- /dev/null +++ b/test/kreditskit.js @@ -0,0 +1,88 @@ +/* eslint-disable no-undef */ +const namehash = require('ethers').utils.namehash; +const KreditsKit = artifacts.require("KreditsKit.sol"); +const getContract = name => artifacts.require(name); +const ZERO_ADDR = '0x0000000000000000000000000000000000000000'; +const arapp = require('../arapp.json'); +const ENS_ADDRESS = arapp.environments.development.registry; + +contract('DAO bare kit', (accounts) => { + let kreditsKit; + let address; + let apps; + let kernel; + let contribution; + let contributor; + let proposal; + let token; + + before(async () => { + //apps id + const appsId = []; + appsId[0] = namehash("kredits-contribution"); + appsId[1] = namehash("kredits-contributor"); + appsId[2] = namehash("kredits-proposal"); + appsId[3] = namehash("kredits-token"); + + const kernelBase = await getContract('Kernel').new(true); // petrify immediately + const aclBase = await getContract('ACL').new(); + const daoFactory = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDR); + + kreditsKit = await KreditsKit.new(daoFactory.address, ENS_ADDRESS, appsId, { from: accounts[0] }); + }); + + describe("New DAO instance", () => { + it("kit should be defined", async () => { + assert.notEqual(kreditsKit, undefined); + }); + + it('it should deploy DAO', async () => { + const receipt = await kreditsKit.newInstance({ from: accounts[0] }); + + address = receipt.logs.filter(l => l.event === 'DeployInstance')[0].args.dao; + apps = receipt.logs + .filter(l => l.event === 'InstalledApp') + .map(event => { + return { id: event.args.appId, proxy: event.args.appProxy }; + }); + + address.should.not.equal(ZERO_ADDR); + }); + + it('it should install apps', async () => { + apps[0].id.should.equal(namehash('kredits-contribution')); + apps[1].id.should.equal(namehash('kredits-contributor')); + apps[2].id.should.equal(namehash('kredits-proposal')); + apps[3].id.should.equal(namehash('kredits-token')); + }); + + it('it should initialize apps', async () => { + contribution = await getContract('Contribution').at(apps[0].proxy); + contributor = await getContract('Contributor').at(apps[1].proxy); + proposal = await getContract('Proposal').at(apps[2].proxy); + token = await getContract('Token').at(apps[3].proxy); + (await Promise.all([ + contribution.hasInitialized(), + contributor.hasInitialized(), + proposal.hasInitialized(), + token.hasInitialized(), + ])).should.deep.equal([true, true, true, true]); + }); + + it('it should set permissions', async () => { + kernel = await getContract('Kernel').at(address); + (await Promise.all([ + //check contribution app roles + kernel.hasPermission(accounts[0], contribution.address, await space.ADD_CONTRIBUTION_ROLE(), '0x0'), + kernel.hasPermission(accounts[0], contribution.address, await space.VETO_CONTRIBUTION_ROLE(), '0x0'), + kernel.hasPermission(proposal.address, contribution.address, await space.ADD_CONTRIBUTION_ROLE(), '0x0'), + //proposal app roles + kernel.hasPermission(accounts[0], proposal.address, await proposal.VOTE_PROPOSAL_ROLE(), '0x0'), + //token app roles + kernel.hasPermission(accounts[0], token.address, await token.MINT_TOKEN_ROLE(), '0x0'), + kernel.hasPermission(contribution.address, token.address, await token.MINT_TOKEN_ROLE(), '0x0'), + ])).should.deep.equal([true, true, true, true, true, true]); + }); + + }); +});