Compare commits

...

20 Commits

Author SHA1 Message Date
01d4e66c74 update tests 2019-11-20 18:12:11 +01:00
9d71b29f0f fix apm 2019-11-20 16:28:07 +01:00
4ef5db5185 modify travis config 2019-10-05 18:16:27 +01:00
b2d4277a11 modify travis config 2019-10-05 18:06:01 +01:00
bc37ab5686 fix revert claim test 2019-09-24 15:55:41 +01:00
c2ada23590 update travis config 2019-09-20 10:16:57 +01:00
dc3d267cd5 modify travis config 2019-09-20 10:07:48 +01:00
7b546a31a7 modify travis config 2019-09-20 10:01:19 +01:00
3515bdfda9 refactor 2019-09-19 16:05:25 +01:00
42c0782c0e fix veto tests 2019-09-19 10:45:44 +01:00
6b0083eeb8 clean tests 2019-09-19 10:10:11 +01:00
965b9cf18c Merge branch 'master' into tests/contracts-contribution 2019-09-19 09:59:25 +01:00
f8d89a1b0d Merge branch 'master' into tests/contracts-contribution 2019-08-14 10:33:47 +01:00
2fc6850c52 modify getBlockNumber() function 2019-08-10 15:35:22 +01:00
c823bb977a try to fix tests 2019-08-09 23:52:29 +01:00
a6806ec4ff add tests 2019-08-06 11:57:36 +01:00
3d6ca962e8 clean 2019-08-06 11:39:38 +01:00
268353287a fix claim contribution test 2019-08-06 11:32:44 +01:00
1305a29966 add expectation messages 2019-08-03 12:41:16 +01:00
9db1ffddcb contribution contracts tests 2019-08-02 17:11:30 +01:00
12 changed files with 14583 additions and 2493 deletions

View File

@ -15,19 +15,26 @@ cache:
- apps/token/node_modules
- apps/vault/node_modules
env:
- TASK=lint:wrapper
- TASK=lint:contract-tests
- TASK=test:token
- TASK=test:contributor
- TASK=test:contribution
- TASK=test:proposal
install:
- npm install -g @aragon/cli
- npm install -g truffle
- npm install
before_script:
- npm run devchain &
- npm run devchain > /dev/null &
- sleep 5
script:
- npm run lint:wrapper
- npm run lint:contract-tests
- npm run test
- travis_wait 60 npm run $TASK
branches:
only:
- master
- master

View File

@ -152,6 +152,8 @@ contract Contribution is AragonApp {
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) {
//require(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope');
require(amount > 0, "INVALID_AMOUNT");
uint32 contributionId = contributionsCount + 1;
ContributionData storage c = contributions[contributionId];
c.exists = true;

View File

@ -0,0 +1,18 @@
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";
import "../../../contributor/contracts/Contributor.sol";
import "../../../token/contracts/Token.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 {
// ...
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +0,0 @@
// const Contribution = artifacts.require('Contribution.sol');
contract('Contribution', (_accounts) => {
it('should be tested');
});

View File

@ -0,0 +1,332 @@
const namehash = require('ethers').utils.namehash;
// eslint-disable-next-line no-undef
const Contribution = artifacts.require("Contribution.sol");
// eslint-disable-next-line no-undef
const Contributor = artifacts.require("Contributor.sol");
// 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';
const timeTravel = function(time){
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-undef
web3.currentProvider.sendAsync({
jsonrpc: "2.0",
method: "evm_increaseTime",
params: [time], //86400 is num seconds in day
id: new Date().getSeconds(),
}, (err, result) => {
if(err) {
return reject(err);
}
return resolve(result);
});
});
};
const mineBlock = function() {
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-undef
web3.currentProvider.sendAsync({
jsonrpc: "2.0",
method: "evm_mine",
params: [],
id: new Date().getSeconds(),
}, (err, result) => {
if(err){ return reject(err); }
return resolve(result);
});
});
};
const getBlockNumber = function() {
return new Promise((resolve, reject) => {
// eslint-disable-next-line no-undef
web3.eth.getBlockNumber(async (err, res) => {
if (err || !res) return reject(err);
resolve(res);
});
});
};
contract('Contribution app', (accounts) => {
// eslint-disable-next-line no-undef
let kernelBase, aclBase, daoFactory, r, dao, acl, contribution, token, contributor;
const root = accounts[0];
const member1 = accounts[1];
const blocksToWait = 40320;
// 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 }
);
//apps id
let appsId = [];
appsId[0] = namehash("kredits-contribution");
appsId[1] = namehash("kredits-contributor");
appsId[2] = namehash("kredits-proposal");
appsId[3] = namehash("kredits-token");
//get new app instance from DAO
let receipt = await dao.newAppInstance(
appsId[0],
(await Contribution.new()).address,
0x0,
false,
{ from: root }
);
contribution = Contribution.at(
receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy
);
receipt = await dao.newAppInstance(
appsId[3],
(await Token.new()).address,
0x0,
false,
{ from: root }
);
token = Token.at(
receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy
);
receipt = await dao.newAppInstance(
appsId[1],
(await Contributor.new()).address,
0x0,
false,
{ from: root }
);
contributor = Contributor.at(
receipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy
);
//init app
await contribution.initialize(appsId);
await acl.createPermission(
root,
contribution.address,
await contribution.ADD_CONTRIBUTION_ROLE(),
root,
{ from: root }
);
await acl.createPermission(
root,
contribution.address,
await contribution.VETO_CONTRIBUTION_ROLE(),
root,
{ from: root }
);
//init token (app)
await token.initialize(appsId);
//create token mint permission for coin owner
await acl.createPermission(
contribution.address,
token.address,
await token.MINT_TOKEN_ROLE(),
root,
{ from: root }
);
//init contributor app
await contributor.initialize(root, appsId);
await acl.createPermission(
root,
contributor.address,
await contributor.MANAGE_CONTRIBUTORS_ROLE(),
root,
{ from: root }
);
});
describe("Owner default space permissions", async () => {
it('check owner can add contribution', async () => {
let addContributionPermission = await acl.hasPermission(root, contribution.address, await contribution.ADD_CONTRIBUTION_ROLE());
// eslint-disable-next-line no-undef
assert.equal(addContributionPermission, true);
});
it('check owner can veto contribution', async () => {
let vetoContributionPermission = await acl.hasPermission(root, contribution.address, await contribution.VETO_CONTRIBUTION_ROLE());
// eslint-disable-next-line no-undef
assert.equal(vetoContributionPermission, true);
});
it('check contribution app can mint token', async () => {
let mintTokenPermission = await acl.hasPermission(contribution.address, token.address, await token.MINT_TOKEN_ROLE());
// eslint-disable-next-line no-undef
assert.equal(mintTokenPermission, true);
});
});
describe("Add contribution", async () => {
// contributor detials
let account, contributorHashDigest, contributorHashFunction, contributorHashSize;
// contribution details
let amount, contributorId, hashDigest, hashFunction, hashSize;
// eslint-disable-next-line no-undef
before(async () => {
// Add contributor from Contributor app
account = root;
contributorHashDigest = '0x0000000000000000000000000000000000000000000000000000000000000000';
contributorHashFunction = 0;
contributorHashSize = 0;
await contributor.addContributor(account, contributorHashDigest, contributorHashFunction, contributorHashSize);
// eslint-disable-next-line no-undef
assert.equal(await contributor.addressExists(account), true);
amount = 100;
contributorId = await contributor.getContributorIdByAddress(root);
hashDigest = '0x0000000000000000000000000000000000000000000000000000000000000000';
hashFunction = 1;
hashSize = 1;
});
it("should revert when add contribution from address that does not have permission", async () => {
return assertRevert(async () => {
await contribution.add(amount, contributorId, hashDigest, hashFunction, hashSize, {from: member1});
'sender does not have permission';
});
});
it("should revert when add contribution with amount equal to zero", async () => {
return assertRevert(async () => {
await contribution.add(0, contributorId, hashDigest, hashFunction, hashSize, {from: root});
'amount equal to zero';
});
});
it("should add contribution", async () => {
let contributionCountBefore = await contribution.contributionsCount();
await contribution.add(amount, contributorId, hashDigest, hashFunction, hashSize, {from: root});
let contributionCountAfter = await contribution.contributionsCount();
// eslint-disable-next-line no-undef
assert.equal(contributionCountAfter.toNumber()-contributionCountBefore.toNumber(), 1, "contributions counter incremented");
let contributionObject = await contribution.getContribution(contributionCountAfter.toNumber());
// eslint-disable-next-line no-undef
assert.equal(contributionObject[1].toNumber(), contributorId.toNumber(), "contribution added belong to contributor id");
let isExist = await contribution.exists(contributionCountAfter.toNumber());
// eslint-disable-next-line no-undef
assert.equal(isExist, true, "contribution exist");
});
});
describe("Veto contribution", async () => {
it("should revert when veto from address that does not have permission", async () => {
const contributionId = await contribution.contributionsCount();
return assertRevert(async () => {
await contribution.veto(contributionId.toNumber(), {from: member1});
'sender does not have permission to veto';
});
});
it("should revert when veto contribution that does not exist", async () => {
const contributionId = await contribution.contributionsCount();
return assertRevert(async () => {
await contribution.veto(contributionId.toNumber()+1, {from: root});
'contribution not found';
});
});
it("veto contribution", async () => {
const contributionId = await contribution.contributionsCount();
if(contributionId < 10) {
return assertRevert(async () => {
await contribution.veto(contributionId.toNumber(), {from: root});
'can not veto first 10 contribution';
});
}
else {
await contribution.veto(contributionId.toNumber(), {from: root});
let contributionObject = await contribution.getContribution(contributionId.toNumber());
// eslint-disable-next-line no-undef
assert(contributionObject[9], true);
}
});
});
describe("Claim contribution", async () => {
let contributionId;
// eslint-disable-next-line no-undef
before(async () =>{
//add contribution
let amount = 200;
let contributorId = await contributor.getContributorIdByAddress(root);
let contributionHashDigest = '0x0000000000000000000000000000000000000000000000000000000000000000';
let contributionHashFunction = 1;
let contributionHashSize = 1;
await contribution.add(amount, contributorId.toNumber(), contributionHashDigest, contributionHashFunction, contributionHashSize, {from: root});
contributionId = await contribution.contributionsCount();
});
it("should revert when claim contribution that does not exist", async () => {
return assertRevert(async () => {
await contribution.claim(contributionId.toNumber()+1, {from: root});
'contribution not found';
});
});
it("should revert when claim contribution before confirmation block", async () => {
if(contributionId > 10) {
return assertRevert(async () => {
await contribution.claim(contributionId.toNumber(), {from: root});
'contribution not confirmed yet';
});
}
});
it("claim contribution", async () => {
let contributionObject = await contribution.getContribution(contributionId.toNumber());
let confirmationBlock = contributionObject[7];
let chainBlockNumberBefore = await getBlockNumber();
if(contributionId > 10) {
await timeTravel(blocksToWait);
await mineBlock();
let chainBlockNumberAfter = await getBlockNumber();
// eslint-disable-next-line no-undef
assert.equal(chainBlockNumberAfter.toNumber()-chainBlockNumberBefore.toNumber(), confirmationBlock.toNumber());
}
//Claim contribution
await contribution.claim(contributionId, {from: root});
contributionObject = await contribution.getContribution(contributionId.toNumber());
// eslint-disable-next-line no-undef
assert(contributionObject[3], true);
});
it("should revert when claim already claimed contribution", async () => {
return assertRevert(async () => {
await contribution.claim(contributionId.toNumber(), {from: root});
'contribution already claimed';
});
});
});
});

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,9 @@
"environments": {
"development": {
"network": "development",
"apm": "open.aragonpm.eth",
"apm": {
"open.aragonpm.eth"
},
"registry": "0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1",
"appName": "dummy.open.aragonpm.eth"
},
@ -44,7 +46,9 @@
"wsRPC": "wss://rinkeby.eth.aragon.network/ws",
"daoFactory": "0x2298d27a9b847c681d2b2c2828ab9d79013f5f1d",
"appName": "dummy.open.aragonpm.eth",
"apm": "open.aragonpm.eth"
"apm": {
"open.aragonpm.eth"
}
},
"kovan": {
"network": "kovan",
@ -53,7 +57,9 @@
"default": {
"network": "development",
"appName": "dummy.aragonpm.eth",
"apm": "open.aragonpm.eth"
"apm": {
"open.aragonpm.eth"
}
}
},
"path": "contracts/misc/DummyApp.sol"

893
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,7 @@
"devDependencies": {
"@aragon/kits-base": "^1.0.0",
"@aragon/os": "^4.2.0",
"@aragon/test-helpers": "^2.0.0",
"async-each-series": "^1.1.0",
"cli-table": "^0.3.1",
"eslint": "^5.16.0",