From 21955da00dc667b2f875702cd2d82022ecef697f Mon Sep 17 00:00:00 2001 From: Jorge Izquierdo Date: Fri, 16 Nov 2018 19:33:27 +0100 Subject: [PATCH] Actor app: improve tests --- future-apps/actor/contracts/Actor.sol | 1 + future-apps/actor/package.json | 1 + future-apps/actor/test/actor.js | 14 +++++++------- shared/test-helpers/assertEvent.js | 5 +++++ 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 shared/test-helpers/assertEvent.js diff --git a/future-apps/actor/contracts/Actor.sol b/future-apps/actor/contracts/Actor.sol index a7a93771dc..83dd45dfb6 100644 --- a/future-apps/actor/contracts/Actor.sol +++ b/future-apps/actor/contracts/Actor.sol @@ -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) { diff --git a/future-apps/actor/package.json b/future-apps/actor/package.json index f01129e87d..4dbfccc73f 100644 --- a/future-apps/actor/package.json +++ b/future-apps/actor/package.json @@ -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": { diff --git a/future-apps/actor/test/actor.js b/future-apps/actor/test/actor.js index b4361aaf0c..b876ef3334 100644 --- a/future-apps/actor/test/actor.js +++ b/future-apps/actor/test/actor.js @@ -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') @@ -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 () => { @@ -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 () => { @@ -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 () => { diff --git a/shared/test-helpers/assertEvent.js b/shared/test-helpers/assertEvent.js new file mode 100644 index 0000000000..471c1bf195 --- /dev/null +++ b/shared/test-helpers/assertEvent.js @@ -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 +}