From a11a6318d738696b700a7d57eec6ebaf6f0eb27c Mon Sep 17 00:00:00 2001 From: filip mertens Date: Sat, 3 Sep 2022 18:50:25 +0200 Subject: [PATCH] CheckVariableDebug --- .../src/commands/checkVariableDebug.ts | 51 +++++++++++-------- apps/remix-ide-e2e/src/tests/debugger.test.ts | 38 +++++--------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/checkVariableDebug.ts b/apps/remix-ide-e2e/src/commands/checkVariableDebug.ts index 41a45ea702..843e1d4571 100644 --- a/apps/remix-ide-e2e/src/commands/checkVariableDebug.ts +++ b/apps/remix-ide-e2e/src/commands/checkVariableDebug.ts @@ -4,7 +4,7 @@ import EventEmitter from 'events' const deepequal = require('deep-equal') class CheckVariableDebug extends EventEmitter { - command (this: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue): NightwatchBrowser { + command(this: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue): NightwatchBrowser { this.api.perform((done) => { checkDebug(this.api, id, debugValue, () => { done() @@ -15,27 +15,38 @@ class CheckVariableDebug extends EventEmitter { } } -function checkDebug (browser: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue, done: VoidFunction) { +function checkDebug(browser: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue, done: VoidFunction) { // id is soliditylocals or soliditystate - browser.execute(function (id: string) { - const elem = document.querySelector('#' + id + ' .dropdownrawcontent') as HTMLElement - - return elem.innerText - }, [id], function (result) { - let value - try { - value = JSON.parse(result.value) - } catch (e) { - browser.assert.fail('cant parse solidity state', e.message, '') + let resultOfElement = null + let isEqual = false + browser.waitUntil(() => { + browser.execute(function (id: string) { + const elem = document.querySelector('#' + id + ' .dropdownrawcontent') as HTMLElement + if (elem && elem.innerText) { + console.log(elem.innerText) + return elem.innerText + } + }, [id], (result) => { + if (result.value) { + console.log(JSON.parse(result.value)) + try { + resultOfElement = JSON.parse(result.value) + isEqual = deepequal(debugValue, resultOfElement) + } catch (e) { + browser.assert.fail('cant parse solidity state', e.message, '') + console.log(e) + } + } + }) + if (isEqual) return true + return false + }, 10000, 1000) + .perform(() => { + if (!isEqual) { + browser.assert.fail(JSON.stringify(resultOfElement), 'info about error\n ' + JSON.stringify(debugValue) + '\n ' + JSON.stringify(resultOfElement), '') + } done() - return - } - const equal = deepequal(debugValue, value) - if (!equal) { - browser.assert.fail(JSON.stringify(value), 'info about error\n ' + JSON.stringify(debugValue) + '\n ' + JSON.stringify(value), '') - } - done() - }) + }) } module.exports = CheckVariableDebug diff --git a/apps/remix-ide-e2e/src/tests/debugger.test.ts b/apps/remix-ide-e2e/src/tests/debugger.test.ts index 3c0ee800df..c3bdf2c4c8 100644 --- a/apps/remix-ide-e2e/src/tests/debugger.test.ts +++ b/apps/remix-ide-e2e/src/tests/debugger.test.ts @@ -62,10 +62,10 @@ module.exports = { browser.waitForElementVisible('#editorView') .execute(() => { (window as any).addRemixBreakpoint(11) - }, [], () => {}) + }, [], () => { }) .execute(() => { (window as any).addRemixBreakpoint(21) - }, [], () => {}) + }, [], () => { }) .waitForElementVisible('*[data-id="buttonNavigatorJumpPreviousBreakpoint"]') .click('*[data-id="buttonNavigatorJumpPreviousBreakpoint"]') .pause(2000) @@ -103,7 +103,7 @@ module.exports = { _name = name_; _symbol = symbol_; }`) !== -1, - 'current displayed content is not from the ERC20 source code') + 'current displayed content is not from the ERC20 source code') }) }, @@ -133,31 +133,19 @@ module.exports = { selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"133")]', }) .goToVMTraceStep(261) - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"261")]', - }) .waitForElementPresent('.highlightLine8') - /* - for the test below: - source highlight should remain line `bytes32 idAsk = abi.decode(userData[:33], (bytes32));` - At this vmtrace index, the sourcemap has file = -1 because the execution is in the generated sources (ABIEncoderV2) - the atIndex of SourceLocationTracker was buggy and return an incorrect value, this is fixed - But the debugger uses now validSourcelocation, which means file is not -1. - In that case the source highlight at 261 should be the same as for step 262 - */ - + /* + for the test below: + source highlight should remain line `bytes32 idAsk = abi.decode(userData[:33], (bytes32));` + At this vmtrace index, the sourcemap has file = -1 because the execution is in the generated sources (ABIEncoderV2) + the atIndex of SourceLocationTracker was buggy and return an incorrect value, this is fixed + But the debugger uses now validSourcelocation, which means file is not -1. + In that case the source highlight at 261 should be the same as for step 262 + */ + .goToVMTraceStep(266) - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"266")]', - }) .checkVariableDebug('soliditylocals', localVariable_step266_ABIEncoder) // locals should not be initiated at this point, only idAsk should .goToVMTraceStep(717) - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: '//*[@data-id="treeViewLivm trace step" and contains(.,"717")]', - }) .checkVariableDebug('soliditylocals', localVariable_step717_ABIEncoder) // all locals should be initiaed .clearTransactions() }, @@ -248,7 +236,7 @@ module.exports = { .waitForElementVisible('*[data-id="solidityLocals"]', 60000) .pause(10000) .checkVariableDebug('soliditylocals', { num: { value: '2', type: 'uint256' } }) - .checkVariableDebug('soliditystate', { number: { value: '0', type: 'uint256', constant: false, immutable: false } }) + .checkVariableDebug('soliditystate', { number: { value: '0', type: 'uint256', constant: false, immutable: false } }) }, 'Should debug reverted transactions #group5': function (browser: NightwatchBrowser) {