Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle array of events #557

Merged
merged 3 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 deletions libs/remix-tests/src/testRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
4 changes: 4 additions & 0 deletions libs/remix-tests/tests/examples_1/simple_storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down