contribution app unit tests
This commit is contained in:
parent
ab6d6a4025
commit
5a78a50990
@ -137,6 +137,7 @@ contract Contribution is AragonApp {
|
|||||||
|
|
||||||
function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_CONTRIBUTION_ROLE) {
|
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(canPerform(msg.sender, ADD_CONTRIBUTION_ROLE, new uint32[](0)), 'nope');
|
||||||
|
require(amount > 0, "amount equal to zero");
|
||||||
uint32 contributionId = contributionsCount + 1;
|
uint32 contributionId = contributionsCount + 1;
|
||||||
ContributionData storage c = contributions[contributionId];
|
ContributionData storage c = contributions[contributionId];
|
||||||
c.exists = true;
|
c.exists = true;
|
||||||
|
16
apps/contribution/contracts/test/Spoof.sol
Normal file
16
apps/contribution/contracts/test/Spoof.sol
Normal file
@ -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 {
|
||||||
|
// ...
|
||||||
|
}
|
1377
apps/contribution/package-lock.json
generated
1377
apps/contribution/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -6,13 +6,14 @@
|
|||||||
"@aragon/os": "^4.1.0",
|
"@aragon/os": "^4.1.0",
|
||||||
"@aragon/cli": "^5.5.0"
|
"@aragon/cli": "^5.5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {
|
||||||
|
"@aragon/test-helpers": "^1.0.0"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "npm run start:aragon:ipfs",
|
"start": "npm run start:aragon:ipfs",
|
||||||
"start:aragon:ipfs": "aragon run",
|
"start:aragon:ipfs": "aragon run",
|
||||||
"start:aragon:http": "aragon run --http localhost:8001 --http-served-from ./dist",
|
"start:aragon:http": "aragon run --http localhost:8001 --http-served-from ./dist",
|
||||||
"start:app": "",
|
"start:app": "",
|
||||||
"test": "aragon contracts test",
|
|
||||||
"compile": "aragon contracts compile",
|
"compile": "aragon contracts compile",
|
||||||
"sync-assets": "",
|
"sync-assets": "",
|
||||||
"build:app": "",
|
"build:app": "",
|
||||||
@ -21,7 +22,10 @@
|
|||||||
"publish:patch": "aragon apm publish patch",
|
"publish:patch": "aragon apm publish patch",
|
||||||
"publish:minor": "aragon apm publish minor",
|
"publish:minor": "aragon apm publish minor",
|
||||||
"publish:major": "aragon apm publish major",
|
"publish:major": "aragon apm publish major",
|
||||||
"versions": "aragon apm versions"
|
"versions": "aragon apm versions",
|
||||||
|
"ganache-cli:test": "./node_modules/@aragon/test-helpers/ganache-cli.sh",
|
||||||
|
"test": "aragon contracts test",
|
||||||
|
"coverage": "SOLIDITY_COVERAGE=true npm run ganache-cli:test"
|
||||||
},
|
},
|
||||||
"keywords": []
|
"keywords": []
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
const Contribution = artifacts.require('Contribution.sol')
|
|
||||||
|
|
||||||
contract('Contribution', (accounts) => {
|
|
||||||
it('should be tested')
|
|
||||||
})
|
|
170
apps/contribution/test/contribution.js
Normal file
170
apps/contribution/test/contribution.js
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
const namehash = require('eth-ens-namehash').hash;
|
||||||
|
|
||||||
|
const Contribution = artifacts.require("Contribution.sol");
|
||||||
|
|
||||||
|
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, acl, contribution;
|
||||||
|
|
||||||
|
const root = accounts[0];
|
||||||
|
const member1 = accounts[1];
|
||||||
|
|
||||||
|
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 Contribution.new()).address,
|
||||||
|
0x0,
|
||||||
|
false,
|
||||||
|
{ from: root }
|
||||||
|
)
|
||||||
|
contribution = Contribution.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 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 }
|
||||||
|
)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
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());
|
||||||
|
assert.equal(addContributionPermission, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('check owner can veto contribution', async() => {
|
||||||
|
let vetoContributionPermission = await acl.hasPermission(root, contribution.address, await contribution.VETO_CONTRIBUTION_ROLE());
|
||||||
|
assert.equal(vetoContributionPermission, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Add contribution", async() => {
|
||||||
|
let amount = 100;
|
||||||
|
let contributorId = 1;
|
||||||
|
let hashDigest = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
||||||
|
let hashFunction = 1;
|
||||||
|
let 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("add contribution", async() => {
|
||||||
|
let contributionCountBefore = await contribution.contributionsCount();
|
||||||
|
await contribution.add(amount, contributorId, hashDigest, hashFunction, hashSize, {from: root});
|
||||||
|
let contributionCountAfter = await contribution.contributionsCount();
|
||||||
|
assert.equal(contributionCountAfter.toNumber()-contributionCountBefore.toNumber(), 1);
|
||||||
|
let contributionObject = await contribution.getContribution(contributionCountAfter.toNumber());
|
||||||
|
assert.equal(contributionObject[1], contributorId);
|
||||||
|
let isExist = await contribution.exists(contributionCountAfter.toNumber());
|
||||||
|
assert.equal(isExist, true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Veto/Claim contribution", async() => {
|
||||||
|
|
||||||
|
it("should revert when veto from address that does not have permission", async() => {
|
||||||
|
let 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() => {
|
||||||
|
let contributionId = await contribution.contributionsCount();
|
||||||
|
return assertRevert(async() => {
|
||||||
|
await contribution.veto(contributionId.toNumber()+1, {from: root});
|
||||||
|
'contribution not found'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should revert when claim contribution that does not exist", async() => {
|
||||||
|
let contributionId = await contribution.contributionsCount();
|
||||||
|
return assertRevert(async() => {
|
||||||
|
await contribution.claim(contributionId.toNumber()+1, {from: root});
|
||||||
|
'contribution not found'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("claim contribution", async() => {
|
||||||
|
let contributionId = await contribution.contributionsCount();
|
||||||
|
await contribution.claim(contributionId);
|
||||||
|
let contributionObject = await contribution.getContribution(contributionId.toNumber());
|
||||||
|
assert(contributionObject[3], true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should revert when claim already claimed contribution", async() => {
|
||||||
|
let contributionId = await contribution.contributionsCount();
|
||||||
|
return assertRevert(async() => {
|
||||||
|
await contribution.claim(contributionId.toNumber(), {from: root});
|
||||||
|
'contribution already claimed'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should revert when veto already claimed contribution", async() => {
|
||||||
|
let contributionId = await contribution.contributionsCount();
|
||||||
|
return assertRevert(async() => {
|
||||||
|
await contribution.veto(contributionId.toNumber(), {from: root});
|
||||||
|
'contribution already claimed'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
@ -23,6 +23,7 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"test:token": "cd apps/token && aragon contracts test --environment default",
|
"test:token": "cd apps/token && aragon contracts test --environment default",
|
||||||
"test:contributor": "cd apps/contributor && aragon contracts test --environment default",
|
"test:contributor": "cd apps/contributor && aragon contracts test --environment default",
|
||||||
|
"test:contribution": "cd apps/contribution && aragon contracts test --environment default",
|
||||||
"test:kit": "aragon contracts test --environment default"
|
"test:kit": "aragon contracts test --environment default"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user