From d0ddd202bcf6741c503f1766ee5b6ffb37a3af74 Mon Sep 17 00:00:00 2001 From: Scott Tsai Date: Sat, 25 May 2019 19:37:37 +0800 Subject: [PATCH] Fix 'testSignature' browser tests under nightwatch_local MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `testSignature()` browser test in `generalTests.js` would occasionally fail due to not obtaining the correct `hash` and `signature` values from the browser, resulting in: ``` ✖ generalTests - Simple Contract (40.954s) Failed [equal]: ('' == '0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') - expected "0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c" but got: "" at Object. (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:129:22) ``` failures. This patch fixes it by waiting for the DOM elements with `waitForElementPresent` which implicitly retries and obtaining the correct contract instance address instead of hard coding it. --- src/app/tabs/runTab/settings.js | 2 +- test-browser/helpers/contracts.js | 2 ++ test-browser/tests/compiling.js | 8 +++---- test-browser/tests/generalTests.js | 36 +++++++++++++++++------------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/app/tabs/runTab/settings.js b/src/app/tabs/runTab/settings.js index ba704e42d7..9263ca52a5 100644 --- a/src/app/tabs/runTab/settings.js +++ b/src/app/tabs/runTab/settings.js @@ -97,7 +97,7 @@ class SettingsUI {
${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)} - +
` diff --git a/test-browser/helpers/contracts.js b/test-browser/helpers/contracts.js index 949afb0217..758a17923a 100644 --- a/test-browser/helpers/contracts.js +++ b/test-browser/helpers/contracts.js @@ -172,7 +172,9 @@ function scrollInto (target) { function signMsg (browser, msg, cb) { let hash, signature browser + .waitForElementPresent('i[id="remixRunSignMsg"]') .click('i[id="remixRunSignMsg"]') + .waitForElementPresent('textarea[id="prompt_text"]') .setValue('textarea[id="prompt_text"]', msg, () => { browser.modalFooterOKClick().perform( (client, done) => { diff --git a/test-browser/tests/compiling.js b/test-browser/tests/compiling.js index e7c4e94347..c28dcfb66c 100644 --- a/test-browser/tests/compiling.js +++ b/test-browser/tests/compiling.js @@ -160,8 +160,8 @@ function testInputValues (browser, callback) { var sources = [ {'browser/Untitled.sol': {content: ` - contract TestContract { function f() public returns (uint) { return 8; } - function g() public returns (uint, string memory, bool, uint) { + contract TestContract { function f() public returns (uint) { return 8; } + function g() public returns (uint, string memory, bool, uint) { uint payment = 345; bool payed = true; string memory comment = "comment_comment_"; @@ -176,7 +176,7 @@ var sources = [ _i = -345; _a = msg.sender; } - + function retunValues2 () public returns (byte _b, bytes2 _b2, bytes3 _b3, bytes memory _blit, bytes5 _b5, bytes6 _b6, string memory _str, bytes7 _b7, bytes22 _b22, bytes32 _b32) { _b = 0x12; _b2 = 0x1223; @@ -188,7 +188,7 @@ var sources = [ _blit = hex"123498"; _str = "this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string _ this is a long string"; } - + function retunValues3 () public returns (ActionChoices _en, int[5][] memory _a1) { _en = ActionChoices.GoStraight; int[5][] memory a = new int[5][](3); diff --git a/test-browser/tests/generalTests.js b/test-browser/tests/generalTests.js index af41be8f5f..046982e368 100644 --- a/test-browser/tests/generalTests.js +++ b/test-browser/tests/generalTests.js @@ -34,7 +34,7 @@ function runTests (browser) { async.waterfall([function (callback) { callback(null, browser) }, testSimpleContract, testSuccessImport, - testFailedImport, /* testGitHubImport */ + testFailedImport, /* testGitHubImport, */ addDeployLibTestFile, testAutoDeployLib, testManualDeployLib, @@ -168,22 +168,28 @@ function testSignature (browser, callback) { contractHelper.signMsg(browser, 'test message', (h, s) => { hash = h signature = s + browser.assert.ok(typeof hash.value === 'string', 'type of hash.value must be String') + browser.assert.ok(typeof signature.value === 'string', 'type of signature.value must be String') contractHelper.addFile(browser, 'signMassage.sol', sources[6]['browser/signMassage.sol'], () => { contractHelper.switchFile(browser, 'browser/signMassage.sol', () => { contractHelper.selectContract(browser, 'ECVerify', () => { // deploy lib contractHelper.createContract(browser, '', () => { - browser.waitForElementPresent('.instance:nth-of-type(4)') - .click('.instance:nth-of-type(4) > div > button') - .clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`}).perform( - () => { - contractHelper.verifyCallReturnValue( - browser, - '0x08970fed061e7747cd9a38d680a601510cb659fb', - ['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'], - () => { callback(null, browser) } - ) - } - ) + const instanceSelector = '.instance:nth-of-type(4)' + browser.waitForElementPresent(instanceSelector) + .click(instanceSelector + ' > div > button') + .getAttribute(instanceSelector, 'id', (result) => { + // skip 'instance' part of e.g. 'instance0x692a70d2e424a56d2c6c27aa97d1a86395877b3a' + const address = result.value.slice('instance'.length) + browser.clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`}).perform( + () => { + contractHelper.verifyCallReturnValue( + browser, + address, + ['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'], + () => { callback(null, browser) } + ) + }) + }) }) }) }) @@ -347,13 +353,13 @@ var sources = [ 'browser/Untitled5.sol': {content: `library lib { function getInt () public view returns (uint) { return 45; - } + } } contract test { function get () public view returns (uint) { return lib.getInt(); - } + } }`} }, {