From b6673abdcf352f9f4e13290411562df6f0a4c813 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 29 Jul 2019 13:26:06 +0100 Subject: [PATCH 1/6] test token app --- apps/token/contracts/Token.sol | 2 + apps/token/test/app.js | 5 -- apps/token/test/token.js | 123 +++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 5 deletions(-) delete mode 100644 apps/token/test/app.js create mode 100644 apps/token/test/token.js diff --git a/apps/token/contracts/Token.sol b/apps/token/contracts/Token.sol index 3fe68a4..35acc03 100644 --- a/apps/token/contracts/Token.sol +++ b/apps/token/contracts/Token.sol @@ -21,6 +21,8 @@ contract Token is ERC20Token, AragonApp { } function mintFor(address contributorAccount, uint256 amount, uint32 contributionId) public isInitialized auth(MINT_TOKEN_ROLE) { + require(amount > 0, "amount should be greater than zero"); + uint256 amountInWei = amount.mul(1 ether); _mint(contributorAccount, amountInWei); emit LogMint(contributorAccount, amount, contributionId); diff --git a/apps/token/test/app.js b/apps/token/test/app.js deleted file mode 100644 index 2f583dd..0000000 --- a/apps/token/test/app.js +++ /dev/null @@ -1,5 +0,0 @@ -// const Token = artifacts.require('Token.sol'); - -contract('Token', (_accounts) => { - it('should be tested'); -}); diff --git a/apps/token/test/token.js b/apps/token/test/token.js new file mode 100644 index 0000000..b1db44f --- /dev/null +++ b/apps/token/test/token.js @@ -0,0 +1,123 @@ +const namehash = require('ethers').utils.namehash; + +// eslint-disable-next-line no-undef +const Token = artifacts.require("Token.sol"); + +// eslint-disable-next-line no-undef +const getContract = name => artifacts.require(name); +const { assertRevert } = require('@aragon/test-helpers/assertThrow'); + +const ZERO_ADDR = '0x0000000000000000000000000000000000000000'; + +contract('Token app', (accounts) => { + let kernelBase, aclBase, daoFactory, dao, r, acl, token; + + 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 Token.new()).address, + 0x0, + false, + { from: root } + ); + token = Token.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 token (app) + await token.initialize(appsId); + + //create token mint permission for coin owner + await acl.createPermission( + root, + token.address, + await token.MINT_TOKEN_ROLE(), + root, + { from: root } + ); + + }); + + describe("Owner default space permissions", async () => { + it('check owner is token issuer', async () => { + let tokenIssuerPermission = await acl.hasPermission(root, token.address, await token.MINT_TOKEN_ROLE()); + // eslint-disable-next-line no-undef + assert.equal(tokenIssuerPermission, true); + }); + }); + + describe("Token issuing", async () => { + let name = "Kredits"; + let symbol = "₭S"; + let decimals = 18; + + it("check token properties", async () => { + assert.equal(await token.name(), name); // eslint-disable-line no-undef + assert.equal(await token.symbol(), symbol); // eslint-disable-line no-undef + assert.equal(await token.decimals(), decimals); // eslint-disable-line no-undef + }); + + }); + + describe("Token minting", async () => { + let tokenToMint = 250; + let ether = 1000000000000000000; + + it("should revert when mint tokens from an address that does not have minting permission", async () => { + return assertRevert(async () => { + await token.mintFor(root, tokenToMint, 1, { from: member1}); + 'address does not have permission to mint tokens'; + }); + }); + + it("should revert when mint tokens to address(0)", async () => { + return assertRevert(async () => { + await token.mintFor(ZERO_ADDR, tokenToMint, 1, { from: root}); + 'invalid contributor address'; + }); + }); + + it("should revert when mint amount of tokens equal to 0", async () => { + return assertRevert(async () => { + await token.mintFor(root, 0, 1, { from: root}); + 'amount to mint should be greater than zero'; + }); + }); + + it("mint tokens", async () => { + await token.mintFor(root, tokenToMint, 1, { from: root }); + let ownerBalance = await token.balanceOf(root); + let totalSupply = await token.totalSupply(); + assert.equal(ownerBalance.toNumber(), tokenToMint*ether); // eslint-disable-line no-undef + assert.equal(totalSupply.toNumber(), tokenToMint*ether); // eslint-disable-line no-undef + }); + }); +}); -- 2.25.1 From 983d4995718246506c519ae2584d7d77d4f83582 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 29 Jul 2019 13:49:52 +0100 Subject: [PATCH 2/6] update travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index b745388..1e498d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ cache: install: - npm install + - npm run install-all before_script: - npm run devchain & -- 2.25.1 From b759bbbb2107a19fff2acc9c97d413965afbb88d Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 29 Jul 2019 14:13:31 +0100 Subject: [PATCH 3/6] update travis config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1e498d8..b745388 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ cache: install: - npm install - - npm run install-all before_script: - npm run devchain & -- 2.25.1 From 97e2897f2d40fbb1f7d65571142a814b467ea187 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Mon, 29 Jul 2019 15:03:51 +0100 Subject: [PATCH 4/6] fix tests --- apps/token/contracts/test/Spoof.sol | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 apps/token/contracts/test/Spoof.sol diff --git a/apps/token/contracts/test/Spoof.sol b/apps/token/contracts/test/Spoof.sol new file mode 100644 index 0000000..34fb889 --- /dev/null +++ b/apps/token/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 { + // ... +} -- 2.25.1 From 9e43c7b93a9bf86221ba8654a0315a4e038b2f10 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Wed, 31 Jul 2019 15:44:44 +0100 Subject: [PATCH 5/6] modify error message --- apps/token/contracts/Token.sol | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/token/contracts/Token.sol b/apps/token/contracts/Token.sol index 35acc03..deda698 100644 --- a/apps/token/contracts/Token.sol +++ b/apps/token/contracts/Token.sol @@ -6,6 +6,8 @@ import "./ERC20Token.sol"; contract Token is ERC20Token, AragonApp { bytes32 public constant MINT_TOKEN_ROLE = keccak256("MINT_TOKEN_ROLE"); + string private constant ERROR_INVALID_AMOUNT = "Amount should be greater than zero"; + // ensure alphabetic order enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; @@ -21,7 +23,7 @@ contract Token is ERC20Token, AragonApp { } function mintFor(address contributorAccount, uint256 amount, uint32 contributionId) public isInitialized auth(MINT_TOKEN_ROLE) { - require(amount > 0, "amount should be greater than zero"); + require(amount > 0, ERROR_INVALID_AMOUNT); uint256 amountInWei = amount.mul(1 ether); _mint(contributorAccount, amountInWei); -- 2.25.1 From c8ba573fb264f3853f75d358fdde1cca4a955409 Mon Sep 17 00:00:00 2001 From: Haythem Sellami Date: Wed, 31 Jul 2019 16:05:20 +0100 Subject: [PATCH 6/6] modify error message --- apps/token/contracts/Token.sol | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/token/contracts/Token.sol b/apps/token/contracts/Token.sol index deda698..06810e4 100644 --- a/apps/token/contracts/Token.sol +++ b/apps/token/contracts/Token.sol @@ -6,8 +6,6 @@ import "./ERC20Token.sol"; contract Token is ERC20Token, AragonApp { bytes32 public constant MINT_TOKEN_ROLE = keccak256("MINT_TOKEN_ROLE"); - string private constant ERROR_INVALID_AMOUNT = "Amount should be greater than zero"; - // ensure alphabetic order enum Apps { Contribution, Contributor, Proposal, Token } bytes32[4] public appIds; @@ -23,7 +21,7 @@ contract Token is ERC20Token, AragonApp { } function mintFor(address contributorAccount, uint256 amount, uint32 contributionId) public isInitialized auth(MINT_TOKEN_ROLE) { - require(amount > 0, ERROR_INVALID_AMOUNT); + require(amount > 0, "INVALID_AMOUNT"); uint256 amountInWei = amount.mul(1 ether); _mint(contributorAccount, amountInWei); -- 2.25.1