Skip to content

Commit

Permalink
shared: test files enhacements
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Apr 12, 2019
1 parent 1a9cdf7 commit a9f6112
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 474 deletions.
54 changes: 17 additions & 37 deletions apps/agent/test/agent.js
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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 () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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 }))
})
})
})
Expand Down Expand Up @@ -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)
})
})
Expand Down Expand Up @@ -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))
})

Expand Down
Loading

0 comments on commit a9f6112

Please sign in to comment.