Skip to content

Commit

Permalink
Fix 'ballot', 'compiling' and 'testSignature' browser tests under nig…
Browse files Browse the repository at this point in the history
…htwatch_local

Running `npm rpn nightwatch_local`, a few tests would consistently fail
due to the "Account" dropdown in the Run Tab (i.e. 'select#txorigin') being
filled-in asynchronously and the tests were running without a valid
account value.  E.g. contract deployment would fail with:
"creation of Ballot errored: Invalid account selected"

This patch fixes it by adding a, admittedly weird looking,
`waitForValue()` function which checks the `value` attribute
for some DOM element is present.

Browsing the nightwatch API, I expected:
`browser.expect.element(selector).value` to provide equivalent
functionality but empirically I couldn't get that to work.

Tested with:
```
nightwatch 0.9.21
selenium-server-standalone 3.141.5
ChromeDriver 2.43.600233
Chrome 74.0.3729.169
```

Error message on test failure:
```
 - Ballot (13.92s)
   Timed out while waiting for element <.instance:nth-of-type(2)> to be present for 10000 milliseconds.  - expected "found" but got: "not found"
       at runTests (/home/scottt/work/remix-0.8/remix-ide/test-browser/tests/ballot.js:40:8)
       at Object.Ballot (/home/scottt/work/remix-0.8/remix-ide/test-browser/tests/ballot.js:19:5)

 ✖ compiling
   - Compiling (13.389s)
   Timed out while waiting for element <.instance:nth-of-type(2)> to be present for 10000 milliseconds.  - expected "found" but got: "not found"
       at /home/scottt/work/remix-0.8/remix-ide/test-browser/tests/compiling.js:43:8
       at getCompiledContracts (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:84:5)
       at Object.<anonymous> (/home/scottt/work/remix-0.8/remix-ide/test-browser/helpers/contracts.js:50:5)
 ✖ 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)
```
  • Loading branch information
scottt committed May 27, 2019
1 parent de4dfad commit c8b84c2
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/app/tabs/runTab/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SettingsUI {
<div class=${css.account}>
<select name="txorigin" class="form-control ${css.select}" id="txorigin"></select>
${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>
`
Expand Down
30 changes: 29 additions & 1 deletion test-browser/helpers/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ module.exports = {
getAddressAtPosition,
clickLaunchIcon,
scrollInto,
signMsg
signMsg,
waitForValue
}

function clickLaunchIcon (icon) {
Expand Down Expand Up @@ -172,7 +173,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) => {
Expand Down Expand Up @@ -467,3 +470,28 @@ function goToVMtraceStep (browser, step, done, incr) {
}
})
}

function waitForValue (selector, retryCount) {
function performFunc (browser, done) {
browser.getValue(selector, function (result) {
const value = result.value
console.log('waitForValue: value:', value)
if (value) {
done()
} else {
if (retryCount === 0) {
done()
} else {
retryCount--
browser.pause(500).perform(function (browser, done2) {
performFunc(browser, function () {
done2()
done()
})
})
}
}
})
}
return performFunc
}
3 changes: 2 additions & 1 deletion test-browser/tests/ballot.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ function runTests (browser, testData) {
})
}).clickLaunchIcon('run')
.setValue('input[placeholder="uint8 _numProposals"]', '1')
.click('#runTabView button[class^="instanceButton"]')
.perform(contractHelper.waitForValue('#txorigin', 10)) // browser.expect.element('#txorigin').value somehow doesn't work
.click('#runTabView button[class^="instanceButton"]') // "creation of Ballot errored: Invalid account selected"
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
.testFunction('delegate - transact (not payable)', '0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e',
Expand Down
11 changes: 7 additions & 4 deletions test-browser/tests/compiling.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function runTests (browser) {
function testSimpleContract (browser, callback) {
contractHelper.testContracts(browser, 'Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract'], function () {
browser.clickLaunchIcon('run')
.perform(contractHelper.waitForValue('#txorigin', 10))
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
Expand Down Expand Up @@ -70,6 +71,7 @@ function testSimpleContract (browser, callback) {
function testReturnValues (browser, callback) {
contractHelper.testContracts(browser, 'returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues'], function () {
browser.clickLaunchIcon('run')
.perform(contractHelper.waitForValue('#txorigin', 10))
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
Expand Down Expand Up @@ -108,6 +110,7 @@ function testReturnValues (browser, callback) {
function testInputValues (browser, callback) {
contractHelper.testContracts(browser, 'inputValues.sol', sources[2]['browser/inputValues.sol'], ['test'], function () {
browser.clickLaunchIcon('run')
.perform(contractHelper.waitForValue('#txorigin', 10))
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
Expand Down Expand Up @@ -160,8 +163,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_";
Expand All @@ -176,7 +179,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;
Expand All @@ -188,7 +191,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);
Expand Down
40 changes: 24 additions & 16 deletions test-browser/tests/generalTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function runTests (browser) {
async.waterfall([function (callback) { callback(null, browser) },
testSimpleContract,
testSuccessImport,
testFailedImport, /* testGitHubImport */
testFailedImport, /* testGitHubImport, */
addDeployLibTestFile,
testAutoDeployLib,
testManualDeployLib,
Expand Down Expand Up @@ -164,26 +164,34 @@ function checkDeployShouldSucceed (browser, address, callback) {

function testSignature (browser, callback) {
let hash, signature
browser.perform((client, done) => {
browser
.perform(contractHelper.waitForValue('#txorigin', 10)) // ensure createContract uses the right account
.perform((client, done) => {
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) }
)
})
})
})
})
})
Expand Down Expand Up @@ -347,13 +355,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();
}
}
}`}
},
{
Expand Down

0 comments on commit c8b84c2

Please sign in to comment.