Fix 'testSignature' browser tests under nightwatch_local

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.<anonymous> (/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.
pull/3094/head
Scott Tsai 6 years ago
parent e95204195c
commit 7f11882df1
  1. 2
      src/app/tabs/runTab/settings.js
  2. 2
      test-browser/helpers/contracts.js
  3. 8
      test-browser/tests/compiling.js
  4. 36
      test-browser/tests/generalTests.js

@ -97,7 +97,7 @@ class SettingsUI {
<div class=${css.account}> <div class=${css.account}>
<select name="txorigin" class="form-control ${css.select}" id="txorigin"></select> <select name="txorigin" class="form-control ${css.select}" id="txorigin"></select>
${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)} ${copyToClipboard(() => document.querySelector('#runTabView #txorigin').value)}
<i id="remixRunSignMsg" class="fas fa-edit ${css.icon}" aria-hiden="true" onclick=${this.signMessage.bind(this)} title="Sign a message using this account key"></i> <i id="remixRunSignMsg" class="fas fa-edit ${css.icon}" aria-hidden="true" onclick=${this.signMessage.bind(this)} title="Sign a message using this account key"></i>
</div> </div>
</div> </div>
` `

@ -172,7 +172,9 @@ function scrollInto (target) {
function signMsg (browser, msg, cb) { function signMsg (browser, msg, cb) {
let hash, signature let hash, signature
browser browser
.waitForElementPresent('i[id="remixRunSignMsg"]')
.click('i[id="remixRunSignMsg"]') .click('i[id="remixRunSignMsg"]')
.waitForElementPresent('textarea[id="prompt_text"]')
.setValue('textarea[id="prompt_text"]', msg, () => { .setValue('textarea[id="prompt_text"]', msg, () => {
browser.modalFooterOKClick().perform( browser.modalFooterOKClick().perform(
(client, done) => { (client, done) => {

@ -160,8 +160,8 @@ function testInputValues (browser, callback) {
var sources = [ var sources = [
{'browser/Untitled.sol': {content: ` {'browser/Untitled.sol': {content: `
contract TestContract { function f() public returns (uint) { return 8; } contract TestContract { function f() public returns (uint) { return 8; }
function g() public returns (uint, string memory, bool, uint) { function g() public returns (uint, string memory, bool, uint) {
uint payment = 345; uint payment = 345;
bool payed = true; bool payed = true;
string memory comment = "comment_comment_"; string memory comment = "comment_comment_";
@ -176,7 +176,7 @@ var sources = [
_i = -345; _i = -345;
_a = msg.sender; _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) { 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; _b = 0x12;
_b2 = 0x1223; _b2 = 0x1223;
@ -188,7 +188,7 @@ var sources = [
_blit = hex"123498"; _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"; _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) { function retunValues3 () public returns (ActionChoices _en, int[5][] memory _a1) {
_en = ActionChoices.GoStraight; _en = ActionChoices.GoStraight;
int[5][] memory a = new int[5][](3); int[5][] memory a = new int[5][](3);

@ -34,7 +34,7 @@ function runTests (browser) {
async.waterfall([function (callback) { callback(null, browser) }, async.waterfall([function (callback) { callback(null, browser) },
testSimpleContract, testSimpleContract,
testSuccessImport, testSuccessImport,
testFailedImport, /* testGitHubImport */ testFailedImport, /* testGitHubImport, */
addDeployLibTestFile, addDeployLibTestFile,
testAutoDeployLib, testAutoDeployLib,
testManualDeployLib, testManualDeployLib,
@ -168,22 +168,28 @@ function testSignature (browser, callback) {
contractHelper.signMsg(browser, 'test message', (h, s) => { contractHelper.signMsg(browser, 'test message', (h, s) => {
hash = h hash = h
signature = s 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.addFile(browser, 'signMassage.sol', sources[6]['browser/signMassage.sol'], () => {
contractHelper.switchFile(browser, 'browser/signMassage.sol', () => { contractHelper.switchFile(browser, 'browser/signMassage.sol', () => {
contractHelper.selectContract(browser, 'ECVerify', () => { // deploy lib contractHelper.selectContract(browser, 'ECVerify', () => { // deploy lib
contractHelper.createContract(browser, '', () => { contractHelper.createContract(browser, '', () => {
browser.waitForElementPresent('.instance:nth-of-type(4)') const instanceSelector = '.instance:nth-of-type(4)'
.click('.instance:nth-of-type(4) > div > button') browser.waitForElementPresent(instanceSelector)
.clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`}).perform( .click(instanceSelector + ' > div > button')
() => { .getAttribute(instanceSelector, 'id', (result) => {
contractHelper.verifyCallReturnValue( // skip 'instance' part of e.g. 'instance0x692a70d2e424a56d2c6c27aa97d1a86395877b3a'
browser, const address = result.value.slice('instance'.length)
'0x08970fed061e7747cd9a38d680a601510cb659fb', browser.clickFunction('ecrecovery - call', {types: 'bytes32 hash, bytes sig', values: `"${hash.value}","${signature.value}"`}).perform(
['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'], () => {
() => { callback(null, browser) } contractHelper.verifyCallReturnValue(
) browser,
} address,
) ['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'],
() => { callback(null, browser) }
)
})
})
}) })
}) })
}) })
@ -347,13 +353,13 @@ var sources = [
'browser/Untitled5.sol': {content: `library lib { 'browser/Untitled5.sol': {content: `library lib {
function getInt () public view returns (uint) { function getInt () public view returns (uint) {
return 45; return 45;
} }
} }
contract test { contract test {
function get () public view returns (uint) { function get () public view returns (uint) {
return lib.getInt(); return lib.getInt();
} }
}`} }`}
}, },
{ {

Loading…
Cancel
Save