From 8292f66b1dc8779ecca5621422004dc65ffc2e5b Mon Sep 17 00:00:00 2001 From: topocount Date: Wed, 1 May 2019 17:02:13 -0700 Subject: [PATCH 1/7] Create tests to increase coverage - Line 188: can't initialiaze with invalid vault address - Line 393: can't approve nonexistent assignment - Line 457: can't approve work for fulfilled bounty --- apps/projects/contracts/Projects.sol | 6 +- apps/projects/test/projects.test.js | 1625 ++++++++++++++------------ 2 files changed, 858 insertions(+), 773 deletions(-) diff --git a/apps/projects/contracts/Projects.sol b/apps/projects/contracts/Projects.sol index b01f7aaf0..dbf087537 100644 --- a/apps/projects/contracts/Projects.sol +++ b/apps/projects/contracts/Projects.sol @@ -204,7 +204,7 @@ contract Projects is IsContract, AragonApp { /** - * @notice Update settings for the Projects app + * @notice Update settings for the Projects app */ function changeBountySettings( uint256[] _expMultipliers, @@ -441,9 +441,7 @@ contract Projects is IsContract, AragonApp { submission.submissionHash = _updatedSubmissionHash; if (_approved) { - if (issue.hasBounty) { - bounties.acceptFulfillment(issue.standardBountyId, submission.fulfillmentId); - } + bounties.acceptFulfillment(issue.standardBountyId, submission.fulfillmentId); issue.fulfilled = true; submission.status = SubmissionStatus.Accepted; emit SubmissionAccepted(_submissionNumber, _repoId, _issueNumber); diff --git a/apps/projects/test/projects.test.js b/apps/projects/test/projects.test.js index 7bde89757..07ff11948 100644 --- a/apps/projects/test/projects.test.js +++ b/apps/projects/test/projects.test.js @@ -28,6 +28,8 @@ contract('Projects App', accounts => { const owner1 = accounts[0] // 0xb421 const bountyAdder = accounts[2] const repoRemover = accounts[3] + const repoIdString = 'MDEwOIJlcG9zaXRvcnkxNjY3MjlyMjY=' + const ZERO_ADDR = '0x0000000000000000000000000000000000000000' before(async () => { //Create Base DAO Contracts @@ -144,901 +146,986 @@ contract('Projects App', accounts => { //bounties = StandardBounties.at(registry.address) - await app.initialize(bounties.address, vault.address, '') }) - context('creating and retrieving repos and bounties', () => { - let repoId - - beforeEach(async () => { - repoId = addedRepo( - await app.addRepo( - 'MDEwOIJlcG9zaXRvcnkxNjY3MjlyMjY=', // repoId - { from: owner1 } + context('pre-initialization', () => { + it('will not initialize with invalid vault address', async () =>{ + return assertRevert(async () => { + await app.initialize( + bounties.address, + ZERO_ADDR, + '', ) - ) - }) - - it('creates a repo id entry', async () => { - assert.equal( - repoId, - 'MDEwOIJlcG9zaXRvcnkxNjY3MjlyMjY=', // TODO: extract to a variable - 'repo is created and ID is returned' - ) + }) }) - - it('retrieve repo array length', async () => { - const repolength = await app.getReposCount() - assert(repolength, 1, 'valid repo length returned') + }) + context('post-initialization', () => { + beforeEach(async () =>{ + await app.initialize(bounties.address, vault.address, '') }) - it('retrieve repo information successfully', async () => { - const repoInfo = await app.getRepo(repoId, { from: owner1 }) - const result = repoInfo // get repo index on the registry - assert.equal( - result, - 0, // repoIndex - 'valid repo info returned' - ) - }) + context('creating and retrieving repos and bounties', () => { + let repoId - it('can remove repos', async () => { - repoId2 = addedRepo( - await app.addRepo( - 'MDawOlJlcG9zaXRvcnk3NTM5NTIyNA==', // repoId - { from: owner1 } - ) - ) - app.removeRepo(repoId, { from: repoRemover }) - app.removeRepo(repoId2, { from: repoRemover }) - }) - - context('standard bounty verification tests', () => { beforeEach(async () => { - await bounties.issueBounty( - accounts[0], - 2528821098, - 'data', - 1000, - 0x0, - false, - 0x0, - { from: accounts[0] } + repoId = addedRepo( + await app.addRepo( + repoIdString, // repoId + { from: owner1 } + ) ) }) - it('StandardBounties Deployed Correctly', async () => { - let owner = await bounties.owner() - assert(owner == accounts[0]) + it('creates a repo id entry', async () => { + assert.equal( + repoId, + repoIdString, // TODO: extract to a variable + 'repo is created and ID is returned' + ) }) - it('verifies that simple bounty contribution and activation functions', async () => { - await bounties.contribute(0, 1000, { from: accounts[0], value: 1000 }) - let bounty = await bounties.getBounty(0) - assert(bounty[4] == 0) - await bounties.activateBounty(0, 0, { from: accounts[0] }) - bounty = await bounties.getBounty(0) - assert(bounty[4] == 1) + it('retrieve repo array length', async () => { + const repolength = await app.getReposCount() + assert(repolength, 1, 'valid repo length returned') }) - it('verifies that basic fulfillment acceptance flow works', async () => { - await bounties.activateBounty(0, 1000, { - from: accounts[0], - value: 1000, - }) - await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) - let fulfillment = await bounties.getFulfillment(0, 0) - assert(fulfillment[0] === false) - await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) - fulfillment = await bounties.getFulfillment(0, 0) - assert(fulfillment[0] === true) + it('retrieve repo information successfully', async () => { + const repoInfo = await app.getRepo(repoId, { from: owner1 }) + const result = repoInfo // get repo index on the registry + assert.equal( + result, + 0, // repoIndex + 'valid repo info returned' + ) }) - it('verifies that bounty fulfillment completes', async () => { - await bounties.issueBounty( - accounts[0], - 2528821098, - 'data', - 1000, - 0x0, - false, - 0x0, - { from: accounts[0] } + it('can remove repos', async () => { + repoId2 = addedRepo( + await app.addRepo( + 'MDawOlJlcG9zaXRvcnk3NTM5NTIyNA==', // repoId + { from: owner1 } + ) ) - await bounties.activateBounty(0, 1000, { - from: accounts[0], - value: 1000, - }) - await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) - let fulfillment = await bounties.getFulfillment(0, 0) - assert(fulfillment[0] === false) - await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) - fulfillment = await bounties.getFulfillment(0, 0) - const bounty = await bounties.getBounty(0) - assert(fulfillment[0] === true) - assert(bounty[5] == 0) + app.removeRepo(repoId, { from: repoRemover }) + app.removeRepo(repoId2, { from: repoRemover }) }) - it('verifies that bounty fulfillment flow works to completion with several fulfillments', async () => { - await bounties.issueBounty( - accounts[0], - 2528821098, - 'data', - 1000, - 0x0, - false, - 0x0, - { from: accounts[0] } - ) - await bounties.activateBounty(0, 1000, { - from: accounts[0], - value: 1000, + context('standard bounty verification tests', () => { + beforeEach(async () => { + await bounties.issueBounty( + accounts[0], + 2528821098, + 'data', + 1000, + 0x0, + false, + 0x0, + { from: accounts[0] } + ) }) - await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) - await bounties.fulfillBounty(0, 'data2', { from: accounts[2] }) - let fulfillment = await bounties.getFulfillment(0, 0) - assert(fulfillment[0] === false) - await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) - fulfillment = await bounties.getFulfillment(0, 0) - const bounty = await bounties.getBounty(0) - assert(fulfillment[0] === true) - assert(bounty[5] == 0) - }) - }) - context('issue, fulfill, and accept fulfillment for bulk bounties', () => { - let issue3Receipt - const issueNumber = 1 + it('StandardBounties Deployed Correctly', async () => { + let owner = await bounties.owner() + assert(owner == accounts[0]) + }) - beforeEach('issue bulk bounties', async () => { - issue3Receipt = addedBounties( - await app.addBounties( - Array(3).fill(repoId), - [ 1, 2, 3 ], - [ 10, 20, 30 ], - [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], - [ false, false, false ], - [ 0, 0, 0 ], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', - 'something', - { from: bountyAdder, value: 60 } + it('verifies that simple bounty contribution and activation functions', async () => { + await bounties.contribute(0, 1000, { from: accounts[0], value: 1000 }) + let bounty = await bounties.getBounty(0) + assert(bounty[4] == 0) + await bounties.activateBounty(0, 0, { from: accounts[0] }) + bounty = await bounties.getBounty(0) + assert(bounty[4] == 1) + }) + + it('verifies that basic fulfillment acceptance flow works', async () => { + await bounties.activateBounty(0, 1000, { + from: accounts[0], + value: 1000, + }) + await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) + let fulfillment = await bounties.getFulfillment(0, 0) + assert(fulfillment[0] === false) + await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) + fulfillment = await bounties.getFulfillment(0, 0) + assert(fulfillment[0] === true) + }) + + it('verifies that bounty fulfillment completes', async () => { + await bounties.issueBounty( + accounts[0], + 2528821098, + 'data', + 1000, + 0x0, + false, + 0x0, + { from: accounts[0] } ) - ) - }) + await bounties.activateBounty(0, 1000, { + from: accounts[0], + value: 1000, + }) + await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) + let fulfillment = await bounties.getFulfillment(0, 0) + assert(fulfillment[0] === false) + await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) + fulfillment = await bounties.getFulfillment(0, 0) + const bounty = await bounties.getBounty(0) + assert(fulfillment[0] === true) + assert(bounty[5] == 0) + }) - it('verifies bounty data contains correct IPFS hashes', async () => { - const issue3Bounty = issue3Receipt.args.bountySize.toNumber() - assert.strictEqual(issue3Bounty, 30, 'bounty not added') - const IssueData1 = await app.getIssue(repoId, 1) - const bountyId1 = IssueData1[1].toNumber() - const bountyData1 = await bounties.getBountyData(bountyId1) - assert.strictEqual( - bountyData1, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', - 'IPFS hash stored correctly' - ) - const IssueData2 = await app.getIssue(repoId, 2) - const bountyId2 = IssueData2[1].toNumber() - const bountyData2 = await bounties.getBountyData(bountyId2) - assert.strictEqual( - bountyData2, - 'QmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWu', - 'IPFS hash stored correctly' - ) - const IssueData3 = await app.getIssue(repoId, 3) - const bountyId3 = IssueData3[1].toNumber() - const bountyData3 = await bounties.getBountyData(bountyId3) - assert.strictEqual( - bountyData3, - 'QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', - 'IPFS hash stored correctly' - ) + it('verifies that bounty fulfillment flow works to completion with several fulfillments', async () => { + await bounties.issueBounty( + accounts[0], + 2528821098, + 'data', + 1000, + 0x0, + false, + 0x0, + { from: accounts[0] } + ) + await bounties.activateBounty(0, 1000, { + from: accounts[0], + value: 1000, + }) + await bounties.fulfillBounty(0, 'data', { from: accounts[1] }) + await bounties.fulfillBounty(0, 'data2', { from: accounts[2] }) + let fulfillment = await bounties.getFulfillment(0, 0) + assert(fulfillment[0] === false) + await bounties.acceptFulfillment(0, 0, { from: accounts[0] }) + fulfillment = await bounties.getFulfillment(0, 0) + const bounty = await bounties.getBounty(0) + assert(fulfillment[0] === true) + assert(bounty[5] == 0) + }) }) - it('allows users to request assignment', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - response = await app.getApplicant(repoId, issueNumber, 0) - assert.strictEqual(response[0], root, 'applicant address incorrect') - assert.strictEqual( - response[1], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - 'application IPFS hash incorrect' - ) - }) + context('issue, fulfill, and accept fulfillment for ETH bounties', () => { + let issue3Receipt + const issueNumber = 1 + + beforeEach('issue bulk bounties', async () => { + issue3Receipt = addedBounties( + await app.addBounties( + Array(3).fill(repoId), + [ 1, 2, 3 ], + [ 10, 20, 30 ], + [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], + [ false, false, false ], + [ 0, 0, 0 ], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', + 'something', + { from: bountyAdder, value: 60 } + ) + ) + }) - it('users cannot apply for a given issue more than once', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - assertRevert(async () => { + it('verifies bounty data contains correct IPFS hashes', async () => { + const issue3Bounty = issue3Receipt.args.bountySize.toNumber() + assert.strictEqual(issue3Bounty, 30, 'bounty not added') + const IssueData1 = await app.getIssue(repoId, 1) + const bountyId1 = IssueData1[1].toNumber() + const bountyData1 = await bounties.getBountyData(bountyId1) + assert.strictEqual( + bountyData1, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', + 'IPFS hash stored correctly' + ) + const IssueData2 = await app.getIssue(repoId, 2) + const bountyId2 = IssueData2[1].toNumber() + const bountyData2 = await bounties.getBountyData(bountyId2) + assert.strictEqual( + bountyData2, + 'QmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWu', + 'IPFS hash stored correctly' + ) + const IssueData3 = await app.getIssue(repoId, 3) + const bountyId3 = IssueData3[1].toNumber() + const bountyData3 = await bounties.getBountyData(bountyId3) + assert.strictEqual( + bountyData3, + 'QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', + 'IPFS hash stored correctly' + ) + }) + + it('allows users to request assignment', async () => { await app.requestAssignment( repoId, issueNumber, 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', { from: root } ) + response = await app.getApplicant(repoId, issueNumber, 0) + assert.strictEqual(response[0], root, 'applicant address incorrect') + assert.strictEqual( + response[1], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + 'application IPFS hash incorrect' + ) }) - }) - it('assign tasks to applicants', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) + it('users cannot apply for a given issue more than once', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + assertRevert(async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + }) + }) - const issue = await app.getIssue(repoId, 1) - assert.strictEqual(issue[6], root, 'assignee address incorrect') - }) + it('cannot approve assignment if application was not created', async () => { + return assertRevert(async () => { + await app.reviewApplication( + repoId, + issueNumber, + ZERO_ADDR, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) + }) + }) - it('approve and reject assignment request', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - assert.strictEqual( - applicant[2].toNumber(), - 0, - 'assignment request status is not Unreviewed' - ) + it('assign tasks to applicants', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - assert.strictEqual( - applicant[2].toNumber(), - 1, - 'assignment request status is not Accepted' - ) + const issue = await app.getIssue(repoId, 1) + assert.strictEqual(issue[6], root, 'assignee address incorrect') + }) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - false, - { from: bountyAdder } - ) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - assert.strictEqual( - applicant[2].toNumber(), - 2, - 'assignment request status is not Rejected' - ) - }) + it('approve and reject assignment request', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + assert.strictEqual( + applicant[2].toNumber(), + 0, + 'assignment request status is not Unreviewed' + ) - it('users can submit work', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + assert.strictEqual( + applicant[2].toNumber(), + 1, + 'assignment request status is not Accepted' + ) - await app.submitWork( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' - ) - submissionQty = await app.getSubmissionsLength(repoId, issueNumber) - submission = await app.getSubmission( - repoId, - issueNumber, - submissionQty.toNumber() - 1 - ) - assert.strictEqual( - submission[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk', - 'submission incorrect' - ) - }) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + false, + { from: bountyAdder } + ) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + assert.strictEqual( + applicant[2].toNumber(), + 2, + 'assignment request status is not Rejected' + ) + }) - it('work can be rejected', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) + it('users can submit work', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) - await app.submitWork( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' - ) - submissionQty = await app.getSubmissionsLength(repoId, issueNumber) - const submissionIndex = submissionQty.toNumber() - 1 - submission = await app.getSubmission( - repoId, - issueNumber, - submissionIndex - ) + await app.submitWork( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' + ) + submissionQty = await app.getSubmissionsLength(repoId, issueNumber) + submission = await app.getSubmission( + repoId, + issueNumber, + submissionQty.toNumber() - 1 + ) + assert.strictEqual( + submission[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk', + 'submission incorrect' + ) + }) - await app.reviewSubmission( - repoId, - issueNumber, - submissionIndex, - false, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', - { from: bountyAdder } - ) - submission = await app.getSubmission( - repoId, - issueNumber, - submissionIndex - ) - assert.strictEqual( - submission[2].toNumber(), - 2, - 'submission status not rejected' - ) - }) + it('work can be rejected', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) - it('work can be accepted', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) + await app.submitWork( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' + ) + submissionQty = await app.getSubmissionsLength(repoId, issueNumber) + const submissionIndex = submissionQty.toNumber() - 1 + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) - await app.submitWork( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' - ) - submissionQty = await app.getSubmissionsLength(repoId, issueNumber) - const submissionIndex = submissionQty.toNumber() - 1 - submission = await app.getSubmission( - repoId, - issueNumber, - submissionIndex - ) + await app.reviewSubmission( + repoId, + issueNumber, + submissionIndex, + false, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', + { from: bountyAdder } + ) + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) + assert.strictEqual( + submission[2].toNumber(), + 2, + 'submission status not rejected' + ) + }) - await app.reviewSubmission( - repoId, - issueNumber, - submissionIndex, - true, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', - { from: bountyAdder } - ) - submission = await app.getSubmission( - repoId, - issueNumber, - submissionIndex - ) - assert.strictEqual( - submission[2].toNumber(), - 1, - 'submission status not accepted' - ) - }) + it('work can be accepted', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) - it('users cannot submit work for an issue they are not assigned to', async () => { - assertRevert(async () => { await app.submitWork( repoId, issueNumber, 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' ) - }) - }) + submissionQty = await app.getSubmissionsLength(repoId, issueNumber) + const submissionIndex = submissionQty.toNumber() - 1 + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) - it('work cannot be accepted or submitted after bounty is fulfilled', async () => { - await app.requestAssignment( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', - { from: root } - ) - applicantQty = await app.getApplicantsLength(repoId, 1) - applicant = await app.getApplicant( - repoId, - issueNumber, - applicantQty.toNumber() - 1 - ) - await app.reviewApplication( - repoId, - issueNumber, - applicant[0], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', - true, - { from: bountyAdder } - ) + await app.reviewSubmission( + repoId, + issueNumber, + submissionIndex, + true, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', + { from: bountyAdder } + ) + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) + assert.strictEqual( + submission[2].toNumber(), + 1, + 'submission status not accepted' + ) + }) - await app.submitWork( - repoId, - issueNumber, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' - ) - submissionQty = await app.getSubmissionsLength(repoId, issueNumber) - const submissionIndex = submissionQty.toNumber() - 1 - submission = await app.getSubmission( - repoId, - issueNumber, - submissionIndex - ) + it('work cannot be accepted twice', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) - await app.reviewSubmission( - repoId, - issueNumber, - submissionIndex, - true, - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', - { from: bountyAdder } - ) - assertRevert(async () => { await app.submitWork( repoId, issueNumber, 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' ) - }) - assertRevert(async () => { + submissionQty = await app.getSubmissionsLength(repoId, issueNumber) + const submissionIndex = submissionQty.toNumber() - 1 + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) + await app.reviewSubmission( repoId, issueNumber, submissionIndex, true, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', { from: bountyAdder } ) - }) - }) - xit('fulfill bounties and accept fulfillment', async () => { - const IssueData1 = await app.getIssue(repoId, 1) - const bountyId1 = IssueData1[1].toNumber() - const fulfillmentId1 = fulfilledBounty( - await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment1 = await bounties.getFulfillment( - bountyId1, - fulfillmentId1 - ) - assert(fulfillment1[0] === false) - await app.acceptFulfillment(repoId, 1, fulfillmentId1, { - from: bountyAdder, + return assertRevert(async () => { + await app.reviewSubmission( + repoId, + issueNumber, + submissionIndex, + true, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', + { from: bountyAdder } + ) + }) }) - fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) - assert(fulfillment1[0] === true) - const IssueData2 = await app.getIssue(repoId, 2) - const bountyId2 = IssueData2[1].toNumber() - const fulfillmentId2 = fulfilledBounty( - await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment2 = await bounties.getFulfillment( - bountyId2, - fulfillmentId2 - ) - assert(fulfillment2[0] === false) - await app.acceptFulfillment(repoId, 2, fulfillmentId2, { - from: bountyAdder, - }) - fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) - assert(fulfillment2[0] === true) - - const IssueData3 = await app.getIssue(repoId, 3) - const bountyId3 = IssueData3[1].toNumber() - const fulfillmentId3 = fulfilledBounty( - await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment3 = await bounties.getFulfillment( - bountyId3, - fulfillmentId3 - ) - assert(fulfillment3[0] === false) - await app.acceptFulfillment(repoId, 3, fulfillmentId3, { - from: bountyAdder, + it('users cannot submit work for an issue they are not assigned to', async () => { + assertRevert(async () => { + await app.submitWork( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' + ) + }) }) - fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) - assert(fulfillment3[0] === true) - }) - xit('verify balance is correct before and after accepting fulfillment in standard bounty', async () => { - const IssueData1 = await app.getIssue(repoId, 1) - const bountyId1 = IssueData1[1].toNumber() - const fulfillmentId1 = fulfilledBounty( - await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment1 = await bounties.getFulfillment( - bountyId1, - fulfillmentId1 - ) - assert(fulfillment1[0] === false) - let bounty1 = await bounties.getBounty(bountyId1) - assert.strictEqual(bounty1[5].toNumber(), 10) - await app.acceptFulfillment(repoId, 1, fulfillmentId1, { - from: bountyAdder, + it('work cannot be accepted or submitted after bounty is fulfilled', async () => { + await app.requestAssignment( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDd', + { from: root } + ) + applicantQty = await app.getApplicantsLength(repoId, 1) + applicant = await app.getApplicant( + repoId, + issueNumber, + applicantQty.toNumber() - 1 + ) + await app.reviewApplication( + repoId, + issueNumber, + applicant[0], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDe', + true, + { from: bountyAdder } + ) + + await app.submitWork( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' + ) + submissionQty = await app.getSubmissionsLength(repoId, issueNumber) + const submissionIndex = submissionQty.toNumber() - 1 + submission = await app.getSubmission( + repoId, + issueNumber, + submissionIndex + ) + + await app.reviewSubmission( + repoId, + issueNumber, + submissionIndex, + true, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDl', + { from: bountyAdder } + ) + assertRevert(async () => { + await app.submitWork( + repoId, + issueNumber, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDk' + ) + }) + assertRevert(async () => { + await app.reviewSubmission( + repoId, + issueNumber, + submissionIndex, + true, + { from: bountyAdder } + ) + }) }) - fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) - assert(fulfillment1[0] === true) - bounty1 = await bounties.getBounty(bountyId1) - assert.strictEqual(bounty1[5].toNumber(), 0) - - const IssueData2 = await app.getIssue(repoId, 2) - const bountyId2 = IssueData2[1].toNumber() - const fulfillmentId2 = fulfilledBounty( - await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment2 = await bounties.getFulfillment( - bountyId2, - fulfillmentId2 - ) - assert(fulfillment2[0] === false) - let bounty2 = await bounties.getBounty(bountyId2) - assert.strictEqual(bounty2[5].toNumber(), 20) - await app.acceptFulfillment(repoId, 2, fulfillmentId2, { - from: bountyAdder, + + xit('fulfill bounties and accept fulfillment', async () => { + const IssueData1 = await app.getIssue(repoId, 1) + const bountyId1 = IssueData1[1].toNumber() + const fulfillmentId1 = fulfilledBounty( + await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment1 = await bounties.getFulfillment( + bountyId1, + fulfillmentId1 + ) + assert(fulfillment1[0] === false) + await app.acceptFulfillment(repoId, 1, fulfillmentId1, { + from: bountyAdder, + }) + fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) + assert(fulfillment1[0] === true) + + const IssueData2 = await app.getIssue(repoId, 2) + const bountyId2 = IssueData2[1].toNumber() + const fulfillmentId2 = fulfilledBounty( + await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment2 = await bounties.getFulfillment( + bountyId2, + fulfillmentId2 + ) + assert(fulfillment2[0] === false) + await app.acceptFulfillment(repoId, 2, fulfillmentId2, { + from: bountyAdder, + }) + fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) + assert(fulfillment2[0] === true) + + const IssueData3 = await app.getIssue(repoId, 3) + const bountyId3 = IssueData3[1].toNumber() + const fulfillmentId3 = fulfilledBounty( + await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment3 = await bounties.getFulfillment( + bountyId3, + fulfillmentId3 + ) + assert(fulfillment3[0] === false) + await app.acceptFulfillment(repoId, 3, fulfillmentId3, { + from: bountyAdder, + }) + fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) + assert(fulfillment3[0] === true) }) - fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) - assert(fulfillment2[0] === true) - bounty2 = await bounties.getBounty(bountyId2) - assert.strictEqual(bounty2[5].toNumber(), 0) - - const IssueData3 = await app.getIssue(repoId, 3) - const bountyId3 = IssueData3[1].toNumber() - const fulfillmentId3 = fulfilledBounty( - await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment3 = await bounties.getFulfillment( - bountyId3, - fulfillmentId3 - ) - assert(fulfillment3[0] === false) - let bounty3 = await bounties.getBounty(bountyId3) - assert.strictEqual(bounty3[5].toNumber(), 30) - await app.acceptFulfillment(repoId, 3, fulfillmentId3, { - from: bountyAdder, + + xit('verify balance is correct before and after accepting fulfillment in standard bounty', async () => { + const IssueData1 = await app.getIssue(repoId, 1) + const bountyId1 = IssueData1[1].toNumber() + const fulfillmentId1 = fulfilledBounty( + await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment1 = await bounties.getFulfillment( + bountyId1, + fulfillmentId1 + ) + assert(fulfillment1[0] === false) + let bounty1 = await bounties.getBounty(bountyId1) + assert.strictEqual(bounty1[5].toNumber(), 10) + await app.acceptFulfillment(repoId, 1, fulfillmentId1, { + from: bountyAdder, + }) + fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) + assert(fulfillment1[0] === true) + bounty1 = await bounties.getBounty(bountyId1) + assert.strictEqual(bounty1[5].toNumber(), 0) + + const IssueData2 = await app.getIssue(repoId, 2) + const bountyId2 = IssueData2[1].toNumber() + const fulfillmentId2 = fulfilledBounty( + await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment2 = await bounties.getFulfillment( + bountyId2, + fulfillmentId2 + ) + assert(fulfillment2[0] === false) + let bounty2 = await bounties.getBounty(bountyId2) + assert.strictEqual(bounty2[5].toNumber(), 20) + await app.acceptFulfillment(repoId, 2, fulfillmentId2, { + from: bountyAdder, + }) + fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) + assert(fulfillment2[0] === true) + bounty2 = await bounties.getBounty(bountyId2) + assert.strictEqual(bounty2[5].toNumber(), 0) + + const IssueData3 = await app.getIssue(repoId, 3) + const bountyId3 = IssueData3[1].toNumber() + const fulfillmentId3 = fulfilledBounty( + await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') + )._fulfillmentId.toNumber() + let fulfillment3 = await bounties.getFulfillment( + bountyId3, + fulfillmentId3 + ) + assert(fulfillment3[0] === false) + let bounty3 = await bounties.getBounty(bountyId3) + assert.strictEqual(bounty3[5].toNumber(), 30) + await app.acceptFulfillment(repoId, 3, fulfillmentId3, { + from: bountyAdder, + }) + fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) + assert(fulfillment3[0] === true) + bounty3 = await bounties.getBounty(bountyId3) + assert.strictEqual(bounty3[5].toNumber(), 0) }) - fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) - assert(fulfillment3[0] === true) - bounty3 = await bounties.getBounty(bountyId3) - assert.strictEqual(bounty3[5].toNumber(), 0) }) }) - }) - context('issue curation', () => { + context('issue curation', () => { // TODO: We should create every permission for every test this way to speed up testing // TODO: Create an external helper function that inits acl and sets permissions - before(async () => {}) - it('should curate a multiple issues', async () => { - const unusedAddresses = accounts.slice(0, 4) - const zeros = new Array(unusedAddresses.length).fill(0) - const issuePriorities = zeros - const issueDescriptionIndices = zeros - const unused_issueDescriptions = '' - const issueRepos = zeros - const issueNumbers = zeros - const unused_curationId = 0 - const description = 'description' - await app.curateIssues( - unusedAddresses, - issuePriorities, - issueDescriptionIndices, - unused_issueDescriptions, - description, - issueRepos, - issueNumbers, - unused_curationId - ) - // assert() - }) - context('invalid issue curation operations', () => { - it('should revert on issueDescriptionindices and priorities array length mismatch', async () => { + before(async () => {}) + it('should curate a multiple issues', async () => { const unusedAddresses = accounts.slice(0, 4) const zeros = new Array(unusedAddresses.length).fill(0) const issuePriorities = zeros - const issueDescriptionIndices = zeros.slice(0, 3) + const issueDescriptionIndices = zeros const unused_issueDescriptions = '' const issueRepos = zeros const issueNumbers = zeros const unused_curationId = 0 const description = 'description' - assertRevert(async () => { - await app.curateIssues( - unusedAddresses, - issuePriorities, - issueDescriptionIndices, - unused_issueDescriptions, - description, - issueRepos, - issueNumbers, - unused_curationId - ) - }) + await app.curateIssues( + unusedAddresses, + issuePriorities, + issueDescriptionIndices, + unused_issueDescriptions, + description, + issueRepos, + issueNumbers, + unused_curationId + ) + // assert() }) - it('should revert on IssuedescriptionIndices and issueRepos array length mismatch', async () => { - const unusedAddresses = accounts.slice(0, 4) - const zeros = new Array(unusedAddresses.length).fill(0) - const issuePriorities = zeros - const issueDescriptionIndices = zeros - const unused_issueDescriptions = '' - const issueRepos = zeros.slice(0, 3) - const issueNumbers = zeros - const unused_curationId = 0 - const description = 'description' - assertRevert(async () => { - await app.curateIssues( - unusedAddresses, - issuePriorities, - issueDescriptionIndices, - unused_issueDescriptions, - description, - issueRepos, - issueNumbers, - unused_curationId - ) + context('invalid issue curation operations', () => { + it('should revert on issueDescriptionindices and priorities array length mismatch', async () => { + const unusedAddresses = accounts.slice(0, 4) + const zeros = new Array(unusedAddresses.length).fill(0) + const issuePriorities = zeros + const issueDescriptionIndices = zeros.slice(0, 3) + const unused_issueDescriptions = '' + const issueRepos = zeros + const issueNumbers = zeros + const unused_curationId = 0 + const description = 'description' + assertRevert(async () => { + await app.curateIssues( + unusedAddresses, + issuePriorities, + issueDescriptionIndices, + unused_issueDescriptions, + description, + issueRepos, + issueNumbers, + unused_curationId + ) + }) }) - }) - it('should revert on IssueRepos and IssuesNumbers array length mismatch', async () => { - const unusedAddresses = accounts.slice(0, 4) - const zeros = new Array(unusedAddresses.length).fill(0) - const issuePriorities = zeros - const issueDescriptionIndices = zeros - const unused_issueDescriptions = '' - const issueRepos = zeros - const issueNumbers = zeros.slice(0, 3) - const unused_curationId = 0 - const description = 'description' - assertRevert(async () => { - await app.curateIssues( - unusedAddresses, - issuePriorities, - issueDescriptionIndices, - unused_issueDescriptions, - description, - issueRepos, - issueNumbers, - unused_curationId - ) + it('should revert on IssuedescriptionIndices and issueRepos array length mismatch', async () => { + const unusedAddresses = accounts.slice(0, 4) + const zeros = new Array(unusedAddresses.length).fill(0) + const issuePriorities = zeros + const issueDescriptionIndices = zeros + const unused_issueDescriptions = '' + const issueRepos = zeros.slice(0, 3) + const issueNumbers = zeros + const unused_curationId = 0 + const description = 'description' + assertRevert(async () => { + await app.curateIssues( + unusedAddresses, + issuePriorities, + issueDescriptionIndices, + unused_issueDescriptions, + description, + issueRepos, + issueNumbers, + unused_curationId + ) + }) }) - }) - xit('should revert if an issue has an already assigned bounty', async () => { + it('should revert on IssueRepos and IssuesNumbers array length mismatch', async () => { + const unusedAddresses = accounts.slice(0, 4) + const zeros = new Array(unusedAddresses.length).fill(0) + const issuePriorities = zeros + const issueDescriptionIndices = zeros + const unused_issueDescriptions = '' + const issueRepos = zeros + const issueNumbers = zeros.slice(0, 3) + const unused_curationId = 0 + const description = 'description' + assertRevert(async () => { + await app.curateIssues( + unusedAddresses, + issuePriorities, + issueDescriptionIndices, + unused_issueDescriptions, + description, + issueRepos, + issueNumbers, + unused_curationId + ) + }) + }) + xit('should revert if an issue has an already assigned bounty', async () => { // assert() + }) }) }) - }) - context('settings management', () => { - it('can change Bounty Settings', async () => { - await app.changeBountySettings( - [ 100, 300, 500, 1000 ], // xp multipliers - [ + context('settings management', () => { + it('can change Bounty Settings', async () => { + await app.changeBountySettings( + [ 100, 300, 500, 1000 ], // xp multipliers + [ // Experience Levels - web3.fromAscii('Beginner'), - web3.fromAscii('Intermediate'), - web3.fromAscii('Advanced'), - web3.fromAscii('Expert'), - ], - 1, // baseRate - 336, // bountyDeadline - '0x0000000000000000000000000000000000000000', // bountyCurrency - bounties.address // bountyAllocator + web3.fromAscii('Beginner'), + web3.fromAscii('Intermediate'), + web3.fromAscii('Advanced'), + web3.fromAscii('Expert'), + ], + 1, // baseRate + 336, // bountyDeadline + ZERO_ADDR, // bountyCurrency + bounties.address // bountyAllocator //0x0000000000000000000000000000000000000000 //bountyArbiter - ) - - response = await app.getSettings() - - expect(response[0].map(x => x.toNumber())).to.have.ordered.members([ - 100, - 300, - 500, - 1000, - ]) - const xpLvlDescs = response[1].map(x => web3.toUtf8(x)) - expect(xpLvlDescs).to.have.ordered.members([ - 'Beginner', - 'Intermediate', - 'Advanced', - 'Expert', - ]) - - assert.strictEqual(response[2].toNumber(), 1, 'baseRate Incorrect') - assert.strictEqual( - response[3].toNumber(), - 336, - 'bounty deadline inccorrect' - ) - assert.strictEqual( - response[4], - '0x0000000000000000000000000000000000000000', - 'Token Address incorrect' - ) - assert.strictEqual( - response[5], - bounties.address, - 'StandardBounties Contract address incorrect' - ) + ) + + response = await app.getSettings() + + expect(response[0].map(x => x.toNumber())).to.have.ordered.members([ + 100, + 300, + 500, + 1000, + ]) + const xpLvlDescs = response[1].map(x => web3.toUtf8(x)) + expect(xpLvlDescs).to.have.ordered.members([ + 'Beginner', + 'Intermediate', + 'Advanced', + 'Expert', + ]) + + assert.strictEqual(response[2].toNumber(), 1, 'baseRate Incorrect') + assert.strictEqual( + response[3].toNumber(), + 336, + 'bounty deadline inccorrect' + ) + assert.strictEqual( + response[4], + '0x0000000000000000000000000000000000000000', + 'Token Address incorrect' + ) + assert.strictEqual( + response[5], + bounties.address, + 'StandardBounties Contract address incorrect' + ) //assert.strictEqual( // response[5], // '0x0000000000000000000000000000000000000000', // 'arbiter incorrect' //) + }) }) - }) - - context('invalid operations', () => { - it('cannot add a repo that is already present', async () => { - await app.addRepo('abc', { from: owner1 }) - assertRevert(async () => { + context('invalid operations', () => { + it('cannot add a repo that is already present', async () => { await app.addRepo('abc', { from: owner1 }) + + assertRevert(async () => { + await app.addRepo('abc', { from: owner1 }) + }) }) - }) - it('cannot remove a repo that was never added', async () => { - assertRevert(async () => { - await app.removeRepo('99999', { from: repoRemover }) - }) - }) - it('cannot retrieve a removed Repo', async () => { - const repoId = addedRepo( - await app.addRepo('abc', { from: owner1 }) - ) - await app.removeRepo(repoId, { from: repoRemover }) - // const result = await app.getRepo(repoId) - assertRevert(async () => { - await app.getRepo(repoId, { from: repoRemover }) + it('cannot remove a repo that was never added', async () => { + assertRevert(async () => { + await app.removeRepo('99999', { from: repoRemover }) + }) }) + it('cannot retrieve a removed Repo', async () => { + const repoId = addedRepo( + await app.addRepo('abc', { from: owner1 }) + ) + await app.removeRepo(repoId, { from: repoRemover }) + // const result = await app.getRepo(repoId) + assertRevert(async () => { + await app.getRepo(repoId, { from: repoRemover }) + }) // assert.equal( // web3.toAscii(result[0]).replace(/\0/g, ''), // '', // 'repo returned' // ) - }) + }) - // TODO: Cannot remove a not existing repo - // TODO: settings tests + // TODO: Cannot remove a not existing repo + // TODO: settings tests - it('cannot add bounties to unregistered repos', async () => { - assertRevert(async () => { - await app.addBounties( - Array(3).fill('0xdeadbeef'), - [ 1, 2, 3 ], - [ 10, 20, 30 ], - 'something cool', - { - from: bountyAdder, - } - ) + it('cannot add bounties to unregistered repos', async () => { + assertRevert(async () => { + await app.addBounties( + Array(3).fill('0xdeadbeef'), + [ 1, 2, 3 ], + [ 10, 20, 30 ], + 'something cool', + { + from: bountyAdder, + } + ) + }) }) - }) - xit('cannot accept unfulfilled bounties', async () => { - let repoId = addedRepo( - await app.addRepo( - 'MDEyOk9yZ2FuaXphdGlvbjM0MDE4MzU5', - { from: owner1 } + xit('cannot accept unfulfilled bounties', async () => { + let repoId = addedRepo( + await app.addRepo( + 'MDEyOk9yZ2FuaXphdGlvbjM0MDE4MzU5', + { from: owner1 } + ) ) - ) - await app.addBounties( - Array(3).fill(repoId), - [ 1, 2, 3 ], - [ 10, 20, 30 ], - [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], - [ false, false, false ], - [ 0, 0, 0 ], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', - 'something else', - { from: bountyAdder, value: 60 } - ) - assertRevert(async () => { - await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) - }) - await bounties.fulfillBounty(0, 'findthemillenniumfalcon') - let fulfillment1 = await bounties.getFulfillment(0, 0) - assert(fulfillment1[0] === false) - await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) - fulfillment1 = await bounties.getFulfillment(0, 0) - assert(fulfillment1[0] === true) - }) - - xit('cannot issue bulk bounties with mismatched values', async () => { - const bountyAdder = accounts[2] - const repoId = addedRepo( - await app.addRepo('abc', { from: owner1 }) - ) - assertRevert(async () => { await app.addBounties( Array(3).fill(repoId), [ 1, 2, 3 ], - [ 10, 20, 30 ], // 60 total Wei should be sent + [ 10, 20, 30 ], [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], [ false, false, false ], [ 0, 0, 0 ], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', - 'something awesome', - { from: bountyAdder, value: 61 } // 61 Wei sent instead + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', + 'something else', + { from: bountyAdder, value: 60 } ) + assertRevert(async () => { + await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) + }) + await bounties.fulfillBounty(0, 'findthemillenniumfalcon') + let fulfillment1 = await bounties.getFulfillment(0, 0) + assert(fulfillment1[0] === false) + await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) + fulfillment1 = await bounties.getFulfillment(0, 0) + assert(fulfillment1[0] === true) + }) + + xit('cannot issue bulk bounties with mismatched values', async () => { + const bountyAdder = accounts[2] + const repoId = addedRepo( + await app.addRepo('abc', { from: owner1 }) + ) + assertRevert(async () => { + await app.addBounties( + Array(3).fill(repoId), + [ 1, 2, 3 ], + [ 10, 20, 30 ], // 60 total Wei should be sent + [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], + [ false, false, false ], + [ 0, 0, 0 ], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', + 'something awesome', + { from: bountyAdder, value: 61 } // 61 Wei sent instead + ) + }) }) }) }) From 3068e0cc054dff5c3466e0e3533f2d42bb139d60 Mon Sep 17 00:00:00 2001 From: topocount Date: Fri, 3 May 2019 14:13:18 -0700 Subject: [PATCH 2/7] Increase Projects test coverage to 100% - cover requirement for xp array lengths: line 218 - cover token bounty activation handling: lines 657 - 661 --- apps/projects/test/projects.test.js | 86 ++++++++++++++++- package-lock.json | 142 +++++++++------------------- 2 files changed, 129 insertions(+), 99 deletions(-) diff --git a/apps/projects/test/projects.test.js b/apps/projects/test/projects.test.js index 07ff11948..f58b0cae2 100644 --- a/apps/projects/test/projects.test.js +++ b/apps/projects/test/projects.test.js @@ -5,6 +5,7 @@ const { EVMScriptRegistryFactory, Kernel, StandardBounties, + MiniMeToken, } = require('@tps/test-helpers/artifacts') const Vault = artifacts.require('Vault') @@ -22,7 +23,9 @@ const fulfilledBounty = receipt => contract('Projects App', accounts => { let daoFact, bounties, - app = {} + app = {}, + vaultBase = {}, + vault = {} const root = accounts[0] const owner1 = accounts[0] // 0xb421 @@ -134,8 +137,10 @@ contract('Projects App', accounts => { // Deploy test Bounties contract bounties = await StandardBounties.new(web3.toBigNumber(owner1)) - vault = await Vault.new() - + vaultBase = await Vault.new() + const vaultReceipt = await dao.newAppInstance('0x5678', vaultBase.address, '0x', false, { from: root }) + vault = Vault.at(vaultReceipt.logs.filter(l => l.event == 'NewAppProxy')[0].args.proxy) + await vault.initialize() await acl.createPermission( app.address, vault.address, @@ -870,6 +875,63 @@ contract('Projects App', accounts => { bounty3 = await bounties.getBounty(bountyId3) assert.strictEqual(bounty3[5].toNumber(), 0) }) + + it('can issue bulk token bounties', async () => { + const issueNumber = 1 + let issue3Receipt + let token = {} + + token = await MiniMeToken.new( + ZERO_ADDR, + ZERO_ADDR, + 0, + 'n', + 0, + 'n', + true + ) // empty parameters minime + await token.generateTokens(vault.address, 6) + issue3Receipt = addedBounties( + await app.addBounties( + Array(3).fill(repoId), + [ 1, 2, 3 ], + [ 1, 2, 3 ], + [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], + [ true, true, true ], + [ token.address, token.address, token.address ], + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', + 'something', + { from: bountyAdder, } + ) + ) + + const issue3Bounty = issue3Receipt.args.bountySize.toNumber() + assert.strictEqual(issue3Bounty, 3, 'bounty not added') + const IssueData1 = await app.getIssue(repoId, 1) + const bountyId1 = IssueData1[1].toNumber() + const bountyData1 = await bounties.getBountyData(bountyId1) + assert.strictEqual( + bountyData1, + 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', + 'IPFS hash stored correctly' + ) + const IssueData2 = await app.getIssue(repoId, 2) + const bountyId2 = IssueData2[1].toNumber() + const bountyData2 = await bounties.getBountyData(bountyId2) + assert.strictEqual( + bountyData2, + 'QmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWu', + 'IPFS hash stored correctly' + ) + const IssueData3 = await app.getIssue(repoId, 3) + const bountyId3 = IssueData3[1].toNumber() + const bountyData3 = await bounties.getBountyData(bountyId3) + assert.strictEqual( + bountyData3, + 'QmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', + 'IPFS hash stored correctly' + ) + }) }) }) @@ -976,6 +1038,24 @@ contract('Projects App', accounts => { }) context('settings management', () => { + it('cannot accept experience arrays of differenct length', async () => { + return assertRevert( async () => { + await app.changeBountySettings( + [ 100, 300, 500, 1000 ], // xp multipliers + [ + // Experience Levels + web3.fromAscii('Beginner'), + web3.fromAscii('Intermediate'), + web3.fromAscii('Advanced'), + ], + 1, // baseRate + 336, // bountyDeadline + ZERO_ADDR, // bountyCurrency + bounties.address // bountyAllocator + //0x0000000000000000000000000000000000000000 //bountyArbiter + ) + }) + }) it('can change Bounty Settings', async () => { await app.changeBountySettings( [ 100, 300, 500, 1000 ], // xp multipliers diff --git a/package-lock.json b/package-lock.json index 11834a4d3..085f00bf3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11227,7 +11227,8 @@ "bindings": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.3.0.tgz", - "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==" + "integrity": "sha512-DpLh5EzMR2kzvX1KIlVC0VkC3iZtHKTgdtZ0a3pglBZdaQFjt5S9g9xd1lE+YvXyfd6mtCeRnrUfOLYiTMlNSw==", + "dev": true }, "bip39": { "version": "2.4.0", @@ -11246,6 +11247,7 @@ "version": "1.1.5", "resolved": "https://registry.npmjs.org/bip66/-/bip66-1.1.5.tgz", "integrity": "sha1-AfqHSHhcpwlV1QESF9GzE5lpyiI=", + "dev": true, "requires": { "safe-buffer": "^5.0.1" } @@ -11291,7 +11293,8 @@ "bn.js": { "version": "4.11.6", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.6.tgz", - "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=" + "integrity": "sha1-UzRK2xRhehP26N0s4okF0cC6MhU=", + "dev": true }, "body-parser": { "version": "1.18.3", @@ -11323,7 +11326,8 @@ "brorand": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz", - "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=" + "integrity": "sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8=", + "dev": true }, "browser-stdout": { "version": "1.3.1", @@ -11334,6 +11338,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/browserify-aes/-/browserify-aes-1.2.0.tgz", "integrity": "sha512-+7CHXqGuspUn/Sl5aO7Ea0xWGAtETPXNSAjHo48JfLdPWcMng33Xe4znFvQweqc/uzk5zSOI3H52CYnjCfb5hA==", + "dev": true, "requires": { "buffer-xor": "^1.0.3", "cipher-base": "^1.0.0", @@ -11481,7 +11486,8 @@ "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", - "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=" + "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", + "dev": true }, "builtin-modules": { "version": "1.1.1", @@ -11590,6 +11596,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", + "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -11750,6 +11757,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", + "dev": true, "requires": { "cipher-base": "^1.0.1", "inherits": "^2.0.1", @@ -11762,6 +11770,7 @@ "version": "1.1.7", "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", + "dev": true, "requires": { "cipher-base": "^1.0.3", "create-hash": "^1.1.0", @@ -12078,6 +12087,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/drbg.js/-/drbg.js-1.0.1.tgz", "integrity": "sha1-Pja2xCs3BDgjzbwzLVjzHiRFSAs=", + "dev": true, "requires": { "browserify-aes": "^1.0.6", "create-hash": "^1.1.2", @@ -12116,6 +12126,7 @@ "version": "6.4.0", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz", "integrity": "sha1-ysmvh2LIWDYYcAPI3+GT5eLq5d8=", + "dev": true, "requires": { "bn.js": "^4.4.0", "brorand": "^1.0.1", @@ -12359,7 +12370,8 @@ "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==" + "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", + "dev": true }, "eth-block-tracker": { "version": "2.3.1", @@ -12383,46 +12395,8 @@ "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "dev": true, "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", "ethereumjs-util": "^5.1.1" - }, - "dependencies": { - "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb", - "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", - "dev": true, - "requires": { - "bn.js": "^4.11.8", - "ethereumjs-util": "^6.0.0" - }, - "dependencies": { - "ethereumjs-util": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz", - "integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==", - "dev": true, - "requires": { - "bn.js": "^4.11.0", - "create-hash": "^1.1.2", - "ethjs-util": "0.1.6", - "keccak": "^1.0.2", - "rlp": "^2.0.0", - "safe-buffer": "^5.1.1", - "secp256k1": "^3.0.1" - } - } - } - }, - "ethjs-util": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", - "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", - "dev": true, - "requires": { - "is-hex-prefixed": "1.0.0", - "strip-hex-prefix": "1.0.0" - } - } } }, "ethereum-common": { @@ -12434,6 +12408,7 @@ "ethereumjs-abi": { "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", "from": "ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", + "dev": true, "requires": { "bn.js": "^4.10.0", "ethereumjs-util": "^5.0.0" @@ -12604,6 +12579,7 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-5.2.0.tgz", "integrity": "sha512-CJAKdI0wgMbQFLlLRtZKGcy/L6pzVRgelIZqRqNbuVFM3K9VEnyfbcvz0ncWMRNCe4kaHWjwRYQcYMucmwsnWA==", + "dev": true, "requires": { "bn.js": "^4.11.0", "create-hash": "^1.1.2", @@ -12698,6 +12674,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.4.tgz", "integrity": "sha1-HItoeSV0RO9NPz+7rC3tEs2ZfZM=", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0", "strip-hex-prefix": "1.0.0" @@ -12713,6 +12690,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", "integrity": "sha512-/f2Go4TognH/KvCISP7OUsHn85hT9nUkxxA9BEWxFn+Oj9o8ZNLm/40hdlgSLyuOimsrTKLUMEorQexp/aPQeA==", + "dev": true, "requires": { "md5.js": "^1.3.4", "safe-buffer": "^5.1.1" @@ -13215,6 +13193,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", + "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -13224,6 +13203,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.1.3.tgz", "integrity": "sha512-/UETyP0W22QILqS+6HowevwhEFJ3MBJnwTf75Qob9Wz9t0DPuisL8kW8YZMK62dHAKE1c1p+gY1TtOLY+USEHA==", + "dev": true, "requires": { "inherits": "^2.0.3", "minimalistic-assert": "^1.0.0" @@ -13254,6 +13234,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", "integrity": "sha1-0nRXAQJabHdabFRXk+1QL8DGSaE=", + "dev": true, "requires": { "hash.js": "^1.0.3", "minimalistic-assert": "^1.0.0", @@ -13429,7 +13410,8 @@ "is-hex-prefixed": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz", - "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=" + "integrity": "sha1-fY035q135dEnFIkTxXPggtd39VQ=", + "dev": true }, "is-natural-number": { "version": "4.0.1", @@ -13636,6 +13618,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/keccak/-/keccak-1.4.0.tgz", "integrity": "sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw==", + "dev": true, "requires": { "bindings": "^1.2.1", "inherits": "^2.0.3", @@ -13991,6 +13974,7 @@ "version": "1.3.4", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.4.tgz", "integrity": "sha1-6b296UogpawYsENA/Fdk1bCdkB0=", + "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1" @@ -14118,12 +14102,14 @@ "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", - "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" + "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==", + "dev": true }, "minimalistic-crypto-utils": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz", - "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=" + "integrity": "sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=", + "dev": true }, "minimatch": { "version": "3.0.4", @@ -14227,7 +14213,8 @@ "nan": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", - "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==" + "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", + "dev": true }, "nano-json-stream-parser": { "version": "0.1.2", @@ -14899,6 +14886,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", + "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1" @@ -14907,7 +14895,8 @@ "rlp": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.0.0.tgz", - "integrity": "sha1-nbOE/0uJqPYVY9kjldhiWxjzr7A=" + "integrity": "sha1-nbOE/0uJqPYVY9kjldhiWxjzr7A=", + "dev": true }, "rustbn.js": { "version": "0.1.2", @@ -14918,7 +14907,8 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true }, "safer-buffer": { "version": "2.1.2", @@ -14958,6 +14948,7 @@ "version": "3.5.0", "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-3.5.0.tgz", "integrity": "sha512-e5QIJl8W7Y4tT6LHffVcZAxJjvpgE5Owawv6/XCYPQljE9aP2NFFddQ8OYMKhdLshNu88FfL3qCN3/xYkXGRsA==", + "dev": true, "requires": { "bindings": "^1.2.1", "bip66": "^1.1.3", @@ -15078,6 +15069,7 @@ "version": "2.4.11", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", + "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -15311,6 +15303,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz", "integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428=", + "dev": true, "requires": { "is-hex-prefixed": "1.0.0" } @@ -16018,62 +16011,19 @@ "integrity": "sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=", "dev": true, "requires": { - "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb", + "ethereumjs-abi": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", "ethereumjs-util": "^5.1.1" - }, - "dependencies": { - "bn.js": { - "version": "4.11.8", - "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", - "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", - "dev": true - }, - "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#8431eab7b3384e65e8126a4602520b78031666fb", - "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", - "dev": true, - "requires": { - "bn.js": "^4.11.8", - "ethereumjs-util": "^6.0.0" - }, - "dependencies": { - "ethereumjs-util": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz", - "integrity": "sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q==", - "dev": true, - "requires": { - "bn.js": "^4.11.0", - "create-hash": "^1.1.2", - "ethjs-util": "0.1.6", - "keccak": "^1.0.2", - "rlp": "^2.0.0", - "safe-buffer": "^5.1.1", - "secp256k1": "^3.0.1" - } - } - } - } } }, "ethereumjs-abi": { "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", "from": "ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git#00ba8463a7f7a67fcad737ff9c2ebd95643427f7", + "dev": true, "requires": { "bn.js": "^4.10.0", "ethereumjs-util": "^5.0.0" } }, - "ethjs-util": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz", - "integrity": "sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w==", - "dev": true, - "requires": { - "is-hex-prefixed": "1.0.0", - "strip-hex-prefix": "1.0.0" - } - }, "ws": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/ws/-/ws-5.2.0.tgz", @@ -16119,7 +16069,7 @@ "dependencies": { "websocket": { "version": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2", - "from": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible", + "from": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2", "dev": true, "requires": { "debug": "^2.2.0", From f0f8bedeea45ebf23272639658bcee9133c12cb5 Mon Sep 17 00:00:00 2001 From: topocount Date: Sat, 4 May 2019 20:54:16 -0700 Subject: [PATCH 3/7] Update Address Book tests - add returns to assertRevert functions - update getEntry test for nonexistent entries --- apps/address-book/test/address-book.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/address-book/test/address-book.js b/apps/address-book/test/address-book.js index 36d759edb..9547af6ca 100644 --- a/apps/address-book/test/address-book.js +++ b/apps/address-book/test/address-book.js @@ -101,24 +101,25 @@ contract('AddressBook App', accounts => { }) it('should revert when adding duplicate address', async () => { - assertRevert(async () => { + return assertRevert(async () => { await app.addEntry(borg, 'Burg', 'N/A') }) }) it('should revert when adding duplicate name', async () => { - assertRevert(async () => { + return assertRevert(async () => { await app.addEntry(jeanluc, 'Borg', 'Captain') }) }) it('should revert when removing not existant entry', async () => { - assertRevert(async () => { + return assertRevert(async () => { await app.removeEntry(jeanluc) }) }) - it('should revert when getting non-existant entry', async () => { - assertRevert(async () => { - await app.getEntry(jeanluc) - }) + it('should return a zero-address when getting non-existant entry', async () => { + const [ entryAddress, name, entryType ] = await app.getEntry(jeanluc) + assert.strictEqual(entryAddress, '0x0000000000000000000000000000000000000000', 'address should be 0x0') + assert.strictEqual(name, '', 'name should be empty') + assert.strictEqual(entryType, '', 'entry Type should be empty') }) }) }) From e5e7de3adaa4e5f6f30a68c364b640e5ee307788 Mon Sep 17 00:00:00 2001 From: topocount Date: Sat, 4 May 2019 21:16:54 -0700 Subject: [PATCH 4/7] Update allocations tests - cover getPayoutDescription getter --- apps/allocations/test/allocations.test.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/allocations/test/allocations.test.js b/apps/allocations/test/allocations.test.js index d69645c27..8515605c8 100644 --- a/apps/allocations/test/allocations.test.js +++ b/apps/allocations/test/allocations.test.js @@ -138,7 +138,7 @@ contract('Allocations App', accounts => { supports, zeros, '', - '', + 'ETH description', zeros, zeros, accountId, @@ -152,7 +152,7 @@ contract('Allocations App', accounts => { supports, zeros, '', - '', + 'token description', zeros, zeros, accountId, @@ -234,6 +234,11 @@ contract('Allocations App', accounts => { assert.strictEqual(payoutInfo[3].toNumber(), 0, 'recurring payout period length incorrect') }) + it('retrieves payout description', async () =>{ + const payoutDescription = await app.getPayoutDescription(accountId,ethPayoutId) + assert.strictEqual(payoutDescription, 'ETH description', 'Payout description incorrectly stored') + }) + it('sets the distribution (token)', async () => { const candidateArrayLength = (await app.getNumberOfCandidates( accountId, From 83bfe516254fa7c04167c93ae416069e6e8e86b3 Mon Sep 17 00:00:00 2001 From: topocount Date: Sat, 4 May 2019 22:21:31 -0700 Subject: [PATCH 5/7] Improve Rewards Contract Coverage - fix revert tests that weren't set up to run as async - add initialization check for incorrect vault address - add test cases for remaining uncovered requires - remove trailing whitespace from contract --- apps/rewards/contracts/Rewards.sol | 2 +- apps/rewards/test/Rewards.test.js | 553 +++++++++++++++++------------ 2 files changed, 322 insertions(+), 233 deletions(-) diff --git a/apps/rewards/contracts/Rewards.sol b/apps/rewards/contracts/Rewards.sol index 4c41b377c..7cf4a59c9 100644 --- a/apps/rewards/contracts/Rewards.sol +++ b/apps/rewards/contracts/Rewards.sol @@ -146,7 +146,7 @@ contract Rewards is IsContract, AragonApp { uint256 _duration, uint256 _occurances, uint256 _delay - ) public auth(ADD_REWARD_ROLE) returns (uint256 rewardId) + ) public auth(ADD_REWARD_ROLE) returns (uint256 rewardId) { require(isContract(_referenceToken), "_referenceToken must be a contract"); if (_rewardToken != address(0)) { diff --git a/apps/rewards/test/Rewards.test.js b/apps/rewards/test/Rewards.test.js index 38d8cdf42..387d3ff0f 100644 --- a/apps/rewards/test/Rewards.test.js +++ b/apps/rewards/test/Rewards.test.js @@ -98,281 +98,370 @@ contract('Rewards App', accounts => { root, { from: root } ) - await app.initialize(vault.address) referenceToken = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'one', 18, 'one', true) // empty parameters minime rewardToken = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'two', 18, 'two', true) // empty parameters minime minBlock = await getBlockNumber() }) - context('Basic contract functions', () => { - before(async () => { - await referenceToken.generateTokens(root, 1e18) - await referenceToken.generateTokens(contributor1, 1e18) - await referenceToken.generateTokens(contributor2, 1e18) - await referenceToken.generateTokens(contributor3, 1e18) + context('pre-initialization', () => { + it('will not initialize with invalid vault address', async () =>{ + return assertRevert(async () => { + await app.initialize(0x0) + }) + }) + }) - await rewardToken.generateTokens(root, 25e18) - await rewardToken.transfer(vault.address, 25e18) + context('successful initialization', () => { + before(async () => { + await app.initialize(vault.address) }) - let dividendRewardId, meritRewardId, rewardInformation - it('creates a dividend reward', async () => { - let blockNumber = await getBlockNumber() - dividendRewardIds = rewardAdded( - await app.newReward( - 'testReward', - false, - referenceToken.address, - rewardToken.address, - 4e18, - blockNumber, - 1, - 2, - 0 + context('Basic contract functions', () => { + before(async () => { + await referenceToken.generateTokens(root, 1e18) + await referenceToken.generateTokens(contributor1, 1e18) + await referenceToken.generateTokens(contributor2, 1e18) + await referenceToken.generateTokens(contributor3, 1e18) + + await rewardToken.generateTokens(root, 25e18) + await rewardToken.transfer(vault.address, 25e18) + }) + + let dividendRewardId, meritRewardId, rewardInformation + it('creates a dividend reward', async () => { + let blockNumber = await getBlockNumber() + dividendRewardIds = rewardAdded( + await app.newReward( + 'testReward', + false, + referenceToken.address, + rewardToken.address, + 4e18, + blockNumber, + 1, + 2, + 0 + ) ) - ) - await mineBlock() - assert(dividendRewardIds[0] == 0, 'first reward should be id 0') - assert(dividendRewardIds[1] == 1, 'second reward should be id 1') - }) + await mineBlock() + assert(dividendRewardIds[0] == 0, 'first reward should be id 0') + assert(dividendRewardIds[1] == 1, 'second reward should be id 1') + }) - it('creates a merit reward', async () => { - let blockNumber = await getBlockNumber() - meritRewardIds = rewardAdded( - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 4e18, - blockNumber, - 6, - 1, - 0 + it('creates a merit reward', async () => { + let blockNumber = await getBlockNumber() + meritRewardIds = rewardAdded( + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 4e18, + blockNumber, + 6, + 1, + 0 + ) ) - ) - let meritRewardId = meritRewardIds[0] - await referenceToken.generateTokens(root, 1e18) - await referenceToken.generateTokens(contributor1, 1e18) - await referenceToken.generateTokens(contributor2, 1e18) - await referenceToken.generateTokens(contributor3, 1e18) - await mineBlock() - await mineBlock() - assert(meritRewardId == 2, 'third reward should be id 2') - }) + let meritRewardId = meritRewardIds[0] + await referenceToken.generateTokens(root, 1e18) + await referenceToken.generateTokens(contributor1, 1e18) + await referenceToken.generateTokens(contributor2, 1e18) + await referenceToken.generateTokens(contributor3, 1e18) + await mineBlock() + await mineBlock() + assert(meritRewardId == 2, 'third reward should be id 2') + }) - it('gets information on the dividend reward', async () => { - rewardInformation = await app.getReward(dividendRewardIds[0]) - assert(rewardInformation[1] === false, 'First reward should be dividend') - }) + it('gets information on the dividend reward', async () => { + rewardInformation = await app.getReward(dividendRewardIds[0]) + assert(rewardInformation[1] === false, 'First reward should be dividend') + }) - it('gets information on the merit reward', async () => { - rewardInformation = await app.getReward(meritRewardIds[0]) - assert(rewardInformation[1] === true, 'third reward should be merit') - }) + it('gets information on the merit reward', async () => { + rewardInformation = await app.getReward(meritRewardIds[0]) + assert(rewardInformation[1] === true, 'third reward should be merit') + }) - it('receives rewards dividends', async () => { - rewardInformation = await app.getReward(dividendRewardIds[0]) - await app.claimReward(dividendRewardIds[0]) - const balance = await rewardToken.balanceOf(root) - assert(balance == 1e18, 'reward should be 1e18 or 1eth equivalant') - rewardInformation = await app.getReward(dividendRewardIds[0]) - assert.strictEqual(rewardInformation[10], true, 'reward is claimed') - }) + it('receives rewards dividends', async () => { + rewardInformation = await app.getReward(dividendRewardIds[0]) + await app.claimReward(dividendRewardIds[0]) + const balance = await rewardToken.balanceOf(root) + assert(balance == 1e18, 'reward should be 1e18 or 1eth equivalant') + rewardInformation = await app.getReward(dividendRewardIds[0]) + assert.strictEqual(rewardInformation[10], true, 'reward is claimed') + }) - it('receives rewards merit', async () => { - await app.claimReward(meritRewardIds[0]) - const balance = await rewardToken.balanceOf(root) - assert(balance == 2e18, 'reward should be 2e18 or 2eth equivalant; 1 for each reward') - rewardInformation = await app.getReward(meritRewardIds[0]) - assert.strictEqual(rewardInformation[10], true, 'reward is claimed') - }) + it('receives rewards merit', async () => { + await app.claimReward(meritRewardIds[0]) + const balance = await rewardToken.balanceOf(root) + assert(balance == 2e18, 'reward should be 2e18 or 2eth equivalant; 1 for each reward') + rewardInformation = await app.getReward(meritRewardIds[0]) + assert.strictEqual(rewardInformation[10], true, 'reward is claimed') + }) - it('gets total rewards amount claimed', async () => { - const totalClaimed = await app.getTotalAmountClaimed(rewardToken.address) - assert.strictEqual( - web3.fromWei(totalClaimed.toNumber(),'ether'), - '2', - 'total claims incorrect: should be 2 Eth' - ) - }) + it('gets total rewards amount claimed', async () => { + const totalClaimed = await app.getTotalAmountClaimed(rewardToken.address) + assert.strictEqual( + web3.fromWei(totalClaimed.toNumber(),'ether'), + '2', + 'total claims incorrect: should be 2 Eth' + ) + }) - it('gets total claims made', async () => { - const totalClaims = await app.totalClaimsEach() - assert.strictEqual(totalClaims.toString(), '2', 'total individual claims should be 2') - }) + it('gets total claims made', async () => { + const totalClaims = await app.totalClaimsEach() + assert.strictEqual(totalClaims.toString(), '2', 'total individual claims should be 2') + }) - it('creates a merit reward that started in the past', async () => { - let blockNumber = await getBlockNumber() - meritRewardIds = rewardAdded( - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 4e18, - minBlock, - blockNumber - minBlock, - 1, - 0 + it('creates a merit reward that started in the past', async () => { + let blockNumber = await getBlockNumber() + meritRewardIds = rewardAdded( + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 4e18, + minBlock, + blockNumber - minBlock, + 1, + 0 + ) ) - ) - let meritRewardId = meritRewardIds[0] - - assert(meritRewardId == 3, 'fourth reward should be id 3') - }) + let meritRewardId = meritRewardIds[0] - it('can read rewards array length', async () => { - const rewardsLength = await app.getRewardsLength() - assert.strictEqual(rewardsLength.toNumber(), 4, 'rewards array length incorrect') - }) + assert(meritRewardId == 3, 'fourth reward should be id 3') + }) - }) + it('can read rewards array length', async () => { + const rewardsLength = await app.getRewardsLength() + assert.strictEqual(rewardsLength.toNumber(), 4, 'rewards array length incorrect') + }) - context('Check require statements and edge cases', () => { - - it('fails to create reward without permission', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - false, - root, - rewardToken.address, - 4e18, - minBlock, - 1, - 1, - 0 + it('creates a ETH reward', async () => { + let blockNumber = await getBlockNumber() + meritRewardIds = rewardAdded( + await app.newReward( + 'testETHReward', + true, + referenceToken.address, + 0x0, + 4e18, + blockNumber, + 6, + 1, + 0 + ) ) + let meritRewardId = meritRewardIds[0] + await referenceToken.generateTokens(root, 1e18) + await referenceToken.generateTokens(contributor1, 1e18) + await referenceToken.generateTokens(contributor2, 1e18) + await referenceToken.generateTokens(contributor3, 1e18) + await mineBlock() + await mineBlock() + assert.strictEqual(meritRewardId.toNumber(), 4, 'fifth reward should be id 4') }) }) - it('fails to create reward with period starting prior to token creation', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - false, - root, - rewardToken.address, - 4e18, - minBlock-1, - 1, - 1, - 0 - ) + context('Check require statements and edge cases', () => { + let meritRewardIds + + it('fails to create reward without permission', async () => { + return assertRevert(async () => { + await app.newReward( + 'testReward', + false, + root, + rewardToken.address, + 4e18, + minBlock, + 1, + 1, + 0 + ) + }) }) - }) + it('fails to create reward with period starting prior to token creation', async () => { + return assertRevert(async () => { + await app.newReward( + 'testReward', + false, + referenceToken.address, + rewardToken.address, + 4e18, + minBlock-1, + 1, + 1, + 0 + ) + }) + }) - it('fails to create reward with invalid reference token', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - false, - root, - rewardToken.address, - 4e18, - minBlock, - 1, - 1, - 0 - ) + + it('fails to create reward with invalid reference token', async () => { + return assertRevert(async () => { + await app.newReward( + 'testReward', + false, + root, + rewardToken.address, + 4e18, + minBlock, + 1, + 1, + 0 + ) + }) }) - }) - it('fails to create reward with invalid reward token', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - false, - referenceToken.address, - root, - 4e18, - minBlock, - 1, - 1, - 0 - ) + it('fails to create reward with invalid reward token', async () => { + return assertRevert(async () => { + await app.newReward( + 'testReward', + false, + referenceToken.address, + root, + 4e18, + minBlock, + 1, + 1, + 0 + ) + }) }) - }) - it('fails to create merit reward multiple occurances', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 6, - 4e18, - minBlock, - 4, - 0 - ) + it('fails to create merit reward multiple occurances', async () => { + return assertRevert(async () => { + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 6, + 4e18, + minBlock, + 4, + 0 + ) + }) + }) + + it('fails to create merit reward multiple occurances', async () => { + assertRevert(async () => { + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 6, + 4e18, + minBlock, + 4, + 0 + ) + }) }) - }) - it('fails to create dividend reward too many occurances', () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - false, - referenceToken.address, - rewardToken.address, - 6, - 4e18, - minBlock, - 43, - 0 + it('fails to create dividend reward too many occurances', async () => { + assertRevert(async () => { + await app.newReward( + 'testReward', + false, + referenceToken.address, + rewardToken.address, + 6, + 4e18, + minBlock, + 43, + 0 + ) + }) + }) + + it('pays out a merit reward of zero with no token changes', async() => { + let blockNumber = await getBlockNumber() + const meritRewardId = rewardAdded( + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 4e18, + blockNumber, + 1, + 1, + 0 + ) ) + const award = await app.getReward(meritRewardId) + await app.claimReward(meritRewardId) + assert.strictEqual(award[9].toNumber(), 0, 'amount should be 0') }) - }) - it('pays out a merit reward of zero with no token changes', async() => { - let blockNumber = await getBlockNumber() - const meritRewardId = rewardAdded( - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 4e18, - blockNumber, - 1, - 1, - 0 + it('pays out a merit reward of zero with no token changes for the user', async() => { + let blockNumber = await getBlockNumber() + const meritRewardId = rewardAdded( + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 4e18, + blockNumber, + 2, + 1, + 0 + ) ) - ) - const award = await app.getReward(meritRewardId) - await app.claimReward(meritRewardId) - assert.strictEqual(award[9].toNumber(), 0, 'amount should be 0') - }) + const origBalance = await rewardToken.balanceOf(root) + await referenceToken.generateTokens(contributor1, 1e18) + await referenceToken.generateTokens(contributor2, 1e18) + await mineBlock() + await app.claimReward(meritRewardId) + const newBalance = await rewardToken.balanceOf(root) + assert.strictEqual(newBalance.toNumber(), origBalance.toNumber(), 'balance awarded should be zero') + }) - it('pays out a merit reward of zero with no token changes for the user', async() => { - let blockNumber = await getBlockNumber() - const meritRewardId = rewardAdded( - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 4e18, - blockNumber, - 2, - 1, - 0 + it('cannot claim reward before period ends', async () => { + let blockNumber = await getBlockNumber() + meritRewardIds = rewardAdded( + await app.newReward( + 'testReward', + true, + referenceToken.address, + rewardToken.address, + 400e18, + blockNumber, + 6, + 1, + 0 + ) ) - ) - const origBalance = await rewardToken.balanceOf(root) - await referenceToken.generateTokens(contributor1, 1e18) - await referenceToken.generateTokens(contributor2, 1e18) - await mineBlock() - await app.claimReward(meritRewardId) - const newBalance = await rewardToken.balanceOf(root) - assert.strictEqual(newBalance.toNumber(), origBalance.toNumber(), 'balance awarded should be zero') + let meritRewardId = meritRewardIds[0] + await referenceToken.generateTokens(root, 1e18) + await referenceToken.generateTokens(contributor1, 1e18) + await referenceToken.generateTokens(contributor2, 1e18) + await referenceToken.generateTokens(contributor3, 1e18) + return assertRevert(async () => { + await app.claimReward(meritRewardId, { from: root }) + }) + //await mineBlock() + //await mineBlock() + //assert(meritRewardId == 2, 'third reward should be id 2') + }) + + it('reverts if vault contains insufficient reward tokens', async () => { + let meritRewardId = meritRewardIds[0] + await mineBlock() + return assertRevert(async () => { + await app.claimReward(meritRewardId, { from: root }) + }) + }) }) }) - }) From a78c4ee3c279279196aff0b72ccf73e30e9161fb Mon Sep 17 00:00:00 2001 From: topocount Date: Thu, 9 May 2019 15:00:40 -0700 Subject: [PATCH 6/7] delete unnecessary lines --- apps/rewards/test/Rewards.test.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/apps/rewards/test/Rewards.test.js b/apps/rewards/test/Rewards.test.js index 387d3ff0f..657dbc5bc 100644 --- a/apps/rewards/test/Rewards.test.js +++ b/apps/rewards/test/Rewards.test.js @@ -351,22 +351,6 @@ contract('Rewards App', accounts => { }) }) - it('fails to create merit reward multiple occurances', async () => { - assertRevert(async () => { - await app.newReward( - 'testReward', - true, - referenceToken.address, - rewardToken.address, - 6, - 4e18, - minBlock, - 4, - 0 - ) - }) - }) - it('fails to create dividend reward too many occurances', async () => { assertRevert(async () => { await app.newReward( @@ -450,9 +434,6 @@ contract('Rewards App', accounts => { return assertRevert(async () => { await app.claimReward(meritRewardId, { from: root }) }) - //await mineBlock() - //await mineBlock() - //assert(meritRewardId == 2, 'third reward should be id 2') }) it('reverts if vault contains insufficient reward tokens', async () => { From 8bc02178af3041d7a85faab16f1172c6e1897ae6 Mon Sep 17 00:00:00 2001 From: topocount Date: Thu, 9 May 2019 15:13:15 -0700 Subject: [PATCH 7/7] delete redundant projects tests --- apps/projects/test/projects.test.js | 164 ---------------------------- 1 file changed, 164 deletions(-) diff --git a/apps/projects/test/projects.test.js b/apps/projects/test/projects.test.js index f58b0cae2..7d8a00fec 100644 --- a/apps/projects/test/projects.test.js +++ b/apps/projects/test/projects.test.js @@ -764,118 +764,6 @@ contract('Projects App', accounts => { }) }) - xit('fulfill bounties and accept fulfillment', async () => { - const IssueData1 = await app.getIssue(repoId, 1) - const bountyId1 = IssueData1[1].toNumber() - const fulfillmentId1 = fulfilledBounty( - await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment1 = await bounties.getFulfillment( - bountyId1, - fulfillmentId1 - ) - assert(fulfillment1[0] === false) - await app.acceptFulfillment(repoId, 1, fulfillmentId1, { - from: bountyAdder, - }) - fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) - assert(fulfillment1[0] === true) - - const IssueData2 = await app.getIssue(repoId, 2) - const bountyId2 = IssueData2[1].toNumber() - const fulfillmentId2 = fulfilledBounty( - await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment2 = await bounties.getFulfillment( - bountyId2, - fulfillmentId2 - ) - assert(fulfillment2[0] === false) - await app.acceptFulfillment(repoId, 2, fulfillmentId2, { - from: bountyAdder, - }) - fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) - assert(fulfillment2[0] === true) - - const IssueData3 = await app.getIssue(repoId, 3) - const bountyId3 = IssueData3[1].toNumber() - const fulfillmentId3 = fulfilledBounty( - await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment3 = await bounties.getFulfillment( - bountyId3, - fulfillmentId3 - ) - assert(fulfillment3[0] === false) - await app.acceptFulfillment(repoId, 3, fulfillmentId3, { - from: bountyAdder, - }) - fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) - assert(fulfillment3[0] === true) - }) - - xit('verify balance is correct before and after accepting fulfillment in standard bounty', async () => { - const IssueData1 = await app.getIssue(repoId, 1) - const bountyId1 = IssueData1[1].toNumber() - const fulfillmentId1 = fulfilledBounty( - await bounties.fulfillBounty(bountyId1, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment1 = await bounties.getFulfillment( - bountyId1, - fulfillmentId1 - ) - assert(fulfillment1[0] === false) - let bounty1 = await bounties.getBounty(bountyId1) - assert.strictEqual(bounty1[5].toNumber(), 10) - await app.acceptFulfillment(repoId, 1, fulfillmentId1, { - from: bountyAdder, - }) - fulfillment1 = await bounties.getFulfillment(bountyId1, fulfillmentId1) - assert(fulfillment1[0] === true) - bounty1 = await bounties.getBounty(bountyId1) - assert.strictEqual(bounty1[5].toNumber(), 0) - - const IssueData2 = await app.getIssue(repoId, 2) - const bountyId2 = IssueData2[1].toNumber() - const fulfillmentId2 = fulfilledBounty( - await bounties.fulfillBounty(bountyId2, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment2 = await bounties.getFulfillment( - bountyId2, - fulfillmentId2 - ) - assert(fulfillment2[0] === false) - let bounty2 = await bounties.getBounty(bountyId2) - assert.strictEqual(bounty2[5].toNumber(), 20) - await app.acceptFulfillment(repoId, 2, fulfillmentId2, { - from: bountyAdder, - }) - fulfillment2 = await bounties.getFulfillment(bountyId2, fulfillmentId2) - assert(fulfillment2[0] === true) - bounty2 = await bounties.getBounty(bountyId2) - assert.strictEqual(bounty2[5].toNumber(), 0) - - const IssueData3 = await app.getIssue(repoId, 3) - const bountyId3 = IssueData3[1].toNumber() - const fulfillmentId3 = fulfilledBounty( - await bounties.fulfillBounty(bountyId3, 'findthemillenniumfalcon') - )._fulfillmentId.toNumber() - let fulfillment3 = await bounties.getFulfillment( - bountyId3, - fulfillmentId3 - ) - assert(fulfillment3[0] === false) - let bounty3 = await bounties.getBounty(bountyId3) - assert.strictEqual(bounty3[5].toNumber(), 30) - await app.acceptFulfillment(repoId, 3, fulfillmentId3, { - from: bountyAdder, - }) - fulfillment3 = await bounties.getFulfillment(bountyId3, fulfillmentId3) - assert(fulfillment3[0] === true) - bounty3 = await bounties.getBounty(bountyId3) - assert.strictEqual(bounty3[5].toNumber(), 0) - }) - it('can issue bulk token bounties', async () => { const issueNumber = 1 let issue3Receipt @@ -1031,9 +919,6 @@ contract('Projects App', accounts => { ) }) }) - xit('should revert if an issue has an already assigned bounty', async () => { - // assert() - }) }) }) @@ -1158,55 +1043,6 @@ contract('Projects App', accounts => { ) }) }) - - xit('cannot accept unfulfilled bounties', async () => { - let repoId = addedRepo( - await app.addRepo( - 'MDEyOk9yZ2FuaXphdGlvbjM0MDE4MzU5', - { from: owner1 } - ) - ) - await app.addBounties( - Array(3).fill(repoId), - [ 1, 2, 3 ], - [ 10, 20, 30 ], - [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], - [ false, false, false ], - [ 0, 0, 0 ], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmVtYjNij3KeyGmcgg7yVXWskLaBtov3UYL9pgcGK3MCWuQmR45FmbVVrixReBwJkhEKde2qwHYaQzGxu4ZoDeswuF9w', - 'something else', - { from: bountyAdder, value: 60 } - ) - assertRevert(async () => { - await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) - }) - await bounties.fulfillBounty(0, 'findthemillenniumfalcon') - let fulfillment1 = await bounties.getFulfillment(0, 0) - assert(fulfillment1[0] === false) - await app.acceptFulfillment(repoId, 0, 0, { from: bountyAdder }) - fulfillment1 = await bounties.getFulfillment(0, 0) - assert(fulfillment1[0] === true) - }) - - xit('cannot issue bulk bounties with mismatched values', async () => { - const bountyAdder = accounts[2] - const repoId = addedRepo( - await app.addRepo('abc', { from: owner1 }) - ) - assertRevert(async () => { - await app.addBounties( - Array(3).fill(repoId), - [ 1, 2, 3 ], - [ 10, 20, 30 ], // 60 total Wei should be sent - [ Date.now() + 86400, Date.now() + 86400, Date.now() + 86400 ], - [ false, false, false ], - [ 0, 0, 0 ], - 'QmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDCQmbUSy8HCn8J4TMDRRdxCbK2uCCtkQyZtY6XYv3y7kLgDC', - 'something awesome', - { from: bountyAdder, value: 61 } // 61 Wei sent instead - ) - }) - }) }) }) })