Skip to content

Commit

Permalink
Actor app: improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izqui committed Nov 16, 2018
1 parent 7a4dd5b commit 21955da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions future-apps/actor/contracts/Actor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ contract Actor is Vault, IForwarder {
bytes memory input = ""; // no input
address[] memory blacklist = new address[](0); // no addr blacklist, can interact with anything
runScript(_evmScript, input, blacklist);
// We don't need to emit an event here as EVMScriptRunner will emit ScriptResult if successful
}

function canForward(address sender, bytes evmScript) public view returns (bool) {
Expand Down
1 change: 1 addition & 0 deletions future-apps/actor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"solium": "^1.0.4",
"truffle": "4.1.14",
"truffle-hdwallet-provider": "0.0.3",
"web3-eth-abi": "^1.0.0-beta.36",
"webpack": "3.10.0"
},
"dependencies": {
Expand Down
14 changes: 7 additions & 7 deletions future-apps/actor/test/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const { hash } = require('eth-ens-namehash')
const getBalance = require('@aragon/test-helpers/balance')(web3)
const web3Call = require('@aragon/test-helpers/call')(web3)
const { encodeCallScript, EMPTY_SCRIPT } = require('@aragon/test-helpers/evmScript')
const assertEvent = require('@aragon/test-helpers/assertEvent')
const ethABI = require('web3-eth-abi')
const getEvent = (receipt, event, arg) => { return receipt.logs.filter(l => l.event == event)[0].args[arg] }

const ACL = artifacts.require('ACL')
Expand Down Expand Up @@ -84,10 +86,10 @@ contract('Actor app', (accounts) => {
assert.equal(await executionTarget.counter(), 0)

const { to, data } = encodeFunctionCall(executionTarget, 'setCounter', N)
await actor.execute(to, 0, data, { from: executor })
const receipt = await actor.execute(to, 0, data, { from: executor })

// TODO: assert Execute event
assert.equal(await executionTarget.counter(), N)
assertEvent(receipt, 'Execute')
})

it('fails to execute without permissions', async () => {
Expand Down Expand Up @@ -121,10 +123,7 @@ contract('Actor app', (accounts) => {
const call = encodeFunctionCall(actor, 'execute', to, 0, data, { from: executor })
const returnData = await web3Call(call)

const N = 1

// TODO: Add decoding for the return data
assert.equal(returnData, `0x000000000000000000000000000000000000000000000000000000000000000${N}`)
assert.equal(ethABI.decodeParameter('uint256', returnData), 1)
})

it('it reverts if executed action reverts', async () => {
Expand Down Expand Up @@ -193,9 +192,10 @@ contract('Actor app', (accounts) => {
assert.isTrue(await actor.canForward(scriptRunner, script))
assert.equal(await executionTarget.counter(), 0)

await actor.forward(script, { from: scriptRunner })
const receipt = await actor.forward(script, { from: scriptRunner })

assert.equal(await executionTarget.counter(), 2)
assertEvent(receipt, 'ScriptResult')
})

it('fails to run script without permissions', async () => {
Expand Down
5 changes: 5 additions & 0 deletions shared/test-helpers/assertEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (receipt, eventName, instances = 1) => {
const events = receipt.logs.filter(x => x.event == eventName)
assert.equal(events.length, instances, `'${eventName}' event should have been fired ${instances} times`)
return events
}

0 comments on commit 21955da

Please sign in to comment.