From e96bd6b5b1101f1bffff2b50316ea82ca0d2a7a2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:03:51 +0200 Subject: [PATCH 1/6] refactor ballot --- test-browser/tests/ballot.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index 0e3b17ea4e..18c652bb76 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -14,14 +14,8 @@ module.exports = { '@sources': function () { return sources }, - 'Ballot': function (browser) { - runTests(browser) - }, - tearDown: sauce -} - -function runTests (browser, testData) { - browser + 'Deploy Ballot': function (browser) { + browser .waitForElementVisible('#icon-panel', 10000) .clickLaunchIcon('solidity') .testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['Ballot']) @@ -33,7 +27,10 @@ function runTests (browser, testData) { .testFunction('delegate - transact (not payable)', '0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e', `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0x057...3ce2e`, {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) - .pause(500) + }, + + 'Debug Ballot / delegate': function (browser) { + browser.pause(500) .click('span#tx0x0571a2439ea58bd349dd130afb8aff62a33af14c06de0dbc3928519bdf13ce2e button[class^="debug"]') .pause(2000) .clickLaunchIcon('debugger') @@ -43,7 +40,10 @@ function runTests (browser, testData) { .pause(1000) .checkVariableDebug('soliditystate', stateCheck) .checkVariableDebug('soliditylocals', localsCheck) - .clickLaunchIcon('run') + }, + + 'Access Ballot via at address': function (browser) { + browser.clickLaunchIcon('run') .click('button[class^="udappClose"]') .addFile('ballot.abi', { content: ballotABI }) .addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3B', true, false) @@ -56,6 +56,8 @@ function runTests (browser, testData) { `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0xd3c...df10f`, {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) .end() + }, + tearDown: sauce } var localsCheck = { From a3fcd865381b41cd33d43791646e6823f916e498 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:09:02 +0200 Subject: [PATCH 2/6] refactor browser tests --- test-browser/tests/compiling.js | 47 ++++++++++-------------- test-browser/tests/units/testRecorder.js | 2 +- 2 files changed, 20 insertions(+), 29 deletions(-) diff --git a/test-browser/tests/compiling.js b/test-browser/tests/compiling.js index eb960bd592..8c21f7157c 100644 --- a/test-browser/tests/compiling.js +++ b/test-browser/tests/compiling.js @@ -11,26 +11,9 @@ module.exports = { '@sources': function () { return sources }, - 'Compiling': function (browser) { - runTests(browser) - }, - tearDown: sauce -} - -function runTests (browser) { - browser - .waitForElementVisible('#icon-panel', 10000) - .clickLaunchIcon('solidity') - .perform(() => { - // the first fn is used to pass browser to the other ones. - async.waterfall([function (callback) { callback(null, browser) }, testSimpleContract, testReturnValues, testInputValues, testRecorder.test], function () { - browser.end() - }) - }) -} -function testSimpleContract (browser, callback) { - browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract']) + 'Test Simple Contract': function (browser) { + browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['TestContract']) .clickLaunchIcon('run') .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') @@ -54,11 +37,10 @@ function testSimpleContract (browser, callback) { "3": "uint256: 4" }`) .click('i[class^="clearinstance"]') - .perform(() => { callback(null, browser) }) -} + }, -function testReturnValues (browser, callback) { - browser.testContracts('returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues']) + 'Test Return Values': function (browser) { + browser.testContracts('returnValues.sol', sources[1]['browser/returnValues.sol'], ['testReturnValues']) .clickLaunchIcon('run') .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') @@ -91,11 +73,11 @@ function testReturnValues (browser, callback) { '[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues3() 0x5e7...26e9f\nvalue:0 wei\ndata:0x033...e0a7d\nlogs:0\nhash:0x94c...9d28a', null, `{ "0": "uint8: _en 2", "1": "int256[5][]: _a1 1,-45,-78,56,60,-1,42,334,-45455,-446,1,10,-5435,45,-7" -}`).click('i[class^="clearinstance"]').perform(() => { callback(null, browser) }) -} +}`).click('i[class^="clearinstance"]') + }, -function testInputValues (browser, callback) { - browser.testContracts('inputValues.sol', sources[2]['browser/inputValues.sol'], ['test']) + 'Test Input Values': function (browser) { + browser.testContracts('inputValues.sol', sources[2]['browser/inputValues.sol'], ['test']) .clickLaunchIcon('run') .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') @@ -144,7 +126,16 @@ function testInputValues (browser, callback) { } ]`) .click('i[class^="clearinstance"]') - .perform(() => { callback(null, browser) }) + .end() + }, + + 'Test Recorder': function (browser) { + testRecorder.test(browser, () => { + browser.end() + }) + }, + + tearDown: sauce } // @TODO test: bytes8[3][] type as input diff --git a/test-browser/tests/units/testRecorder.js b/test-browser/tests/units/testRecorder.js index 10df90bce7..8a2996800c 100644 --- a/test-browser/tests/units/testRecorder.js +++ b/test-browser/tests/units/testRecorder.js @@ -1,7 +1,7 @@ 'use strict' module.exports = { - '@disabled': true, // run by compiling.j + '@disabled': true, // run by compiling. '@sources': function () { return sources }, From cd5896414c7b70ea0bca6d9995842fe5714cae77 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:17:32 +0200 Subject: [PATCH 3/6] general test refactor --- test-browser/tests/generalTests.js | 210 ++++++++++++----------------- 1 file changed, 85 insertions(+), 125 deletions(-) diff --git a/test-browser/tests/generalTests.js b/test-browser/tests/generalTests.js index 041f358c5c..711d21f165 100644 --- a/test-browser/tests/generalTests.js +++ b/test-browser/tests/generalTests.js @@ -10,110 +10,97 @@ module.exports = { '@sources': function () { return sources }, - 'Simple Contract': function (browser) { - runTests(browser) + 'Test Simple Contract': function (browser) { + console.log('testSimpleContract') + browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2']) + }, + 'Test Success Import': function (browser) { + console.log('testSuccessImport') + browser.addFile('Untitled1.sol', sources[1]['browser/Untitled1.sol']) + .addFile('Untitled2.sol', sources[1]['browser/Untitled2.sol']) + .switchFile('browser/Untitled1.sol') + .verifyContracts(['test6', 'test4', 'test5']) }, - tearDown: sauce -} - -function runTests (browser) { - browser - .waitForElementVisible('#icon-panel', 10000) - .clickLaunchIcon('solidity') - .clickLaunchIcon('fileExplorers') - .perform(() => { - // the first fn is used to pass browser to the other ones. - async.waterfall([function (callback) { callback(null, browser) }, - testSimpleContract, - testSuccessImport, - testFailedImport, /* testGitHubImport, */ - addDeployLibTestFile, - testAutoDeployLib, - testManualDeployLib, - testSignature - ], - function () { - browser.end() - }) - }) -} - -function testSimpleContract (browser, callback) { - console.log('testSimpleContract') - browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2']) - .perform(() => { - callback(null, browser) - }) -} - -function testSuccessImport (browser, callback) { - console.log('testSuccessImport') - browser.addFile('Untitled1.sol', sources[1]['browser/Untitled1.sol']) - .addFile('Untitled2.sol', sources[1]['browser/Untitled2.sol']) - .switchFile('browser/Untitled1.sol') - .verifyContracts(['test6', 'test4', 'test5']) - .perform(() => { - callback(null, browser) - }) -} - -function testFailedImport (browser, callback) { - console.log('testFailedImport') - browser.addFile('Untitled3.sol', sources[2]['browser/Untitled3.sol']) - .clickLaunchIcon('solidity') - .assert.containsText('#compileTabView .error pre', 'Unable to import "browser/Untitled11.sol": File not found') - .perform(function () { - callback(null, browser) - }) -} - -function addDeployLibTestFile (browser, callback) { - browser.addFile('Untitled5.sol', sources[5]['browser/Untitled5.sol']) - .perform(() => { - callback(null, browser) - }) -} -function testAutoDeployLib (browser, callback) { - console.log('testAutoDeployLib') - let addressRef - browser.verifyContracts(['test']) - .selectContract('test') - .createContract('') - .getAddressAtPosition(0, (address) => { - console.log('testAutoDeployLib ' + address) - addressRef = address - }) - .waitForElementPresent('.instance:nth-of-type(2)') - .click('.instance:nth-of-type(2) > div > button') - .perform(() => { - browser - .testConstantFunction(addressRef, 'get - call', '', '0: uint256: 45') - .perform(() => { - callback(null, browser) + 'Test Failed Import': function (browser) { + console.log('testFailedImport') + browser.addFile('Untitled3.sol', sources[2]['browser/Untitled3.sol']) + .clickLaunchIcon('solidity') + .assert.containsText('#compileTabView .error pre', 'Unable to import "browser/Untitled11.sol": File not found') + }, + 'Add Lib Test File': function (browser) { + browser.addFile('Untitled5.sol', sources[5]['browser/Untitled5.sol']) + }, + 'Test Auto Deploy Lib': function (browser) { + console.log('testAutoDeployLib') + let addressRef + browser.verifyContracts(['test']) + .selectContract('test') + .createContract('') + .getAddressAtPosition(0, (address) => { + console.log('testAutoDeployLib ' + address) + addressRef = address }) - }) -} - -function testManualDeployLib (browser, callback) { - console.log('testManualDeployLib') - browser.click('i[class^="clearinstance"]') - .pause(5000) - .clickLaunchIcon('settings') - .click('#generatecontractmetadata') - .clickLaunchIcon('solidity') - .click('#compileTabView button[title="Compile"]') // that should generate the JSON artefact - .verifyContracts(['test']) - .selectContract('lib') // deploy lib - .createContract('') - .getAddressAtPosition(0, (address) => { - console.log(address) - checkDeployShouldFail(browser, () => { - checkDeployShouldSucceed(browser, address, () => { - callback(null, browser) + .waitForElementPresent('.instance:nth-of-type(2)') + .click('.instance:nth-of-type(2) > div > button') + .perform((done) => { + browser.testConstantFunction(addressRef, 'get - call', '', '0: uint256: 45').perform(() => { + done() }) }) + }, + 'Test Manual Deploy Lib': function (browser) { + console.log('testManualDeployLib') + browser.click('i[class^="clearinstance"]') + .pause(5000) + .clickLaunchIcon('settings') + .click('#generatecontractmetadata') + .clickLaunchIcon('solidity') + .click('#compileTabView button[title="Compile"]') // that should generate the JSON artefact + .verifyContracts(['test']) + .selectContract('lib') // deploy lib + .createContract('') + .perform((done) => { + browser.getAddressAtPosition(0, (address) => { + console.log(address) + checkDeployShouldFail(browser, () => { + checkDeployShouldSucceed(browser, address, () => { + done() + }) + }) + }) + }) + + }, + 'Test Signature': function (browser) { + let hash, signature + browser.signMessage('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') + }) + .addFile('signMassage.sol', sources[6]['browser/signMassage.sol']) + .switchFile('browser/signMassage.sol') + .selectContract('ECVerify') + .createContract('') + .waitForElementPresent('.instance:nth-of-type(4)') + .click('.instance:nth-of-type(4) > div > button') + .perform((done) => { + browser.getAttribute('.instance:nth-of-type(4)', '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}"`}) + .verifyCallReturnValue( + address, + ['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c']) + .perform(() => { + done() + }) }) + }) + }, + tearDown: sauce } function checkDeployShouldFail (browser, callback) { @@ -160,33 +147,6 @@ function checkDeployShouldSucceed (browser, address, callback) { }) } -function testSignature (browser, callback) { - let hash, signature - browser.signMessage('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') - }) - .addFile('signMassage.sol', sources[6]['browser/signMassage.sol']) - .switchFile('browser/signMassage.sol') - .selectContract('ECVerify') - .createContract('') - .waitForElementPresent('.instance:nth-of-type(4)') - .click('.instance:nth-of-type(4) > div > button') - .getAttribute('.instance:nth-of-type(4)', '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}"`}) - .verifyCallReturnValue( - address, - ['0: address: 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c']) - .perform(() => { - callback(null, browser) - }) - }) -} - /* function testGitHubImport (browser, callback) { contractHelper.addFile(browser, 'Untitled4.sol', sources[3]['browser/Untitled4.sol'], () => { From ce59159006dce6e7886707740111b51874d55728 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:18:15 +0200 Subject: [PATCH 4/6] naming --- test-browser/tests/sharedFolderExplorer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-browser/tests/sharedFolderExplorer.js b/test-browser/tests/sharedFolderExplorer.js index 410f57eebe..0b825d0e49 100644 --- a/test-browser/tests/sharedFolderExplorer.js +++ b/test-browser/tests/sharedFolderExplorer.js @@ -38,7 +38,7 @@ module.exports = { '@sources': function () { return sources }, - 'SharedFolderExplorer': function (browser) { + 'Test Shared Folder Explorer': function (browser) { runTests(browser) }, tearDown: sauce From f9b34afbc41370a49a0410ffcb122fe99c6d5416 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:20:32 +0200 Subject: [PATCH 5/6] fix ending tests --- test-browser/tests/compiling.js | 1 - test-browser/tests/generalTests.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test-browser/tests/compiling.js b/test-browser/tests/compiling.js index 8c21f7157c..0b62deec0f 100644 --- a/test-browser/tests/compiling.js +++ b/test-browser/tests/compiling.js @@ -126,7 +126,6 @@ module.exports = { } ]`) .click('i[class^="clearinstance"]') - .end() }, 'Test Recorder': function (browser) { diff --git a/test-browser/tests/generalTests.js b/test-browser/tests/generalTests.js index 711d21f165..d656f43068 100644 --- a/test-browser/tests/generalTests.js +++ b/test-browser/tests/generalTests.js @@ -70,7 +70,6 @@ module.exports = { }) }) }) - }, 'Test Signature': function (browser) { let hash, signature @@ -99,6 +98,7 @@ module.exports = { }) }) }) + .end() }, tearDown: sauce } From 78bc8a16d27e90d84dd4fe2c7bfb1b7564343609 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 20 Jun 2019 17:25:12 +0200 Subject: [PATCH 6/6] standard --- test-browser/tests/compiling.js | 1 - test-browser/tests/generalTests.js | 1 - 2 files changed, 2 deletions(-) diff --git a/test-browser/tests/compiling.js b/test-browser/tests/compiling.js index 0b62deec0f..73836e2e7c 100644 --- a/test-browser/tests/compiling.js +++ b/test-browser/tests/compiling.js @@ -1,7 +1,6 @@ 'use strict' var init = require('../helpers/init') var sauce = require('./sauce') -var async = require('async') var testRecorder = require('./units/testRecorder') module.exports = { diff --git a/test-browser/tests/generalTests.js b/test-browser/tests/generalTests.js index d656f43068..6be06561c9 100644 --- a/test-browser/tests/generalTests.js +++ b/test-browser/tests/generalTests.js @@ -1,7 +1,6 @@ 'use strict' var init = require('../helpers/init') var sauce = require('./sauce') -var async = require('async') module.exports = { before: function (browser, done) {