diff --git a/apps/agent/test/agent.js b/apps/agent/test/agent.js index f5b5f24190..e6befe864b 100644 --- a/apps/agent/test/agent.js +++ b/apps/agent/test/agent.js @@ -1,33 +1,27 @@ -const Agent = artifacts.require('Agent') - -const { assertRevert, assertInvalidOpcode } = require('@aragon/test-helpers/assertThrow') +const { assertRevert } = require('@aragon/test-helpers/assertThrow') const { hash: namehash } = require('eth-ens-namehash') const ethUtil = require('ethereumjs-util') const getBalance = require('@aragon/test-helpers/balance')(web3) const web3Call = require('@aragon/test-helpers/call')(web3) const web3Sign = require('@aragon/test-helpers/sign')(web3) -const { encodeCallScript, EMPTY_SCRIPT } = require('@aragon/test-helpers/evmScript') +const { encodeCallScript } = require('@aragon/test-helpers/evmScript') const assertEvent = require('@aragon/test-helpers/assertEvent') const ethABI = new (require('web3-eth-abi').AbiCoder)() const getEvent = (receipt, event, arg) => { return receipt.logs.filter(l => l.event == event)[0].args[arg] } -const ACL = artifacts.require('ACL') -const AppProxyUpgradeable = artifacts.require('AppProxyUpgradeable') -const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') -const DAOFactory = artifacts.require('DAOFactory') -const Kernel = artifacts.require('Kernel') -const KernelProxy = artifacts.require('KernelProxy') - -const EtherTokenConstantMock = artifacts.require('EtherTokenConstantMock') -const DestinationMock = artifacts.require('DestinationMock') -const KernelDepositableMock = artifacts.require('KernelDepositableMock') +const Agent = artifacts.require('Agent') const ExecutionTarget = artifacts.require('ExecutionTarget') const DesignatedSigner = artifacts.require('DesignatedSigner') +const DestinationMock = artifacts.require('DestinationMock') +const EtherTokenConstantMock = artifacts.require('EtherTokenConstantMock') -const NULL_ADDRESS = '0x00' -const NO_SIG = '0x' +const ACL = artifacts.require('ACL') +const Kernel = artifacts.require('Kernel') +const DAOFactory = artifacts.require('DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') +const NO_SIG = '0x' const ERC165_SUPPORT_INTERFACE_ID = '0x01ffc9a7' const ERC165_SUPPORT_INVALID_ID = '0xffffffff' @@ -171,17 +165,13 @@ contract('Agent app', (accounts) => { it('fails to execute without permissions', async () => { const data = executionTarget.contract.execute.getData() - await assertRevert(() => - agent.execute(executionTarget.address, depositAmount, data, { from: nonExecutor }) - ) + await assertRevert(agent.execute(executionTarget.address, depositAmount, data, { from: nonExecutor })) }) it('fails to execute actions with more ETH than the agent owns', async () => { const data = executionTarget.contract.execute.getData() - await assertRevert(() => - agent.execute(executionTarget.address, depositAmount + 1, data, { from: executor }) - ) + await assertRevert(agent.execute(executionTarget.address, depositAmount + 1, data, { from: executor })) }) it('execution forwards success return data', async () => { @@ -201,9 +191,7 @@ contract('Agent app', (accounts) => { // ganache currently doesn't support fetching this data const data = executionTarget.contract.fail.getData() - await assertRevert(() => - agent.execute(executionTarget.address, depositAmount, data, { from: executor }) - ) + await assertRevert(agent.execute(executionTarget.address, depositAmount, data, { from: executor })) }) context('depending on the sig ACL param', () => { @@ -248,18 +236,14 @@ contract('Agent app', (accounts) => { it('equal: fails to execute if signature doesn\'t match', async () => { const data = executionTarget.contract.execute.getData() - await assertRevert(() => - agent.execute(executionTarget.address, depositAmount, data, { from: granteeEqualToSig }) - ) + await assertRevert(agent.execute(executionTarget.address, depositAmount, data, { from: granteeEqualToSig })) }) it('not equal: fails to execute if the signature matches', async () => { const N = 1102 const data = executionTarget.contract.setCounter.getData(N) - await assertRevert(() => - agent.execute(executionTarget.address, depositAmount, data, { from: granteeUnequalToSig }) - ) + await assertRevert(agent.execute(executionTarget.address, depositAmount, data, { from: granteeUnequalToSig })) }) }) }) @@ -294,9 +278,7 @@ contract('Agent app', (accounts) => { assert.isFalse(await agent.canForward(nonScriptRunner, script)) assert.equal(await executionTarget.counter(), 0) - await assertRevert(() => - agent.forward(script, { from: nonScriptRunner }) - ) + await assertRevert(agent.forward(script, { from: nonScriptRunner })) assert.equal(await executionTarget.counter(), 0) }) }) @@ -355,9 +337,7 @@ contract('Agent app', (accounts) => { }) it('fails to presign a hash if not authorized', async () => { - await assertRevert(() => - agent.presignHash(HASH, { from: nobody }) - ) + await assertRevert(agent.presignHash(HASH, { from: nobody })) assertIsValidSignature(false, await agent.isValidSignature(HASH, NO_SIG)) }) diff --git a/apps/finance/test/finance.js b/apps/finance/test/finance.js index 331157a81b..996572569a 100644 --- a/apps/finance/test/finance.js +++ b/apps/finance/test/finance.js @@ -32,15 +32,13 @@ const tokenTestGroups = [ }, ] -contract('Finance App', accounts => { +contract('Finance App', ([root, owner, recipient]) => { let daoFact, financeBase, finance, vaultBase, vault, token1, token2 let ETH, MAX_UINT64, ANY_ENTITY, APP_MANAGER_ROLE let CREATE_PAYMENTS_ROLE, CHANGE_PERIOD_ROLE, CHANGE_BUDGETS_ROLE, EXECUTE_PAYMENTS_ROLE, MANAGE_PAYMENTS_ROLE let TRANSFER_ROLE - const root = accounts[0] - const n = '0x00' const NOW = 1 const ONE_DAY = 60 * 60 * 24 // One day in seconds const PERIOD_DURATION = ONE_DAY @@ -126,11 +124,11 @@ contract('Finance App', accounts => { await vault.initialize() // Set up initial balances - token1 = await TokenMock.new(accounts[0], 10000 + VAULT_INITIAL_TOKEN1_BALANCE) - await token1.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE) - token2 = await TokenMock.new(accounts[0], 10000 + VAULT_INITIAL_TOKEN2_BALANCE) - await token2.transfer(vault.address, VAULT_INITIAL_TOKEN2_BALANCE) - await vault.deposit(ETH, VAULT_INITIAL_ETH_BALANCE, { value: VAULT_INITIAL_ETH_BALANCE, from: accounts[0] }); + token1 = await TokenMock.new(owner, 10000 + VAULT_INITIAL_TOKEN1_BALANCE) + await token1.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE, { from: owner }) + token2 = await TokenMock.new(owner, 10000 + VAULT_INITIAL_TOKEN2_BALANCE) + await token2.transfer(vault.address, VAULT_INITIAL_TOKEN2_BALANCE, { from: owner }) + await vault.deposit(ETH, VAULT_INITIAL_ETH_BALANCE, { value: VAULT_INITIAL_ETH_BALANCE, from: owner }); await finance.initialize(vault.address, PERIOD_DURATION) }) @@ -151,31 +149,27 @@ contract('Finance App', accounts => { }) it('fails on reinitialization', async () => { - return assertRevert(async () => { - await finance.initialize(vault.address, PERIOD_DURATION) - }) + await assertRevert(finance.initialize(vault.address, PERIOD_DURATION)) }) it('cannot initialize base app', async () => { const newFinance = await Finance.new() assert.isTrue(await newFinance.isPetrified()) - return assertRevert(async () => { - await newFinance.initialize(vault.address, PERIOD_DURATION) - }) + await assertRevert(newFinance.initialize(vault.address, PERIOD_DURATION)) }) it('fails on initializing with no vault', async () => { const { financeApp } = await newProxyFinance() - await assertRevert(() => financeApp.initialize(0, PERIOD_DURATION)) - await assertRevert(() => financeApp.initialize(withdrawAddr, PERIOD_DURATION)) + await assertRevert(financeApp.initialize(0, PERIOD_DURATION)) + await assertRevert(financeApp.initialize(withdrawAddr, PERIOD_DURATION)) }) it('fails on initializing with less than one day period', async () => { const badPeriod = 60 * 60 * 24 - 1 const { financeApp } = await newProxyFinance() - return assertRevert(() => financeApp.initialize(vault.address, badPeriod)) + await assertRevert(financeApp.initialize(vault.address, badPeriod)) }) it('adds new token to budget', async () => { @@ -189,7 +183,6 @@ contract('Finance App', accounts => { }) it('before setting budget allows unlimited spending', async () => { - const recipient = accounts[1] const amount = 190 await finance.newImmediatePayment(token2.address, recipient, amount, '') @@ -230,13 +223,13 @@ contract('Finance App', accounts => { beforeEach(async () => { // Set up a new token similar to token1's distribution - tokenInstance = await tokenContract.new(accounts[0], 10000 + VAULT_INITIAL_TOKEN1_BALANCE) - await tokenInstance.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE) + tokenInstance = await tokenContract.new(owner, 10000 + VAULT_INITIAL_TOKEN1_BALANCE) + await tokenInstance.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE, { from: owner }) }) it('records deposits', async () => { - await tokenInstance.approve(finance.address, transferAmount) - const receipt = await finance.deposit(tokenInstance.address, transferAmount, 'ref') + await tokenInstance.approve(finance.address, transferAmount, { from: owner }) + const receipt = await finance.deposit(tokenInstance.address, transferAmount, 'ref', { from: owner }) // vault has 100 tokens initially assert.equal((await tokenInstance.balanceOf(vault.address)).valueOf(), VAULT_INITIAL_TOKEN1_BALANCE + transferAmount, 'deposited tokens must be in vault') @@ -247,16 +240,14 @@ contract('Finance App', accounts => { assert.equal(paymentId, 0, 'payment id should be 0') assert.equal(paymentExecutionNumber, 0, 'payment execution number should be 0') assert.equal(token, tokenInstance.address, 'token should be correct') - assert.equal(entity, accounts[0], 'entity should be correct') + assert.equal(entity, owner, 'entity should be correct') assert.isTrue(incoming, 'tx should be incoming') assert.equal(date, 1, 'date should be correct') assert.equal(getEventData(receipt, 'NewTransaction', 'reference'), 'ref', 'ref should be correct') }) it('fails on no value deposits', async () => { - await assertRevert(() => { - return finance.deposit(tokenInstance.address, 0, 'ref') - }) + await assertRevert(finance.deposit(tokenInstance.address, 0, 'ref')) }) }) } @@ -266,7 +257,7 @@ contract('Finance App', accounts => { it('records deposits using deposit function', async () => { const reference = 'deposit reference' - const receipt = await finance.deposit(ETH, sentWei, reference, { value: sentWei }) + const receipt = await finance.deposit(ETH, sentWei, reference, { from: owner, value: sentWei }) const transactionId = receipt.logs.filter(log => log.event == 'NewTransaction')[0].args.transactionId @@ -278,14 +269,14 @@ contract('Finance App', accounts => { assert.equal(paymentId, 0, 'payment id should be 0') assert.equal(paymentExecutionNumber, 0, 'payment execution number should be 0') assert.equal(token, ETH, 'token should be ETH token') - assert.equal(entity, accounts[0], 'entity should be correct') + assert.equal(entity, owner, 'entity should be correct') assert.isTrue(incoming, 'tx should be incoming') assert.equal(date, 1, 'date should be correct') assert.equal(getEventData(receipt, 'NewTransaction', 'reference'), reference, 'ref should be correct') }) it('records ETH deposits using fallback', async () => { - const receipt = await finance.send(sentWei) + const receipt = await finance.sendTransaction({ from: owner, value: sentWei }) const transactionId = receipt.logs.filter(log => log.event == 'NewTransaction')[0].args.transactionId const [periodId, amount, paymentId, paymentExecutionNumber, token, entity, incoming, date] = await finance.getTransaction(transactionId) @@ -296,7 +287,7 @@ contract('Finance App', accounts => { assert.equal(paymentId, 0, 'payment id should be 0') assert.equal(paymentExecutionNumber, 0, 'payment execution number should be 0') assert.equal(token, ETH, 'token should be ETH token') - assert.equal(entity, accounts[0], 'entity should be correct') + assert.equal(entity, owner, 'entity should be correct') assert.isTrue(incoming, 'tx should be incoming') assert.equal(date, 1, 'date should be correct') assert.equal(getEventData(receipt, 'NewTransaction', 'reference'), 'Ether transfer to Finance app', 'ref should be correct') @@ -310,11 +301,11 @@ contract('Finance App', accounts => { beforeEach(async () => { // Set up a new token similar to token1's distribution - tokenInstance = await tokenContract.new(accounts[0], 10000 + VAULT_INITIAL_TOKEN1_BALANCE + lockedTokenAmount) - await tokenInstance.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE) + tokenInstance = await tokenContract.new(owner, 10000 + VAULT_INITIAL_TOKEN1_BALANCE + lockedTokenAmount) + await tokenInstance.transfer(vault.address, VAULT_INITIAL_TOKEN1_BALANCE, { from: owner }) // 'lock' tokens - await tokenInstance.transfer(finance.address, lockedTokenAmount) + await tokenInstance.transfer(finance.address, lockedTokenAmount, { from: owner }) }) it('allow recoverability is disabled', async () => { @@ -340,16 +331,12 @@ contract('Finance App', accounts => { }) it('fail to be recovered using AragonApp#transferToVault', async () => { - return assertRevert(() => ( - finance.transferToVault(tokenInstance.address) - )) + await assertRevert(finance.transferToVault(tokenInstance.address)) }) it('fail to be recovered if token balance is 0', async () => { // if current balance is zero, it reverts - return assertRevert(async () => ( - finance.recoverToVault(token2.address) - )) + await assertRevert(finance.recoverToVault(token2.address)) }) }) } @@ -385,24 +372,18 @@ contract('Finance App', accounts => { }) it('fails to be recovered using AragonApp#transferToVault', async () => { - return assertRevert(() => ( - finance.transferToVault(ETH) - )) + await assertRevert(finance.transferToVault(ETH)) }) it('fails to be recovered if ETH balance is 0', async () => { await finance.recoverToVault(ETH) // if current balance is zero, it reverts - return assertRevert(async () => ( - finance.recoverToVault(ETH) - )) + await assertRevert(finance.recoverToVault(ETH)) }) }) context('setting budget', () => { - const recipient = accounts[1] - beforeEach(async () => { await finance.setBudget(token1.address, 50) await finance.setBudget(token2.address, 100) @@ -412,7 +393,7 @@ contract('Finance App', accounts => { it('records payment', async () => { const amount = 10 // executes up to 10 times every 2 seconds - const receipt = await finance.newScheduledPayment(token1.address, recipient, amount, NOW, 2, 10, 'ref') + const receipt = await finance.newScheduledPayment(token1.address, recipient, amount, NOW, 2, 10, 'ref', { from: owner }) const [token, receiver, txAmount, initialTime, interval, maxExecutions, disabled, executions, createdBy] = await finance.getPayment(1) @@ -425,7 +406,7 @@ contract('Finance App', accounts => { assert.equal(getEventData(receipt, 'NewPayment', 'reference'), 'ref', 'ref should match') assert.isFalse(disabled, 'should be enabled') assert.equal(executions, 1, 'should be on first execution') - assert.equal(createdBy, accounts[0], 'should have correct creator') + assert.equal(createdBy, owner, 'should have correct creator') }) it('fails trying to get payment out of bounds', async () => { @@ -433,12 +414,8 @@ contract('Finance App', accounts => { // executes up to 10 times every 2 seconds await finance.newScheduledPayment(token1.address, recipient, amount, NOW, 2, 10, 'ref') - await assertRevert(async () => { - await finance.getPayment(0) - }) - await assertRevert(async () => { - await finance.getPayment(2) - }) + await assertRevert(finance.getPayment(0)) + await assertRevert(finance.getPayment(2)) }) it('fails trying to get transaction out of bounds', async () => { @@ -446,9 +423,7 @@ contract('Finance App', accounts => { // executes up to 10 times every 2 seconds await finance.newScheduledPayment(token1.address, recipient, amount, NOW, 2, 10, 'ref') - await assertRevert(async () => { - await finance.getTransaction(2) - }) + await assertRevert(finance.getTransaction(2)) }) it('can create single payment transaction', async () => { @@ -535,9 +510,7 @@ contract('Finance App', accounts => { it('doesnt record payment for single payment transaction', async () => { const receipt = await finance.newImmediatePayment(token1.address, recipient, 1, '') assertEvent(receipt, 'NewPayment', 0) - await assertRevert(async () => { - await finance.getPayment(1) - }) + await assertRevert(finance.getPayment(1)) }) context('multitransaction period', async () => { @@ -550,8 +523,8 @@ contract('Finance App', accounts => { await finance.executePayment(1) // first create payment doesn't get an id because it is simple immediate tx - await token1.approve(finance.address, 5) - await finance.deposit(token1.address, 5, '') + await token1.approve(finance.address, 5, { from: owner }) + await finance.deposit(token1.address, 5, '', { from: owner }) }) it('has correct token statements', async () => { @@ -583,9 +556,7 @@ contract('Finance App', accounts => { await finance.tryTransitionAccountingPeriod(1) const currentPeriodId = await finance.currentPeriodId() - return assertRevert(async () => { - await finance.getPeriod(currentPeriodId + 1) - }) + await assertRevert(finance.getPeriod(currentPeriodId + 1)) }) }) @@ -600,14 +571,10 @@ contract('Finance App', accounts => { it('fails when too many period transitions are needed', async () => { // Normal payments - await assertRevert(async () => { - await finance.newImmediatePayment(token1.address, recipient, 10, '') - }) + await assertRevert(finance.newImmediatePayment(token1.address, recipient, 10, '')) // Direct ETH transfers - await assertRevert(async () => { - await finance.send(10, { gas: 3e5 }) - }) + await assertRevert(finance.send(10, { gas: 3e5 })) }) it('can transition periods externally to remove deadlock for payments', async () => { @@ -654,27 +621,21 @@ contract('Finance App', accounts => { }) it('fails to create a zero-amount single payment', async () => { - await assertRevert(async () => { - await finance.newImmediatePayment(token1.address, recipient, 0, '') - }) + await assertRevert(finance.newImmediatePayment(token1.address, recipient, 0, '')) }) it('fails to create a single payment too high for the current budget', async () => { const budget = 10 await finance.setBudget(token1.address, budget) - return assertRevert(() => { - return finance.newImmediatePayment(token1.address, recipient, budget + 1, '') - }) + await assertRevert(finance.newImmediatePayment(token1.address, recipient, budget + 1, '')) }) it('fails to execute a single payment without enough funds', async () => { const vaultBalance = await vault.balance(token1.address) await finance.removeBudget(token1.address) // clear any budget restrictions - return assertRevert(async () => { - await finance.newImmediatePayment(token1.address, recipient, vaultBalance + 1, '') - }) + await assertRevert(finance.newImmediatePayment(token1.address, recipient, vaultBalance + 1, '')) }) }) @@ -708,48 +669,36 @@ contract('Finance App', accounts => { }) it('fails to create a zero-amount payment', async () => { - await assertRevert(async () => { - await finance.newScheduledPayment(token1.address, recipient, 0, NOW + 1, 1, 2, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, 0, NOW + 1, 1, 2, '')) }) it('fails to create a no-interval payment', async () => { - await assertRevert(async () => { - await finance.newScheduledPayment(token1.address, recipient, 1, NOW + 1, 0, 2, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, 1, NOW + 1, 0, 2, '')) }) it('fails to create a new one-time payment without enough budget', async () => { const budget = 10 await finance.setBudget(token1.address, budget) - return assertRevert(async () => { - await finance.newScheduledPayment(token1.address, recipient, budget + 1, NOW, 1, 1, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, budget + 1, NOW, 1, 1, '')) }) it('fails to create a new one-time payment without enough funds', async () => { const vaultBalance = await vault.balance(token1.address) await finance.removeBudget(token1.address) // clear any budget restrictions - return assertRevert(async () => { - await finance.newScheduledPayment(token1.address, recipient, vaultBalance + 1, NOW, 1, 1, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, vaultBalance + 1, NOW, 1, 1, '')) }) it('fails to create an immediate single payment', async () => { - await assertRevert(async () => { - await finance.newScheduledPayment(token1.address, recipient, 1, NOW - 1, 1, 1, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, 1, NOW - 1, 1, 1, '')) }) it('fails to create a scheduled payment too high for the current budget', async () => { const budget = 10 await finance.setBudget(token1.address, budget) - return assertRevert(() => { - return finance.newScheduledPayment(token1.address, recipient, budget + 1, NOW, 1, 2, '') - }) + await assertRevert(finance.newScheduledPayment(token1.address, recipient, budget + 1, NOW, 1, 2, '')) }) it('fails to execute a scheduled payment without enough funds', async () => { @@ -759,9 +708,7 @@ contract('Finance App', accounts => { const receipt = await finance.newScheduledPayment(token1.address, recipient, vaultBalance + 1, NOW, 1, 2, '') const newScheduledPaymentId = getEventData(receipt, 'NewPayment', 'paymentId') - return assertRevert(async () => { - await finance.executePayment(newScheduledPaymentId, { from: recipient }) - }) + await assertRevert(finance.executePayment(newScheduledPaymentId, { from: recipient })) }) context('created scheduled payment', async () => { @@ -791,30 +738,22 @@ contract('Finance App', accounts => { it('fails when non-receiver attempts to execute a payment', async () => { await finance.mockIncreaseTime(1) - return assertRevert(async () => { - await finance.receiverExecutePayment(paymentId) - }) + await assertRevert(finance.receiverExecutePayment(paymentId)) }) it('fails to execute a scheduled payment before next available time', async () => { - return assertRevert(async () => { - await finance.executePayment(paymentId, { from: recipient }) - }) + await assertRevert(finance.executePayment(paymentId, { from: recipient })) }) it('fails to execute a scheduled payment by receiver before next available time', async () => { - return assertRevert(async () => { - await finance.receiverExecutePayment(paymentId, { from: recipient }) - }) + await assertRevert(finance.receiverExecutePayment(paymentId, { from: recipient })) }) it('fails to execute inactive scheduled payment', async () => { await finance.setPaymentStatus(paymentId, false) await finance.mockIncreaseTime(1) - return assertRevert(async () => { - await finance.executePayment(paymentId, { from: recipient }) - }) + await assertRevert(finance.executePayment(paymentId, { from: recipient })) }) it('succeeds payment after setting payment status to active', async () => { @@ -885,42 +824,30 @@ contract('Finance App', accounts => { }) it('fails to create new scheduled payment', async() => { - const recipient = accounts[1] const amount = 1 - return assertRevert(async() => { - await nonInit.newScheduledPayment(token1.address, recipient, amount, NOW, 1, 2, 'ref') - }) + await assertRevert(nonInit.newScheduledPayment(token1.address, recipient, amount, NOW, 1, 2, 'ref')) }) it('fails to create new single payment transaction', async() => { - const recipient = accounts[1] const amount = 1 - return assertRevert(async() => { - await nonInit.newImmediatePayment(token1.address, recipient, amount, 'ref') - }) + await assertRevert(nonInit.newImmediatePayment(token1.address, recipient, amount, 'ref')) }) it('fails to deposit ERC20 tokens', async() => { - await token1.approve(nonInit.address, 5) - return assertRevert(async() => { - await nonInit.deposit(token1.address, 5, 'ref') - }) + await token1.approve(nonInit.address, 5, { from: owner }) + await assertRevert(nonInit.deposit(token1.address, 5, 'ref')) }) it('fails to send tokens to Vault', async() => { // 'lock' tokens - await token1.transfer(nonInit.address, 5) - return assertRevert(async() => { - await nonInit.recoverToVault(token1.address) - }) + await token1.transfer(nonInit.address, 5, { from: owner }) + await assertRevert(nonInit.recoverToVault(token1.address)) }) it('fails to deposit ETH', async() => { - return assertRevert(async() => { - await nonInit.send(10, { gas: 3e5 }) - }) + await assertRevert(nonInit.send(10, { gas: 3e5 })) }) context('locked ERC20', () => { @@ -928,7 +855,7 @@ contract('Finance App', accounts => { beforeEach(async () => { // 'lock' tokens - await token1.transfer(nonInit.address, lockedTokenAmount) + await token1.transfer(nonInit.address, lockedTokenAmount, { from: owner }) }) it('allow recoverability is enabled', async () => { @@ -942,9 +869,7 @@ contract('Finance App', accounts => { }) it('fail to be recovered using Finance#recoverToVault', async () => { - return assertRevert(async () => ( - finance.recoverToVault(token1.address) - )) + await assertRevert(finance.recoverToVault(token1.address)) }) }) @@ -961,9 +886,7 @@ contract('Finance App', accounts => { }) it('fails to be recovered using Finance#recoverToVault', async () => { - return assertRevert(async () => ( - await nonInit.recoverToVault(ETH) - )) + await assertRevert(nonInit.recoverToVault(ETH)) }) it('can recover ETH using AragonApp#transferToVault', async () => { diff --git a/apps/survey/test/survey.js b/apps/survey/test/survey.js index 51830251e8..3798b9a864 100644 --- a/apps/survey/test/survey.js +++ b/apps/survey/test/survey.js @@ -6,18 +6,13 @@ const pct16 = x => new web3.BigNumber(x).times(new web3.BigNumber(10).toPower(16 const surveyEvent = receipt => receipt.logs.filter(x => x.event == 'StartSurvey')[0].args const createdSurveyId = receipt => surveyEvent(receipt).surveyId -contract('Survey app', accounts => { +contract('Survey app', ([root, holder1, holder2, holder19, holder31, holder50, nonHolder]) => { let daoFact, dao, surveyBase, survey let ABSTAIN_VOTE, ANY_ENTITY let APP_MANAGER_ROLE, CREATE_SURVEYS_ROLE, MODIFY_PARTICIPATION_ROLE - const root = accounts[0] - const holder19 = accounts[0] - const holder31 = accounts[1] - const holder50 = accounts[2] - const nonHolder = accounts[4] - const NULL_ADDRESS = '0x00' + const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const SURVEY_APP_ID = '0x1234' const SURVEY_MOCK_APP_ID = '0x12341234' @@ -27,7 +22,7 @@ contract('Survey app', accounts => { before(async () => { const kernelBase = await getContract('Kernel').new(true) // petrify immediately const aclBase = await getContract('ACL').new() - daoFact = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, NULL_ADDRESS) + daoFact = await getContract('DAOFactory').new(kernelBase.address, aclBase.address, ZERO_ADDRESS) surveyBase = await getContract('SurveyMock').new() // Setup constants @@ -56,7 +51,7 @@ contract('Survey app', accounts => { let token beforeEach(async () => { - token = await getContract('MiniMeToken').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await getContract('MiniMeToken').new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await token.generateTokens(holder19, 19) await token.generateTokens(holder31, 31) @@ -66,17 +61,13 @@ contract('Survey app', accounts => { }) it('fails on reinitialization', async () => { - await assertRevert(async () => { - await survey.initialize(token.address, minimumAcceptanceParticipationPct, surveyTime) - }) + await assertRevert(survey.initialize(token.address, minimumAcceptanceParticipationPct, surveyTime)) }) it('cannot initialize base app', async () => { const newSurvey = await getContract('Survey').new() assert.isTrue(await newSurvey.isPetrified()) - await assertRevert(async () => { - await newSurvey.initialize(token.address, minimumAcceptanceParticipationPct, surveyTime) - }) + await assertRevert(newSurvey.initialize(token.address, minimumAcceptanceParticipationPct, surveyTime)) }) it('can change minimum acceptance participation', async () => { @@ -88,23 +79,19 @@ contract('Survey app', accounts => { }) it('cannot change minimum acceptance participation to 0', async () => { - await assertRevert(async () => { - await survey.changeMinAcceptParticipationPct(0) - }) + await assertRevert(survey.changeMinAcceptParticipationPct(0)) }) it('cannot change minimum acceptance participation to more than 100', async () => { - await assertRevert(async () => { - await survey.changeMinAcceptParticipationPct(pct16(101)) - }) + await assertRevert(survey.changeMinAcceptParticipationPct(pct16(101))) }) context('creating survey', () => { const optionsCount = 10e9 // lots of options - let surveyId + let surveyId, creator, metadata beforeEach(async () => { - createdEvent = surveyEvent(await survey.newSurvey('metadata', optionsCount, { from: nonHolder })) + const createdEvent = surveyEvent(await survey.newSurvey('metadata', optionsCount, { from: nonHolder })) surveyId = createdEvent.surveyId creator = createdEvent.creator metadata = createdEvent.metadata @@ -127,21 +114,15 @@ contract('Survey app', accounts => { }) it('fails getting a survey out of bounds', async () => { - await assertRevert(async () => { - await survey.getSurvey(surveyId + 1) - }) + await assertRevert(survey.getSurvey(surveyId + 1)) }) it('fails getting option power for a survey out of bounds', async () => { - await assertRevert(async () => { - await survey.getOptionPower(surveyId + 1, 0) - }) + await assertRevert(survey.getOptionPower(surveyId + 1, 0)) }) it('fails getting option power for an option out of bounds', async () => { - await assertRevert(async () => { - await survey.getOptionPower(surveyId, optionsCount + 1) - }) + await assertRevert(survey.getOptionPower(surveyId, optionsCount + 1)) }) it('counts votes properly', async () => { @@ -178,21 +159,15 @@ contract('Survey app', accounts => { it('fails if voting on non-existing option', async () => { await survey.voteOption(surveyId, optionsCount, { from: holder31 }) - await assertRevert(async () => { - await survey.voteOption(surveyId, optionsCount + 1, { from: holder31 }) - }) + await assertRevert(survey.voteOption(surveyId, optionsCount + 1, { from: holder31 })) }) it('fails if vote has no options', async () => { - await assertRevert(async () => { - await survey.voteOptions(surveyId, [], [], { from: holder50 }) - }) + await assertRevert(survey.voteOptions(surveyId, [], [], { from: holder50 })) }) it('fails if single-option vote is for ABSTAIN_VOTE', async () => { - await assertRevert(async () => { - await survey.voteOption(surveyId, ABSTAIN_VOTE, { from: holder50 }) - }) + await assertRevert(survey.voteOption(surveyId, ABSTAIN_VOTE, { from: holder50 })) }) it('allows to remove and re-vote', async () => { @@ -226,16 +201,12 @@ contract('Survey app', accounts => { }) it('throws when non-holder votes', async () => { - await assertRevert(async () => { - await survey.voteOption(surveyId, 1, { from: nonHolder }) - }) + await assertRevert(survey.voteOption(surveyId, 1, { from: nonHolder })) }) it('throws when voting after survey closes', async () => { await survey.mockIncreaseTime(surveyTime + 1) - await assertRevert(async () => { - await survey.voteOption(surveyId, 1, { from: holder31 }) - }) + await assertRevert(survey.voteOption(surveyId, 1, { from: holder31 })) }) it('casts complete multi option vote', async () => { @@ -262,27 +233,19 @@ contract('Survey app', accounts => { }) it('fails if multi option vote has different size arrays', async () => { - await assertRevert(async () => { - await survey.voteOptions(surveyId, [1,2], [10, 10, 11], { from: holder31 }) - }) + await assertRevert(survey.voteOptions(surveyId, [1,2], [10, 10, 11], { from: holder31 })) }) it('fails if multi option vote has unordered options', async () => { - await assertRevert(async () => { - await survey.voteOptions(surveyId, [2,1], [10, 21], { from: holder31 }) - }) + await assertRevert(survey.voteOptions(surveyId, [2,1], [10, 21], { from: holder31 })) }) it('fails if multi option vote has NO VOTE option', async () => { - await assertRevert(async () => { - await survey.voteOptions(surveyId, [ABSTAIN_VOTE, 2], [10, 21], { from: holder31 }) - }) + await assertRevert(survey.voteOptions(surveyId, [ABSTAIN_VOTE, 2], [10, 21], { from: holder31 })) }) it('fails if multi option vote has a zero stake option', async () => { - await assertRevert(async () => { - await survey.voteOptions(surveyId, [1,2], [10, 0], { from: holder31 }) - }) + await assertRevert(survey.voteOptions(surveyId, [1,2], [10, 0], { from: holder31 })) }) }) }) @@ -291,7 +254,7 @@ contract('Survey app', accounts => { let token beforeEach(async () => { - token = await getContract('MiniMeToken').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await getContract('MiniMeToken').new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await token.generateTokens(holder19, 19) await token.generateTokens(holder31, 31) @@ -300,43 +263,35 @@ contract('Survey app', accounts => { it('fails if min acceptance participation is 0', async () => { const badMinimumAcceptanceParticipationPct = pct16(0) - await assertRevert(async() => { - await survey.initialize(token.address, badMinimumAcceptanceParticipationPct, surveyTime) - }) + await assertRevert(survey.initialize(token.address, badMinimumAcceptanceParticipationPct, surveyTime)) }) it('fails if min participation is greater than 100', async () => { const badMinimumAcceptanceParticipationPct = pct16(101) - await assertRevert(async () => { - await survey.initialize(token.address, badMinimumAcceptanceParticipationPct, surveyTime) - }) + await assertRevert(survey.initialize(token.address, badMinimumAcceptanceParticipationPct, surveyTime)) }) }) context('before init', () => { it('fails creating a survey before initialization', async () => { - await assertRevert(async () => { - await survey.newSurvey('metadata', 10) - }) + await assertRevert(survey.newSurvey('metadata', 10)) }) }) context('empty token', () => { beforeEach(async() => { - const badToken = await getContract('MiniMeToken').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + const badToken = await getContract('MiniMeToken').new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await survey.initialize(badToken.address, minimumAcceptanceParticipationPct, surveyTime) }) it('fails creating a survey if token has no holder', async () => { - await assertRevert(async () => { - await survey.newSurvey('metadata', 10) - }) + await assertRevert(survey.newSurvey('metadata', 10)) }) }) context('wrong supply token', () => { beforeEach(async() => { - const badToken = await getContract('BadToken').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + const badToken = await getContract('BadToken').new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await badToken.generateTokens(holder19, 19) await survey.initialize(badToken.address, minimumAcceptanceParticipationPct, surveyTime) }) @@ -344,25 +299,19 @@ contract('Survey app', accounts => { // this bad token has broken `totalSupplyAt`, returning always 1 it('fails voting with more than 1 token because of wrong votingPower', async () => { const surveyId = createdSurveyId(await survey.newSurvey('metadata', 10)) - await assertRevert(async () => { - await survey.voteOption(surveyId, 10, { from: holder19 }) - }) + await assertRevert(survey.voteOption(surveyId, 10, { from: holder19 })) }) }) context('changing token supply', () => { - const optionsCount = 10e9 // lots of options - const holder1 = accounts[1] - const holder2 = accounts[2] - - let surveyMockBase + let surveyMockBase, token before(async () => { surveyMockBase = await getContract('SurveyMock').new() }) beforeEach(async () => { - token = await getContract('MiniMeToken').new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await getContract('MiniMeToken').new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await token.generateTokens(holder1, 1) await token.generateTokens(holder2, 1) diff --git a/apps/token-manager/test/tokenmanager.js b/apps/token-manager/test/tokenmanager.js index 8fa3aef6e3..7c6d699b6c 100644 --- a/apps/token-manager/test/tokenmanager.js +++ b/apps/token-manager/test/tokenmanager.js @@ -6,11 +6,10 @@ const ExecutionTarget = artifacts.require('ExecutionTarget') const TokenManager = artifacts.require('TokenManagerMock') const MiniMeToken = artifacts.require('MiniMeToken') -const DAOFactory = artifacts.require('@aragon/core/contracts/factory/DAOFactory') -const EVMScriptRegistryFactory = artifacts.require('@aragon/core/contracts/factory/EVMScriptRegistryFactory') const ACL = artifacts.require('@aragon/core/contracts/acl/ACL') const Kernel = artifacts.require('@aragon/core/contracts/kernel/Kernel') - +const DAOFactory = artifacts.require('@aragon/core/contracts/factory/DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('@aragon/core/contracts/factory/EVMScriptRegistryFactory') const EtherTokenConstantMock = artifacts.require('EtherTokenConstantMock') const getContract = name => artifacts.require(name) @@ -18,7 +17,7 @@ const getContract = name => artifacts.require(name) const n = '0x00' const ANY_ADDR = '0xffffffffffffffffffffffffffffffffffffffff' -contract('Token Manager', accounts => { +contract('Token Manager', ([root, holder, holder2, anyone]) => { let tokenManagerBase, daoFact, tokenManager, token let APP_MANAGER_ROLE @@ -27,10 +26,6 @@ contract('Token Manager', accounts => { const NOW = 1 - const root = accounts[0] - const holder = accounts[1] - const holder2 = accounts[2] - before(async () => { const kernelBase = await getContract('Kernel').new(true) // petrify immediately const aclBase = await getContract('ACL').new() @@ -93,15 +88,11 @@ contract('Token Manager', accounts => { }) it('fails when initializing without setting controller', async () => { - return assertRevert(async () => { - await tokenManager.initialize(token.address, true, 0) - }) + await assertRevert(tokenManager.initialize(token.address, true, 0)) }) it('fails when sending ether to token', async () => { - return assertRevert(async () => { - await token.send(1) // transfer 1 wei to token contract - }) + await assertRevert(token.send(1)) // transfer 1 wei to token contract }) context('non-transferable token', async () => { @@ -113,9 +104,7 @@ contract('Token Manager', accounts => { it('holders cannot transfer non-transferable tokens', async () => { await tokenManager.mint(holder, 2000) - return assertRevert(async () => { - await token.transfer(holder2, 10, { from: holder }) - }) + await assertRevert(token.transfer(holder2, 10, { from: holder })) }) it('token manager can transfer', async () => { @@ -144,9 +133,7 @@ contract('Token Manager', accounts => { await tokenManager.forward(script, { from: holder }) assert.equal(await executionTarget.counter(), 1, 'should have received execution call') - return assertRevert(async () => { - await tokenManager.forward(script, { from: accounts[8] }) - }) + await assertRevert(tokenManager.forward(script, { from: anyone })) }) }) @@ -165,9 +152,7 @@ contract('Token Manager', accounts => { }) it('fails to mint more than limit', async () => { - return assertRevert(async () => { - await tokenManager.mint(holder, limit + 1) - }) + await assertRevert(tokenManager.mint(holder, limit + 1)) }) it('can issue unlimited tokens to itself', async () => { @@ -196,9 +181,7 @@ contract('Token Manager', accounts => { it('cannot assign more than limit', async () => { await tokenManager.issue(limit + 2) - return assertRevert(async () => { - await tokenManager.assign(holder, limit + 1) - }) + await assertRevert(tokenManager.assign(holder, limit + 1)) }) it('can transfer tokens to token manager without regard to token limit', async () => { @@ -215,9 +198,7 @@ contract('Token Manager', accounts => { await tokenManager.assign(holder, limit - 1) await tokenManager.assign(holder2, limit - 1) - return assertRevert(async () => { - await token.transfer(holder2, 5, { from: holder }) - }) + await assertRevert(token.transfer(holder2, 5, { from: holder })) }) }) @@ -228,17 +209,13 @@ contract('Token Manager', accounts => { }) it('fails on reinitialization', async () => { - return assertRevert(async () => { - await tokenManager.initialize(token.address, true, 0) - }) + await assertRevert(tokenManager.initialize(token.address, true, 0)) }) it('cannot initialize base app', async () => { const newTokenManager = await TokenManager.new() assert.isTrue(await newTokenManager.isPetrified()) - return assertRevert(async () => { - await newTokenManager.initialize(token.address, true, 0) - }) + await assertRevert(newTokenManager.initialize(token.address, true, 0)) }) it('can mint tokens', async () => { @@ -269,17 +246,13 @@ contract('Token Manager', accounts => { }) it('cannot mint tokens to itself', async () => { - return assertRevert(async () => { - await tokenManager.mint(tokenManager.address, 100) - }) + await assertRevert(tokenManager.mint(tokenManager.address, 100)) }) it('cannot assign more tokens than owned', async () => { await tokenManager.issue(50) - return assertRevert(async () => { - await tokenManager.assign(holder, 51) - }) + await assertRevert(tokenManager.assign(holder, 51)) }) it('forwards actions only to token holders', async () => { @@ -292,9 +265,7 @@ contract('Token Manager', accounts => { await tokenManager.forward(script, { from: holder }) assert.equal(await executionTarget.counter(), 1, 'should have received execution call') - return assertRevert(async () => { - await tokenManager.forward(script, { from: accounts[8] }) - }) + await assertRevert(tokenManager.forward(script, { from: anyone })) }) it("cannot call onTransfer() from outside of the token's context", async () => { @@ -302,7 +273,7 @@ contract('Token Manager', accounts => { await tokenManager.mint(holder, amount) // Make sure this callback fails when called out-of-context - await assertRevert(() => tokenManager.onTransfer(holder, holder2, 10)) + await assertRevert(tokenManager.onTransfer(holder, holder2, 10)) // Make sure the same transfer through the token's context doesn't revert await token.transfer(holder2, amount, { from: holder }) @@ -313,7 +284,7 @@ contract('Token Manager', accounts => { await tokenManager.mint(holder, amount) // Make sure this callback fails when called out-of-context - await assertRevert(() => tokenManager.onApprove(holder, holder2, 10)) + await assertRevert(tokenManager.onApprove(holder, holder2, 10)) // Make sure no allowance was registered assert.equal(await token.allowance(holder, holder2), 0, 'token approval should be 0') @@ -324,18 +295,16 @@ contract('Token Manager', accounts => { const prevTokenManagerBalance = (await getBalance(tokenManager.address)).toNumber() // Make sure this callback fails when called out-of-context - await assertRevert(() => tokenManager.proxyPayment(root, { value })) + await assertRevert(tokenManager.proxyPayment(root, { value })) // Make sure no ETH was transferred assert.equal((await getBalance(tokenManager.address)).toNumber(), prevTokenManagerBalance, 'token manager ETH balance should be the same') }) it('fails when assigning invalid vesting schedule', async () => { - return assertRevert(async () => { - const tokens = 10 - // vesting < cliff - await tokenManager.assignVested(holder, tokens, 10, 20, 10, true) - }) + const tokens = 10 + // vesting < cliff + await assertRevert(tokenManager.assignVested(holder, tokens, 10, 20, 10, true)) }) it('allows to recover external tokens', async () => { @@ -364,9 +333,7 @@ contract('Token Manager', accounts => { }) it('fails trying to get vesting out of bounds', async () => { - return assertRevert(async () => { - await tokenManager.getVesting(holder, 1) - }) + await assertRevert(tokenManager.getVesting(holder, 1)) }) it('can get vesting details before being revoked', async () => { @@ -403,25 +370,19 @@ contract('Token Manager', accounts => { }) it('cannot transfer non-vested tokens', async () => { - return assertRevert(async () => { - await token.transfer(holder2, 10, { from: holder }) - }) + await assertRevert(token.transfer(holder2, 10, { from: holder })) }) it('can approve non-vested tokens but transferFrom fails', async () => { await token.approve(holder2, 10, { from: holder }) - return assertRevert(async () => { - await token.transferFrom(holder, holder2, 10, { from: holder2 }) - }) + await assertRevert(token.transferFrom(holder, holder2, 10, { from: holder2 })) }) it('cannot transfer all tokens right before vesting', async () => { await tokenManager.mockIncreaseTime(VESTING_DURATION - 10) - return assertRevert(async () => { - await token.transfer(holder2, totalTokens, { from: holder }) - }) + await assertRevert(token.transfer(holder2, totalTokens, { from: holder })) }) it('can be revoked and not vested tokens are transfered to token manager', async () => { @@ -436,18 +397,14 @@ contract('Token Manager', accounts => { }) it('cannot assign a vesting to itself', async () => { - return assertRevert(async () => { - await tokenManager.assignVested(tokenManager.address, 5, startDate, cliffDate, vestingDate, revokable) - }) + await assertRevert(tokenManager.assignVested(tokenManager.address, 5, startDate, cliffDate, vestingDate, revokable)) }) it('cannot revoke non-revokable vestings', async () => { await tokenManager.issue(1) await tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false) - return assertRevert(async () => { - await tokenManager.revokeVesting(holder, 1) - }) + await assertRevert(tokenManager.revokeVesting(holder, 1)) }) it('cannot have more than 50 vestings', async () => { @@ -458,15 +415,11 @@ contract('Token Manager', accounts => { await tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false) } - await assertRevert(async () => { - await tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false) - }) + await assertRevert(tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false)) // Can't create a new vesting even after other vestings have finished await tokenManager.mockIncreaseTime(VESTING_DURATION) - await assertRevert(async () => { - await tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false) - }) + await assertRevert(tokenManager.assignVested(holder, 1, startDate, cliffDate, vestingDate, false)) // But can now transfer await token.transfer(holder2, 1, { from: holder }) @@ -476,27 +429,19 @@ contract('Token Manager', accounts => { context('app not initialized', async () => { it('fails to mint tokens', async() => { - return assertRevert(async() => { - await tokenManager.mint(holder, 1) - }) + await assertRevert(tokenManager.mint(holder, 1)) }) it('fails to assign tokens', async() => { - return assertRevert(async() => { - await tokenManager.assign(holder, 1) - }) + await assertRevert(tokenManager.assign(holder, 1)) }) it('fails to issue tokens', async() => { - return assertRevert(async() => { - await tokenManager.issue(1) - }) + await assertRevert(tokenManager.issue(1)) }) it('fails to burn tokens', async() => { - return assertRevert(async() => { - await tokenManager.burn(holder, 1) - }) + await assertRevert(tokenManager.burn(holder, 1)) }) }) }) diff --git a/apps/vault/test/vault_shared.js b/apps/vault/test/vault_shared.js index 472f9da12c..c0082fcc3f 100644 --- a/apps/vault/test/vault_shared.js +++ b/apps/vault/test/vault_shared.js @@ -1,4 +1,4 @@ -const { assertRevert, assertInvalidOpcode } = require('@aragon/test-helpers/assertThrow') +const { assertRevert } = require('@aragon/test-helpers/assertThrow') const { hash } = require('eth-ens-namehash') const getBalanceFn = require('@aragon/test-helpers/balance') @@ -15,7 +15,6 @@ module.exports = ( const getEvent = (receipt, event, arg) => { return receipt.logs.filter(l => l.event == event)[0].args[arg] } const ACL = artifacts.require('ACL') - const AppProxyUpgradeable = artifacts.require('AppProxyUpgradeable') const EVMScriptRegistryFactory = artifacts.require('EVMScriptRegistryFactory') const DAOFactory = artifacts.require('DAOFactory') const Kernel = artifacts.require('Kernel') @@ -34,7 +33,6 @@ module.exports = ( const VaultLike = artifacts.require(vaultName) const root = accounts[0] - const NULL_ADDRESS = '0x00' context(`> Shared tests for Vault-like apps`, () => { let daoFact, vaultBase, vault, vaultId @@ -78,9 +76,7 @@ module.exports = ( it('cannot initialize base app', async () => { const newVault = await VaultLike.new() assert.isTrue(await newVault.isPetrified()) - await assertRevert(async () => { - await newVault.initialize() - }) + await assertRevert(newVault.initialize()) }) context('> ETH', () => { @@ -136,17 +132,13 @@ module.exports = ( await vault.sendTransaction( { value: transferValue }) // Transfer - await assertRevert(async () => { - await vault.transfer(ETH, destination.address, transferValue) - }) + await assertRevert(vault.transfer(ETH, destination.address, transferValue)) }) it('fails if depositing a different amount of ETH than sent', async () => { const value = 1 - await assertRevert(async () => { - await vault.deposit(ETH, value, { value: value * 2 }) - }) + await assertRevert(vault.deposit(ETH, value, { value: value * 2 })) }) }) @@ -197,9 +189,7 @@ module.exports = ( const approvedAmount = 10 await token.approve(vault.address, approvedAmount) - await assertRevert(async () => { - await vault.deposit(token.address, approvedAmount * 2) - }) + await assertRevert(vault.deposit(token.address, approvedAmount * 2)) assert.equal(await token.balanceOf(vault.address), 0, "vault should have initial token balance") }) @@ -210,9 +200,7 @@ module.exports = ( await token.setAllowTransfer(false) // Attempt to deposit - await assertRevert(() => - vault.deposit(token.address, 5) - ) + await assertRevert(vault.deposit(token.address, 5)) assert.equal(await token.balanceOf(vault.address), 0, "vault should have initial token balance") }) @@ -224,9 +212,7 @@ module.exports = ( await token.setAllowTransfer(false) // Attempt to transfer - await assertRevert(() => - vault.transfer(token.address, tokenReceiver, 5) - ) + await assertRevert(vault.transfer(token.address, tokenReceiver, 5)) assert.equal(await token.balanceOf(tokenReceiver), 0, "receiver should have initial token balance") assert.equal(await token.balanceOf(vault.address), 10, "vault should have initial token balance") }) @@ -281,13 +267,13 @@ module.exports = ( it('fails when attempting to recover ETH out of the vault', async () => { await vault.sendTransaction({ value: 1, gas: 31000 }) assert.equal((await getBalance(vault.address)).valueOf(), 1, 'vault should have 1 balance') - await assertRevert(() => vault.transferToVault(ETH)) + await assertRevert(vault.transferToVault(ETH)) }) it('fails when attempting to recover tokens out of the vault', async () => { await token.transfer(vault.address, 10) assert.equal((await token.balanceOf(vault.address)), 10, 'vault should have 10 balance') - await assertRevert(() => vault.transferToVault(token.address)) + await assertRevert(vault.transferToVault(token.address)) }) }) }) diff --git a/apps/voting/test/voting.js b/apps/voting/test/voting.js index 1a09f93b04..c82fa7fae7 100644 --- a/apps/voting/test/voting.js +++ b/apps/voting/test/voting.js @@ -3,15 +3,14 @@ const getBlockNumber = require('@aragon/test-helpers/blockNumber')(web3) const { encodeCallScript, EMPTY_SCRIPT } = require('@aragon/test-helpers/evmScript') const ExecutionTarget = artifacts.require('ExecutionTarget') -const DAOFactory = artifacts.require('@aragon/os/contracts/factory/DAOFactory') -const EVMScriptRegistryFactory = artifacts.require('@aragon/os/contracts/factory/EVMScriptRegistryFactory') +const Voting = artifacts.require('VotingMock') + const ACL = artifacts.require('@aragon/os/contracts/acl/ACL') const Kernel = artifacts.require('@aragon/os/contracts/kernel/Kernel') - +const DAOFactory = artifacts.require('@aragon/os/contracts/factory/DAOFactory') +const EVMScriptRegistryFactory = artifacts.require('@aragon/os/contracts/factory/EVMScriptRegistryFactory') const MiniMeToken = artifacts.require('@aragon/apps-shared-minime/contracts/MiniMeToken') -const Voting = artifacts.require('VotingMock') - const getContract = name => artifacts.require(name) const bigExp = (x, y) => new web3.BigNumber(x).times(new web3.BigNumber(10).toPower(y)) const pct16 = x => bigExp(x, 16) @@ -19,7 +18,7 @@ const startVoteEvent = receipt => receipt.logs.filter(x => x.event == 'StartVote const createdVoteId = receipt => startVoteEvent(receipt).voteId const ANY_ADDR = '0xffffffffffffffffffffffffffffffffffffffff' -const NULL_ADDRESS = '0x00' +const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' const VOTER_STATE = ['ABSENT', 'YEA', 'NAY'].reduce((state, key, index) => { state[key] = index; @@ -27,7 +26,7 @@ const VOTER_STATE = ['ABSENT', 'YEA', 'NAY'].reduce((state, key, index) => { }, {}) -contract('Voting App', accounts => { +contract('Voting App', ([root, holder1, holder2, holder20, holder29, holder51, nonHolder]) => { let votingBase, daoFact, voting, token, executionTarget let APP_MANAGER_ROLE @@ -35,7 +34,6 @@ contract('Voting App', accounts => { const NOW = 1 const votingDuration = 1000 - const root = accounts[0] before(async () => { const kernelBase = await getContract('Kernel').new(true) // petrify immediately @@ -72,7 +70,7 @@ contract('Voting App', accounts => { const minimumAcceptanceQuorum = pct16(20) beforeEach(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) @@ -80,17 +78,13 @@ contract('Voting App', accounts => { }) it('fails on reinitialization', async () => { - return assertRevert(async () => { - await voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) - }) + await assertRevert(voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration)) }) it('cannot initialize base app', async () => { const newVoting = await Voting.new() assert.isTrue(await newVoting.isPetrified()) - return assertRevert(async () => { - await newVoting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) - }) + await assertRevert(newVoting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration)) }) it('checks it is forwarder', async () => { @@ -106,18 +100,12 @@ contract('Voting App', accounts => { }) it('fails changing required support lower than minimum acceptance quorum', async () => { - return assertRevert(async () => { - await voting.changeSupportRequiredPct(minimumAcceptanceQuorum.minus(1)) - }) + await assertRevert(voting.changeSupportRequiredPct(minimumAcceptanceQuorum.minus(1))) }) it('fails changing required support to 100% or more', async () => { - await assertRevert(async () => { - await voting.changeSupportRequiredPct(pct16(101)) - }) - return assertRevert(async () => { - await voting.changeSupportRequiredPct(pct16(100)) - }) + await assertRevert(voting.changeSupportRequiredPct(pct16(101))) + await assertRevert(voting.changeSupportRequiredPct(pct16(100))) }) it('can change minimum acceptance quorum', async () => { @@ -129,25 +117,18 @@ contract('Voting App', accounts => { }) it('fails changing minimum acceptance quorum to greater than min support', async () => { - return assertRevert(async () => { - await voting.changeMinAcceptQuorumPct(neededSupport.plus(1)) - }) + await assertRevert(voting.changeMinAcceptQuorumPct(neededSupport.plus(1))) }) }) for (const decimals of [0, 2, 18, 26]) { context(`normal token supply, ${decimals} decimals`, () => { - const holder20 = accounts[0] - const holder29 = accounts[1] - const holder51 = accounts[2] - const nonHolder = accounts[4] - const neededSupport = pct16(50) const minimumAcceptanceQuorum = pct16(20) beforeEach(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', decimals, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', decimals, 'n', true) // empty parameters minime await token.generateTokens(holder20, bigExp(20, decimals)) await token.generateTokens(holder29, bigExp(29, decimals)) @@ -187,9 +168,7 @@ contract('Voting App', accounts => { const action = { to: executionTarget.address, calldata: executionTarget.contract.execute.getData() } let script = encodeCallScript([action]) script = script.slice(0, -2) // remove one byte from calldata for it to fail - return assertRevert(async () => { - await voting.newVote(script, '', { from: holder51 }) - }) + await assertRevert(voting.newVote(script, '', { from: holder51 })) }) it('forwarding creates vote', async () => { @@ -229,9 +208,7 @@ contract('Voting App', accounts => { }) it('fails getting a vote out of bounds', async () => { - return assertRevert(async () => { - await voting.getVote(voteId + 1) - }) + await assertRevert(voting.getVote(voteId + 1)) }) it('changing required support does not affect vote required support', async () => { @@ -296,16 +273,12 @@ contract('Voting App', accounts => { }) it('throws when non-holder votes', async () => { - return assertRevert(async () => { - await voting.vote(voteId, true, true, { from: nonHolder }) - }) + await assertRevert(voting.vote(voteId, true, true, { from: nonHolder })) }) it('throws when voting after voting closes', async () => { await voting.mockIncreaseTime(votingDuration + 1) - return assertRevert(async () => { - await voting.vote(voteId, true, true, { from: holder29 }) - }) + await assertRevert(voting.vote(voteId, true, true, { from: holder29 })) }) it('can execute if vote is approved with support and quorum', async () => { @@ -319,18 +292,14 @@ contract('Voting App', accounts => { it('cannot execute vote if not enough quorum met', async () => { await voting.vote(voteId, true, true, { from: holder20 }) await voting.mockIncreaseTime(votingDuration + 1) - return assertRevert(async () => { - await voting.executeVote(voteId) - }) + await assertRevert(voting.executeVote(voteId)) }) it('cannot execute vote if not support met', async () => { await voting.vote(voteId, false, true, { from: holder29 }) await voting.vote(voteId, false, true, { from: holder20 }) await voting.mockIncreaseTime(votingDuration + 1) - return assertRevert(async () => { - await voting.executeVote(voteId) - }) + await assertRevert(voting.executeVote(voteId)) }) it('vote can be executed automatically if decided', async () => { @@ -346,16 +315,12 @@ contract('Voting App', accounts => { it('cannot re-execute vote', async () => { await voting.vote(voteId, true, true, { from: holder51 }) // causes execution - return assertRevert(async () => { - await voting.executeVote(voteId) - }) + await assertRevert(voting.executeVote(voteId)) }) it('cannot vote on executed vote', async () => { await voting.vote(voteId, true, true, { from: holder51 }) // causes execution - return assertRevert(async () => { - await voting.vote(voteId, true, true, { from: holder20 }) - }) + await assertRevert(voting.vote(voteId, true, true, { from: holder20 })) }) }) }) @@ -363,25 +328,19 @@ contract('Voting App', accounts => { context('wrong initializations', () => { beforeEach(async() => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime }) - it('fails if min acceptance quorum is greater than min support', () => { + it('fails if min acceptance quorum is greater than min support', async () => { const neededSupport = pct16(20) const minimumAcceptanceQuorum = pct16(50) - return assertRevert(async() => { - await voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) - }) + await assertRevert(voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration)) }) - it('fails if min support is 100% or more', async() => { + it('fails if min support is 100% or more', async () => { const minimumAcceptanceQuorum = pct16(20) - await assertRevert(async() => { - await voting.initialize(token.address, pct16(101), minimumAcceptanceQuorum, votingDuration) - }) - return assertRevert(async() => { - await voting.initialize(token.address, pct16(100), minimumAcceptanceQuorum, votingDuration) - }) + await assertRevert(voting.initialize(token.address, pct16(101), minimumAcceptanceQuorum, votingDuration)) + await assertRevert(voting.initialize(token.address, pct16(100), minimumAcceptanceQuorum, votingDuration)) }) }) @@ -390,28 +349,24 @@ contract('Voting App', accounts => { const minimumAcceptanceQuorum = pct16(20) beforeEach(async() => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) }) it('fails creating a survey if token has no holder', async () => { - return assertRevert(async () => { - await voting.newVote(EMPTY_SCRIPT, 'metadata') - }) + await assertRevert(voting.newVote(EMPTY_SCRIPT, 'metadata')) }) }) context('token supply = 1', () => { - const holder = accounts[1] - const neededSupport = pct16(50) const minimumAcceptanceQuorum = pct16(20) beforeEach(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime - await token.generateTokens(holder, 1) + await token.generateTokens(holder1, 1) await voting.initialize(token.address, neededSupport, minimumAcceptanceQuorum, votingDuration) }) @@ -422,7 +377,7 @@ contract('Voting App', accounts => { assert.isFalse(await voting.canExecute(voteId), 'vote cannot be executed') - await voting.vote(voteId, true, true, { from: holder }) + await voting.vote(voteId, true, true, { from: holder1 }) const [isOpen, isExecuted] = await voting.getVote(voteId) @@ -433,7 +388,7 @@ contract('Voting App', accounts => { context('new vote parameters', () => { it('creating vote as holder executes vote (if _canExecute param says so)', async () => { - const voteId = createdVoteId(await voting.newVoteExt(EMPTY_SCRIPT, 'metadata', true, true, { from: holder })) + const voteId = createdVoteId(await voting.newVoteExt(EMPTY_SCRIPT, 'metadata', true, true, { from: holder1 })) const [isOpen, isExecuted] = await voting.getVote(voteId) assert.isFalse(isOpen, 'vote should be closed') @@ -441,7 +396,7 @@ contract('Voting App', accounts => { }) it("creating vote as holder doesn't execute vote if _canExecute param doesn't says so", async () => { - const voteId = createdVoteId(await voting.newVoteExt(EMPTY_SCRIPT, 'metadata', true, false, { from: holder })) + const voteId = createdVoteId(await voting.newVoteExt(EMPTY_SCRIPT, 'metadata', true, false, { from: holder1 })) const [isOpen, isExecuted] = await voting.getVote(voteId) assert.isTrue(isOpen, 'vote should be open') @@ -451,14 +406,11 @@ contract('Voting App', accounts => { }) context('token supply = 3', () => { - const holder1 = accounts[1] - const holder2 = accounts[2] - const neededSupport = pct16(34) const minimumAcceptanceQuorum = pct16(20) beforeEach(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await token.generateTokens(holder1, 1) await token.generateTokens(holder2, 2) @@ -490,14 +442,11 @@ contract('Voting App', accounts => { }) context('changing token supply', () => { - const holder1 = accounts[1] - const holder2 = accounts[2] - const neededSupport = pct16(50) const minimumAcceptanceQuorum = pct16(20) beforeEach(async () => { - token = await MiniMeToken.new(NULL_ADDRESS, NULL_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime + token = await MiniMeToken.new(ZERO_ADDRESS, ZERO_ADDRESS, 0, 'n', 0, 'n', true) // empty parameters minime await token.generateTokens(holder1, 1) await token.generateTokens(holder2, 1) @@ -534,9 +483,7 @@ contract('Voting App', accounts => { context('before init', () => { it('fails creating a vote before initialization', async () => { - return assertRevert(async () => { - await voting.newVote(encodeCallScript([]), '') - }) + await assertRevert(voting.newVote(encodeCallScript([]), '')) }) }) diff --git a/shared/minime/test/minime.js b/shared/minime/test/minime.js index 27d1fc7f9f..6374d0ff2b 100644 --- a/shared/minime/test/minime.js +++ b/shared/minime/test/minime.js @@ -38,9 +38,7 @@ contract('MiniMeToken', accounts => { assert.equal(await token.totalSupplyAt(block - 1), 100, 'total supply should be 100 in previous block') assert.equal(await token.balanceOf(accounts[1]), 80, 'should have destroyed 20 tokens from orignal amount') - return assertRevert(async () => { - await token.destroyTokens(accounts[2], 100) - }) + await assertRevert(token.destroyTokens(accounts[2], 100)) }) }) @@ -77,16 +75,12 @@ contract('MiniMeToken', accounts => { it('claim tokens', async () => { assert.ok(await token.claimTokens(0x0)) assert.ok(await token.claimTokens(token.address)) - return assertRevert(async () => { - await token.transfer(token.address, 5) - }) + await assertRevert(token.transfer(token.address, 5)) }) it('disable transfers', async () => { await token.enableTransfers(false) - return assertRevert(async () => { - await token.transfer(accounts[3], 5) - }) + await assertRevert(token.transfer(accounts[3], 5)) }) it('re-enable transfers', async () => { @@ -104,9 +98,7 @@ contract('MiniMeToken', accounts => { it('refuse new allowances if transfer are disabled', async () => { await token.enableTransfers(false) - return assertRevert(async () => { - await token.approve(accounts[2], 10) - }) + await assertRevert(token.approve(accounts[2], 10)) }) })