From 1798ee2db6f3735036bd42fbb49b525f4a4fd953 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 5 Nov 2020 10:33:52 +0100 Subject: [PATCH 1/3] manage array of event --- libs/remix-tests/src/testRunner.ts | 57 ++++++++++++++++-------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index 1f08a25d183..a0d3a87617f 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -286,35 +286,38 @@ export function runTest (testName: string, testObject: any, contractDetails: Com const assertionEventHashes = assertionEvents.map(e => Web3.utils.sha3(e.name + '(' + e.params.join() + ')') ) let testPassed = false for (const i in receipt.events) { - const event = receipt.events[i] - const eIndex = assertionEventHashes.indexOf(event.raw.topics[0]) // event name topic will always be at index 0 - if (eIndex >= 0) { - const testEvent = web3.eth.abi.decodeParameters(assertionEvents[eIndex].params, event.raw.data) - if (!testEvent[0]) { - const assertMethod = testEvent[2] - if(assertMethod === 'ok') { // for 'Assert.ok' method - testEvent[3] = 'false' - testEvent[4] = 'true' + let events = receipt.events[i] + if (!Array.isArray(events)) events = [events] + for (const event of events) { + const eIndex = assertionEventHashes.indexOf(event.raw.topics[0]) // event name topic will always be at index 0 + if (eIndex >= 0) { + const testEvent = web3.eth.abi.decodeParameters(assertionEvents[eIndex].params, event.raw.data) + if (!testEvent[0]) { + const assertMethod = testEvent[2] + if(assertMethod === 'ok') { // for 'Assert.ok' method + testEvent[3] = 'false' + testEvent[4] = 'true' + } + const location = getAssertMethodLocation(fileAST, testName, func.name, assertMethod) + const resp: TestResultInterface = { + type: 'testFailure', + value: changeCase.sentenceCase(func.name), + filename: testObject.filename, + time: time, + errMsg: testEvent[1], + context: testName, + assertMethod, + returned: testEvent[3], + expected: testEvent[4], + location + }; + testCallback(undefined, resp) + failureNum += 1 + timePassed += time + return next() } - const location = getAssertMethodLocation(fileAST, testName, func.name, assertMethod) - const resp: TestResultInterface = { - type: 'testFailure', - value: changeCase.sentenceCase(func.name), - filename: testObject.filename, - time: time, - errMsg: testEvent[1], - context: testName, - assertMethod, - returned: testEvent[3], - expected: testEvent[4], - location - }; - testCallback(undefined, resp) - failureNum += 1 - timePassed += time - return next() + testPassed = true } - testPassed = true } } From 2cfa31f757e122f81ca04c6de31d5bb688b3cadc Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 5 Nov 2020 16:48:15 +0530 Subject: [PATCH 2/3] added multiple events to test --- libs/remix-tests/tests/examples_1/simple_storage.sol | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/remix-tests/tests/examples_1/simple_storage.sol b/libs/remix-tests/tests/examples_1/simple_storage.sol index cbef58230b1..c218711d60a 100644 --- a/libs/remix-tests/tests/examples_1/simple_storage.sol +++ b/libs/remix-tests/tests/examples_1/simple_storage.sol @@ -2,12 +2,16 @@ pragma solidity >= 0.5.0 < 0.8.0; contract SimpleStorage { uint public storedData; + event Stored(uint256 value); + constructor() public { storedData = 100; } function set(uint x) public { storedData = x; + emit Stored(x); + emit Stored(x+10); // for testing multiple events only } function get() public view returns (uint retVal) { From 811586deb214d732560d79bec2242c34b7e9b14c Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 5 Nov 2020 18:24:24 +0100 Subject: [PATCH 3/3] standard --- libs/remix-tests/src/testRunner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-tests/src/testRunner.ts b/libs/remix-tests/src/testRunner.ts index a0d3a87617f..965d57758b0 100644 --- a/libs/remix-tests/src/testRunner.ts +++ b/libs/remix-tests/src/testRunner.ts @@ -294,7 +294,7 @@ export function runTest (testName: string, testObject: any, contractDetails: Com const testEvent = web3.eth.abi.decodeParameters(assertionEvents[eIndex].params, event.raw.data) if (!testEvent[0]) { const assertMethod = testEvent[2] - if(assertMethod === 'ok') { // for 'Assert.ok' method + if (assertMethod === 'ok') { // for 'Assert.ok' method testEvent[3] = 'false' testEvent[4] = 'true' }