From 277054708c73c10eed17c875d7200e4d03f4cf77 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 19 Feb 2020 04:59:07 +0000 Subject: [PATCH 01/10] Change testFunction assertion test --- src/app/ui/txLogger.js | 33 +++++----- test-browser/commands/testFunction.js | 93 ++++++++++++++------------- test-browser/tests/ballot.js | 2 + 3 files changed, 66 insertions(+), 62 deletions(-) diff --git a/src/app/ui/txLogger.js b/src/app/ui/txLogger.js index 4ab75bdc34..92f1a260ac 100644 --- a/src/app/ui/txLogger.js +++ b/src/app/ui/txLogger.js @@ -210,7 +210,7 @@ function renderKnownTransaction (self, data, blockchain) { var obj = {from, to} var txType = 'knownTx' var tx = yo` - +
txDetails(e, tx, data, obj)}> ${checkTxStatus(data.receipt, txType)} ${context(self, {from, to, data}, blockchain)} @@ -384,7 +384,8 @@ function txDetails (e, tx, data, obj) { } function createTable (opts) { - var table = yo`
` + console.log('opts: ', opts) + var table = yo`
` if (!opts.isCall) { var msg = '' if (opts.status !== undefined && opts.status !== null) { @@ -399,14 +400,14 @@ function createTable (opts) { table.appendChild(yo` status - ${opts.status}${msg} + ${opts.status}${msg} `) } var transactionHash = yo` transaction hash - ${opts.hash} + ${opts.hash} ${copyToClipboard(() => opts.hash)} @@ -416,7 +417,7 @@ function createTable (opts) { var contractAddress = yo` contract address - ${opts.contractAddress} + ${opts.contractAddress} ${copyToClipboard(() => opts.contractAddress)} @@ -426,7 +427,7 @@ function createTable (opts) { var from = yo` from - ${opts.from} + ${opts.from} ${copyToClipboard(() => opts.from)} @@ -443,7 +444,7 @@ function createTable (opts) { var to = yo` to - ${toHash} + ${toHash} ${copyToClipboard(() => data.to ? data.to : toHash)} @@ -453,7 +454,7 @@ function createTable (opts) { var gas = yo` gas - ${opts.gas} gas + ${opts.gas} gas ${copyToClipboard(() => opts.gas)} @@ -468,7 +469,7 @@ function createTable (opts) { table.appendChild(yo` transaction cost - ${opts.transactionCost} gas ${callWarning} + ${opts.transactionCost} gas ${callWarning} ${copyToClipboard(() => opts.transactionCost)} `) @@ -478,7 +479,7 @@ function createTable (opts) { table.appendChild(yo` execution cost - ${opts.executionCost} gas ${callWarning} + ${opts.executionCost} gas ${callWarning} ${copyToClipboard(() => opts.executionCost)} `) @@ -487,7 +488,7 @@ function createTable (opts) { var hash = yo` hash - ${opts.hash} + ${opts.hash} ${copyToClipboard(() => opts.hash)} @@ -497,7 +498,7 @@ function createTable (opts) { var input = yo` input - ${helper.shortenHexData(opts.input)} + ${helper.shortenHexData(opts.input)} ${copyToClipboard(() => opts.input)} @@ -508,7 +509,7 @@ function createTable (opts) { var inputDecoded = yo` decoded input - ${opts['decoded input']} + ${opts['decoded input']} ${copyToClipboard(() => opts['decoded input'])} ` @@ -519,7 +520,7 @@ function createTable (opts) { var outputDecoded = yo` decoded output - ${opts['decoded output']} + ${opts['decoded output']} ${copyToClipboard(() => opts['decoded output'])} ` @@ -533,7 +534,7 @@ function createTable (opts) { var logs = yo` logs - + ${JSON.stringify(stringified, null, '\t')} ${copyToClipboard(() => JSON.stringify(stringified, null, '\t'))} ${copyToClipboard(() => JSON.stringify(opts.logs.raw || '0'))} @@ -546,7 +547,7 @@ function createTable (opts) { val = yo` value - ${val} wei + ${val} wei ${copyToClipboard(() => `${val} wei`)} diff --git a/test-browser/commands/testFunction.js b/test-browser/commands/testFunction.js index b201158331..9d956c06b7 100644 --- a/test-browser/commands/testFunction.js +++ b/test-browser/commands/testFunction.js @@ -1,54 +1,55 @@ const EventEmitter = require('events') -const deepequal = require('deep-equal') -class TestFunction extends EventEmitter { - command (fnFullName, txHash, log, expectedInput, expectedReturn, expectedEvent, callback) { - this.api.waitForElementPresent('.instance button[title="' + fnFullName + '"]') - .perform(function (client, done) { - client.execute(function () { - document.querySelector('#runTabView').scrollTop = document.querySelector('#runTabView').scrollHeight - }, [], function () { - if (expectedInput) { - client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, function () {}) - } - done() - }) - }) - .click('.instance button[title="' + fnFullName + '"]') - .pause(500) - .waitForElementPresent('#main-panel div[class^="terminal"] span[id="tx' + txHash + '"]') - .assert.containsText('#main-panel div[class^="terminal"] span[id="tx' + txHash + '"] span', log) - .click('#main-panel div[class^="terminal"] span[id="tx' + txHash + '"] div[class^="log"]') - .perform(function (client, done) { - if (expectedReturn) { - client.getText('#main-panel div[class^="terminal"] span[id="tx' + txHash + '"] table[class^="txTable"] #decodedoutput', (result) => { - console.log(result) - var equal = deepequal(JSON.parse(result.value), JSON.parse(expectedReturn)) - if (!equal) { - client.assert.fail('expected ' + expectedReturn + ' got ' + result.value, 'info about error', '') - } - }) - } - done() - }) - .perform((client, done) => { - if (expectedEvent) { - client.getText('#main-panel div[class^="terminal"] span[id="tx' + txHash + '"] table[class^="txTable"] #logs', (result) => { - console.log(result) - var equal = deepequal(JSON.parse(result.value), JSON.parse(expectedEvent)) - if (!equal) { - client.assert.fail('expected ' + expectedEvent + ' got ' + result.value, 'info about error', '') - } - }) - } - done() - if (callback) { - callback.call(this.api) - } +/* + Checks if any child elements of journal (console) contains a matching value. +*/ +class testTransactionLog extends EventEmitter { + command (txHash, expectedValue) { + const browser = this.api; + browser.perform(() => { + const result = parseTransactionLog(this.api, txHash) + this.emit('complete') }) return this } } -module.exports = TestFunction +function parseTransactionLog(browser, txHash){ + const logs = { + status: '', + 'transaction hash': '', + 'contract address': '', + from: '', + to: '', + gas: '', + 'transaction cost': '', + 'execution cost': '', + hash: '', + input: '', + 'decoded input': '', + 'decoded output': '', + logs: '', + value: '' + } + + browser.waitForElementVisible('txLoggerTable'+txHash) + .getText(`*[data-id="txLoggerTableStatus${txHash}"]`, (result) => logs.status = result) + .getText(`*[data-id="txLoggerTableTransactionHash${txHash}"]`, (result) => logs['transaction hash'] = result) + .getText(`*[data-id="txLoggerTableContractAddress${txHash}"]`, (result) => logs['contract address'] = result) + .getText(`*[data-id="txLoggerTableFrom${txHash}"]`, (result) => logs.from = result) + .getText(`*[data-id="txLoggerTableTo${txHash}"]`, (result) => logs.to = result) + .getText(`*[data-id="txLoggerTableGas${txHash}"]`, (result) => logs.gas = result) + .getText(`*[data-id="txLoggerTableTransactionCost${txHash}"]`, (result) => logs['transaction cost'] = result) + .getText(`*[data-id="txLoggerTableExecutionCost${txHash}"]`, (result) => logs['execution cost'] = result) + .getText(`*[data-id="txLoggerTableHash${txHash}"]`, (result) => logs.hash = result) + .getText(`*[data-id="txLoggerTableInput${txHash}"]`, (result) => logs.input = result) + .getText(`*[data-id="txLoggerTableDecodedInput${txHash}"]`, (result) => logs['decoded input'] = result) + .getText(`*[data-id="txLoggerTableDecodedOutput${txHash}"]`, (result) => logs['decoded output'] = result) + .getText(`*[data-id="txLoggerTableDecodedLogs${txHash}"]`, (result) => logs.logs = result) + .getText(`*[data-id="txLoggerTableDecodedLogs${txHash}"]`, (result) => logs.value = result) + + return logs; +} + +module.exports = testFunction \ No newline at end of file diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index 60b4e9b2e7..a74b6e46f6 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -25,6 +25,8 @@ module.exports = { .click('#runTabView button[class^="instanceButton"]') .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') + .createContract(["0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3"]) + .pause(100000) .testFunction('delegate - transact (not payable)', '0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3', `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0x41f...c31b3`, {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) From 3cdd1150bdd68e5b856883e71e7a2e52d48f08ae Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 19 Feb 2020 11:06:17 +0000 Subject: [PATCH 02/10] Improve transaction log tests --- src/app/ui/txLogger.js | 56 +++++++++---------- test-browser/commands/testFunction.js | 55 ------------------- test-browser/commands/testTransactionLog.js | 60 +++++++++++++++++++++ test-browser/tests/ballot.js | 23 +++++--- 4 files changed, 104 insertions(+), 90 deletions(-) delete mode 100644 test-browser/commands/testFunction.js create mode 100644 test-browser/commands/testTransactionLog.js diff --git a/src/app/ui/txLogger.js b/src/app/ui/txLogger.js index 92f1a260ac..1f01a57b48 100644 --- a/src/app/ui/txLogger.js +++ b/src/app/ui/txLogger.js @@ -399,15 +399,15 @@ function createTable (opts) { } table.appendChild(yo` - status - ${opts.status}${msg} + status + ${opts.status}${msg} `) } var transactionHash = yo` - transaction hash - ${opts.hash} + transaction hash + ${opts.hash} ${copyToClipboard(() => opts.hash)} @@ -416,8 +416,8 @@ function createTable (opts) { var contractAddress = yo` - contract address - ${opts.contractAddress} + contract address + ${opts.contractAddress} ${copyToClipboard(() => opts.contractAddress)} @@ -426,8 +426,8 @@ function createTable (opts) { var from = yo` - from - ${opts.from} + from + ${opts.from} ${copyToClipboard(() => opts.from)} @@ -443,8 +443,8 @@ function createTable (opts) { } var to = yo` - to - ${toHash} + to + ${toHash} ${copyToClipboard(() => data.to ? data.to : toHash)} @@ -453,8 +453,8 @@ function createTable (opts) { var gas = yo` - gas - ${opts.gas} gas + gas + ${opts.gas} gas ${copyToClipboard(() => opts.gas)} @@ -468,8 +468,8 @@ function createTable (opts) { if (opts.transactionCost) { table.appendChild(yo` - transaction cost - ${opts.transactionCost} gas ${callWarning} + transaction cost + ${opts.transactionCost} gas ${callWarning} ${copyToClipboard(() => opts.transactionCost)} `) @@ -478,8 +478,8 @@ function createTable (opts) { if (opts.executionCost) { table.appendChild(yo` - execution cost - ${opts.executionCost} gas ${callWarning} + execution cost + ${opts.executionCost} gas ${callWarning} ${copyToClipboard(() => opts.executionCost)} `) @@ -487,8 +487,8 @@ function createTable (opts) { var hash = yo` - hash - ${opts.hash} + hash + ${opts.hash} ${copyToClipboard(() => opts.hash)} @@ -497,8 +497,8 @@ function createTable (opts) { var input = yo` - input - ${helper.shortenHexData(opts.input)} + input + ${helper.shortenHexData(opts.input)} ${copyToClipboard(() => opts.input)} @@ -508,8 +508,8 @@ function createTable (opts) { if (opts['decoded input']) { var inputDecoded = yo` - decoded input - ${opts['decoded input']} + decoded input + ${opts['decoded input']} ${copyToClipboard(() => opts['decoded input'])} ` @@ -519,8 +519,8 @@ function createTable (opts) { if (opts['decoded output']) { var outputDecoded = yo` - decoded output - ${opts['decoded output']} + decoded output + ${opts['decoded output']} ${copyToClipboard(() => opts['decoded output'])} ` @@ -533,8 +533,8 @@ function createTable (opts) { } var logs = yo` - logs - + logs + ${JSON.stringify(stringified, null, '\t')} ${copyToClipboard(() => JSON.stringify(stringified, null, '\t'))} ${copyToClipboard(() => JSON.stringify(opts.logs.raw || '0'))} @@ -546,8 +546,8 @@ function createTable (opts) { var val = opts.val != null ? typeConversion.toInt(opts.val) : 0 val = yo` - value - ${val} wei + value + ${val} wei ${copyToClipboard(() => `${val} wei`)} diff --git a/test-browser/commands/testFunction.js b/test-browser/commands/testFunction.js deleted file mode 100644 index 9d956c06b7..0000000000 --- a/test-browser/commands/testFunction.js +++ /dev/null @@ -1,55 +0,0 @@ -const EventEmitter = require('events') - -/* - Checks if any child elements of journal (console) contains a matching value. -*/ -class testTransactionLog extends EventEmitter { - command (txHash, expectedValue) { - const browser = this.api; - browser.perform(() => { - const result = parseTransactionLog(this.api, txHash) - - this.emit('complete') - }) - return this - } -} - -function parseTransactionLog(browser, txHash){ - const logs = { - status: '', - 'transaction hash': '', - 'contract address': '', - from: '', - to: '', - gas: '', - 'transaction cost': '', - 'execution cost': '', - hash: '', - input: '', - 'decoded input': '', - 'decoded output': '', - logs: '', - value: '' - } - - browser.waitForElementVisible('txLoggerTable'+txHash) - .getText(`*[data-id="txLoggerTableStatus${txHash}"]`, (result) => logs.status = result) - .getText(`*[data-id="txLoggerTableTransactionHash${txHash}"]`, (result) => logs['transaction hash'] = result) - .getText(`*[data-id="txLoggerTableContractAddress${txHash}"]`, (result) => logs['contract address'] = result) - .getText(`*[data-id="txLoggerTableFrom${txHash}"]`, (result) => logs.from = result) - .getText(`*[data-id="txLoggerTableTo${txHash}"]`, (result) => logs.to = result) - .getText(`*[data-id="txLoggerTableGas${txHash}"]`, (result) => logs.gas = result) - .getText(`*[data-id="txLoggerTableTransactionCost${txHash}"]`, (result) => logs['transaction cost'] = result) - .getText(`*[data-id="txLoggerTableExecutionCost${txHash}"]`, (result) => logs['execution cost'] = result) - .getText(`*[data-id="txLoggerTableHash${txHash}"]`, (result) => logs.hash = result) - .getText(`*[data-id="txLoggerTableInput${txHash}"]`, (result) => logs.input = result) - .getText(`*[data-id="txLoggerTableDecodedInput${txHash}"]`, (result) => logs['decoded input'] = result) - .getText(`*[data-id="txLoggerTableDecodedOutput${txHash}"]`, (result) => logs['decoded output'] = result) - .getText(`*[data-id="txLoggerTableDecodedLogs${txHash}"]`, (result) => logs.logs = result) - .getText(`*[data-id="txLoggerTableDecodedLogs${txHash}"]`, (result) => logs.value = result) - - return logs; -} - -module.exports = testFunction \ No newline at end of file diff --git a/test-browser/commands/testTransactionLog.js b/test-browser/commands/testTransactionLog.js new file mode 100644 index 0000000000..df2bb942d0 --- /dev/null +++ b/test-browser/commands/testTransactionLog.js @@ -0,0 +1,60 @@ +const EventEmitter = require('events') +const deepequal = require('deep-equal') + +class testTransactionLog extends EventEmitter { + command (txHash, expectedValue) { + const browser = this.api + const logs = {} + const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; + + browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`) + .click(`*[data-id="txLogger${txHash}"]`) + .waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`) + .click(`*[data-id="txLoggerTable${txHash}"]`) + + // fetch and format transaction logs as key => pair object + .elements('css selector', `*[data-shared="key_${txHash}"]`, (res) => { + res.value.forEach(function (jsonWebElement) { + const jsonWebElementId = jsonWebElement.ELEMENT + + browser.elementIdText(jsonWebElementId, (jsonElement) => { + const key = jsonElement.value.trim() + + logs[key] = null + }) + }) + }) + .elements('css selector', `*[data-shared="pair_${txHash}"]`, (res) => { + res.value.forEach(function (jsonWebElement, index) { + const jsonWebElementId = jsonWebElement.ELEMENT + + browser.elementIdText(jsonWebElementId, (jsonElement) => { + let value = jsonElement.value + + try{ + value = JSON.parse(jsonElement.value) + setLog(index, value) + }catch(e){ + setLog(index, value) + } + }) + }) + }) + + browser.perform(() => { + Object.keys(expectedValue).forEach(key => { + const equal = deepequal(logs[key], expectedValue[key]) + + if (!equal) { + browser.assert.fail(`Expected ${expectedValue[key]} but got ${logs[key]}`) + }else{ + browser.assert.ok(true, `Expected value matched returned value ${expectedValue[key]}`) + } + }) + this.emit('complete') + }) + return this + } +} + +module.exports = testTransactionLog \ No newline at end of file diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index a74b6e46f6..af69c44eea 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -26,10 +26,13 @@ module.exports = { .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') .createContract(["0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3"]) - .pause(100000) - .testFunction('delegate - transact (not payable)', '0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3', - `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0x41f...c31b3`, - {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) + .testTransactionLog('0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', { + status: '0x1 Transaction mined and execution succeed', + 'transaction hash': '0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', + 'decoded input': { + 'bytes32[] proposalNames': [ '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' ] + } + }) }, 'Debug Ballot / delegate': function (browser) { @@ -55,9 +58,15 @@ module.exports = { .pause(500) .waitForElementPresent('.instance:nth-of-type(2)') .click('.instance:nth-of-type(2) > div > button') - .testFunction('delegate - transact (not payable)', '0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803', - `[vm]\nfrom:0xca3...a733c\nto:Ballot.delegate(address) 0x692...77b3a\nvalue:0 wei\ndata:0x5c1...4d2db\nlogs:0\nhash:0xca5...5c803`, - {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}, null, null) + .createContract(["0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803"]) + .pause(100000) + .testTransactionLog('0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', { + status: '0x1 Transaction mined and execution succeed', + 'transaction hash': '0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', + 'decoded input': { + 'bytes32[] proposalNames': [ '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' ] + } + }) }, 'Deploy and use Ballot using external web3': function (browser) { From 419aa38556f4c47633f0b8acbec6281172880770 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 19 Feb 2020 18:36:46 +0000 Subject: [PATCH 03/10] Modified testFunction command --- src/app/components/vertical-icons.js | 2 +- src/app/udapp/run-tab.js | 2 +- src/app/ui/multiParamManager.js | 7 +- src/app/ui/txLogger.js | 2 +- test-browser/commands/goToVMTraceStep.js | 2 +- test-browser/commands/testFunction.js | 73 +++++++++++++++++++++ test-browser/commands/testTransactionLog.js | 13 ++++ test-browser/tests/ballot.js | 23 +++---- 8 files changed, 107 insertions(+), 17 deletions(-) create mode 100644 test-browser/commands/testFunction.js diff --git a/src/app/components/vertical-icons.js b/src/app/components/vertical-icons.js index ca9b604f0e..324a45d82e 100644 --- a/src/app/components/vertical-icons.js +++ b/src/app/components/vertical-icons.js @@ -262,7 +262,7 @@ export class VerticalIcons extends Plugin { ` this.iconKind['debugging'] = yo` -
+
` diff --git a/src/app/udapp/run-tab.js b/src/app/udapp/run-tab.js index 0494c5aeee..49ed6537d6 100644 --- a/src/app/udapp/run-tab.js +++ b/src/app/udapp/run-tab.js @@ -47,7 +47,7 @@ export class RunTab extends LibraryPlugin { } renderContainer () { - this.container = yo`
` + this.container = yo`
` var el = yo`
diff --git a/src/app/ui/multiParamManager.js b/src/app/ui/multiParamManager.js index cc8b7007c5..6468ef1fb4 100644 --- a/src/app/ui/multiParamManager.js +++ b/src/app/ui/multiParamManager.js @@ -100,7 +100,7 @@ class MultiParamManager { if (this.funABI.inputs) { return yo`
${this.funABI.inputs.map(function (inp) { - return yo`
` + return yo`
` })}
` } @@ -119,7 +119,7 @@ class MultiParamManager { this.basicInputField = yo`` this.basicInputField.setAttribute('placeholder', this.inputs) this.basicInputField.setAttribute('title', this.inputs) - this.basicInputField.setAttribute('data-id', this.inputs) + this.basicInputField.setAttribute('data-id', `multiParamManagerBasicInputField${this.inputs}`) var onClick = () => { this.clickCallBack(this.funABI.inputs, this.basicInputField.value) @@ -184,6 +184,7 @@ class MultiParamManager { expandedButton.setAttribute('title', (title + ' - call')) expandedButton.innerHTML = 'call' expandedButton.classList.add('btn-info') + expandedButton.setAttribute('data-id', (title + ' - call')) funcButton.setAttribute('title', (title + ' - call')) funcButton.classList.add('btn-info') funcButton.setAttribute('data-id', (title + ' - call')) @@ -192,6 +193,7 @@ class MultiParamManager { expandedButton.setAttribute('title', (title + ' - transact (payable)')) expandedButton.innerHTML = 'transact' expandedButton.classList.add('btn-danger') + expandedButton.setAttribute('data-id', (title + ' - transact (payable)')) funcButton.setAttribute('title', (title + ' - transact (payable)')) funcButton.classList.add('btn-danger') funcButton.setAttribute('data-id', (title + ' - transact (payable)')) @@ -200,6 +202,7 @@ class MultiParamManager { expandedButton.setAttribute('title', (title + ' - transact (not payable)')) expandedButton.innerHTML = 'transact' expandedButton.classList.add('btn-warning') + expandedButton.setAttribute('data-id', (title + ' - transact (not payable)')) funcButton.classList.add('btn-warning') funcButton.setAttribute('title', (title + ' - transact (not payable)')) funcButton.setAttribute('data-id', (title + ' - transact (not payable)')) diff --git a/src/app/ui/txLogger.js b/src/app/ui/txLogger.js index 1f01a57b48..b3592848e9 100644 --- a/src/app/ui/txLogger.js +++ b/src/app/ui/txLogger.js @@ -215,7 +215,7 @@ function renderKnownTransaction (self, data, blockchain) { ${checkTxStatus(data.receipt, txType)} ${context(self, {from, to, data}, blockchain)}
-
+
diff --git a/test-browser/commands/goToVMTraceStep.js b/test-browser/commands/goToVMTraceStep.js index a1a95d809b..b5a7854916 100644 --- a/test-browser/commands/goToVMTraceStep.js +++ b/test-browser/commands/goToVMTraceStep.js @@ -28,7 +28,7 @@ function goToVMtraceStep (browser, step, incr, done) { browser.click('#intoforward') .perform(() => { setTimeout(() => { - goToVMtraceStep(browser, step, done, incr) + goToVMtraceStep(browser, step, incr, done) }, 200) }) } diff --git a/test-browser/commands/testFunction.js b/test-browser/commands/testFunction.js new file mode 100644 index 0000000000..39f41c6eae --- /dev/null +++ b/test-browser/commands/testFunction.js @@ -0,0 +1,73 @@ +const EventEmitter = require('events') +const deepequal = require('deep-equal') + +class TestFunction extends EventEmitter { + command (fnFullName, txHash, expectedReturn, input) { + const browser = this.api + const logs = {} + const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; + + browser.waitForElementPresent(`*[data-id="${fnFullName}"]`) + .perform(function (client, done) { + client.execute(function () { + document.querySelector('*[data-id="runTabView"]').scrollTop = document.querySelector('*[data-id="runTabView"]').scrollHeight + }, [], function () { + if (input) { + client.setValue(`*[data-id="multiParamManagerBasicInputField${input.types}"]`, input.values, function () {}) + } + done() + }) + }) + .click(`*[data-id="${fnFullName}"]`) + .pause(500) + .waitForElementVisible(`*[data-id="txLogger${txHash}"]`) + .click(`*[data-id="txLogger${txHash}"]`) + .waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`) + .click(`*[data-id="txLoggerTable${txHash}"]`) + + // fetch and format transaction logs as key => pair object + .elements('css selector', `*[data-shared="key_${txHash}"]`, (res) => { + res.value.forEach(function (jsonWebElement) { + const jsonWebElementId = jsonWebElement.ELEMENT + + browser.elementIdText(jsonWebElementId, (jsonElement) => { + const key = jsonElement.value.trim() + + logs[key] = null + }) + }) + }) + .elements('css selector', `*[data-shared="pair_${txHash}"]`, (res) => { + res.value.forEach(function (jsonWebElement, index) { + const jsonWebElementId = jsonWebElement.ELEMENT + + browser.elementIdText(jsonWebElementId, (jsonElement) => { + let value = jsonElement.value + + try{ + value = JSON.parse(jsonElement.value) + setLog(index, value) + }catch(e){ + setLog(index, value) + } + }) + }) + }) + + browser.perform(() => { + Object.keys(expectedReturn).forEach(key => { + const equal = deepequal(logs[key], expectedReturn[key]) + + if (!equal) { + browser.assert.fail(`Expected ${expectedReturn[key]} but got ${logs[key]}`) + }else{ + browser.assert.ok(true, `Expected value matched returned value ${expectedReturn[key]}`) + } + }) + this.emit('complete') + }) + return this + } +} + +module.exports = TestFunction \ No newline at end of file diff --git a/test-browser/commands/testTransactionLog.js b/test-browser/commands/testTransactionLog.js index df2bb942d0..ab7e7c5245 100644 --- a/test-browser/commands/testTransactionLog.js +++ b/test-browser/commands/testTransactionLog.js @@ -7,6 +7,19 @@ class testTransactionLog extends EventEmitter { const logs = {} const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; + browser.waitForElementPresent('.instance button[title="' + fnFullName + '"]') + .perform(function (client, done) { + client.execute(function () { + document.querySelector('#runTabView').scrollTop = document.querySelector('#runTabView').scrollHeight + }, [], function () { + if (expectedInput) { + client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, function () {}) + } + done() + }) + }) + .click('.instance button[title="' + fnFullName + '"]') + .pause(500) browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`) .click(`*[data-id="txLogger${txHash}"]`) .waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`) diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index af69c44eea..61bddd8e17 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -16,23 +16,24 @@ module.exports = { }, 'Deploy Ballot': function (browser) { browser - .waitForElementVisible('#icon-panel', 10000) + .waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000) .clickLaunchIcon('solidity') .testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['Ballot']) .clickLaunchIcon('udapp') .selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') .setValue('input[placeholder="bytes32[] proposalNames"]', '["0x48656c6c6f20576f726c64210000000000000000000000000000000000000000"]') - .click('#runTabView button[class^="instanceButton"]') + .click('*[data-id="Deploy - transact (not payable)"]') .waitForElementPresent('.instance:nth-of-type(2)') - .click('.instance:nth-of-type(2) > div > button') - .createContract(["0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3"]) - .testTransactionLog('0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', { - status: '0x1 Transaction mined and execution succeed', - 'transaction hash': '0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', - 'decoded input': { - 'bytes32[] proposalNames': [ '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' ] - } - }) + .click('*[data-id="universalDappUiTitleExpander"]') + .testFunction( + 'delegate - transact (not payable)', + '0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3', + { + status: '0x1 Transaction mined and execution succeed', + 'transaction hash': '0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3', + 'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' } + }, + {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}) }, 'Debug Ballot / delegate': function (browser) { From 2526d9d52ce2d85e63142d8e49285ca6dba71b0d Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 20 Feb 2020 05:08:22 +0000 Subject: [PATCH 04/10] Updated transaction execution test with improved testFunction --- src/app/panels/terminal.js | 2 +- src/app/tabs/runTab/contractDropdown.js | 2 +- src/app/tabs/runTab/settings.js | 2 +- src/app/ui/universal-dapp-ui.js | 3 +- test-browser/commands/testFunction.js | 25 +-- test-browser/tests/ballot.js | 40 ++--- test-browser/tests/transactionExecution.js | 190 ++++++++++++--------- 7 files changed, 134 insertions(+), 130 deletions(-) diff --git a/src/app/panels/terminal.js b/src/app/panels/terminal.js index f8605a6cfa..8c9730edaf 100644 --- a/src/app/panels/terminal.js +++ b/src/app/panels/terminal.js @@ -165,7 +165,7 @@ class Terminal extends Plugin { ${self._view.dragbar}
${self._view.icon} -
+
diff --git a/src/app/tabs/runTab/contractDropdown.js b/src/app/tabs/runTab/contractDropdown.js index c91fd92986..0b566d604b 100644 --- a/src/app/tabs/runTab/contractDropdown.js +++ b/src/app/tabs/runTab/contractDropdown.js @@ -54,7 +54,7 @@ class ContractDropdownUI { this.createPanel = yo`
` this.orLabel = yo`
or
` let el = yo` -
+
${this.selectContractNames} ${this.compFails} ${info} diff --git a/src/app/tabs/runTab/settings.js b/src/app/tabs/runTab/settings.js index 280675c4c8..12b7e218c7 100644 --- a/src/app/tabs/runTab/settings.js +++ b/src/app/tabs/runTab/settings.js @@ -69,7 +69,7 @@ class SettingsUI { title="Execution environment has been provided by Metamask or similar provider." value="injected" name="executionContext"> Injected Web3 -
+
diff --git a/test-browser/commands/testTransactionLog.js b/test-browser/commands/testTransactionLog.js index df2bb942d0..ab7e7c5245 100644 --- a/test-browser/commands/testTransactionLog.js +++ b/test-browser/commands/testTransactionLog.js @@ -7,6 +7,19 @@ class testTransactionLog extends EventEmitter { const logs = {} const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; + browser.waitForElementPresent('.instance button[title="' + fnFullName + '"]') + .perform(function (client, done) { + client.execute(function () { + document.querySelector('#runTabView').scrollTop = document.querySelector('#runTabView').scrollHeight + }, [], function () { + if (expectedInput) { + client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, function () {}) + } + done() + }) + }) + .click('.instance button[title="' + fnFullName + '"]') + .pause(500) browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`) .click(`*[data-id="txLogger${txHash}"]`) .waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`) diff --git a/test-browser/tests/ballot.js b/test-browser/tests/ballot.js index 5add4d96b6..0cebb4ba5e 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -55,7 +55,6 @@ module.exports = { .clickLaunchIcon('fileExplorers') .addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3A', true, true) .pause(500) -<<<<<<< HEAD .waitForElementPresent('*[data-id="universalDappUiContractActionWrapper"]') .click('*[data-id="universalDappUiTitleExpander"]') .clickFunction('delegate - transact (not payable)', {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'}) @@ -65,19 +64,6 @@ module.exports = { 'transaction hash': '0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803', 'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' } }) -======= - .waitForElementPresent('.instance:nth-of-type(2)') - .click('.instance:nth-of-type(2) > div > button') - .createContract(["0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803"]) - .pause(100000) - .testTransactionLog('0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', { - status: '0x1 Transaction mined and execution succeed', - 'transaction hash': '0x57f7ac07a894739a8bbf059248f47aa49935bfcf673494114b1c5c0c183890f0', - 'decoded input': { - 'bytes32[] proposalNames': [ '0x48656c6c6f20576f726c64210000000000000000000000000000000000000000' ] - } - }) ->>>>>>> Improve transaction log tests }, 'Deploy and use Ballot using external web3': function (browser) { From 548064204c3196d35fbd900f27630ca1c3183ff8 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Thu, 20 Feb 2020 07:51:31 +0000 Subject: [PATCH 09/10] Fixed linting error --- test-browser/commands/testTransactionLog.js | 73 --------------------- 1 file changed, 73 deletions(-) delete mode 100644 test-browser/commands/testTransactionLog.js diff --git a/test-browser/commands/testTransactionLog.js b/test-browser/commands/testTransactionLog.js deleted file mode 100644 index ab7e7c5245..0000000000 --- a/test-browser/commands/testTransactionLog.js +++ /dev/null @@ -1,73 +0,0 @@ -const EventEmitter = require('events') -const deepequal = require('deep-equal') - -class testTransactionLog extends EventEmitter { - command (txHash, expectedValue) { - const browser = this.api - const logs = {} - const setLog = (index, value) => logs[Object.keys(logs)[index]] = value; - - browser.waitForElementPresent('.instance button[title="' + fnFullName + '"]') - .perform(function (client, done) { - client.execute(function () { - document.querySelector('#runTabView').scrollTop = document.querySelector('#runTabView').scrollHeight - }, [], function () { - if (expectedInput) { - client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, function () {}) - } - done() - }) - }) - .click('.instance button[title="' + fnFullName + '"]') - .pause(500) - browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`) - .click(`*[data-id="txLogger${txHash}"]`) - .waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`) - .click(`*[data-id="txLoggerTable${txHash}"]`) - - // fetch and format transaction logs as key => pair object - .elements('css selector', `*[data-shared="key_${txHash}"]`, (res) => { - res.value.forEach(function (jsonWebElement) { - const jsonWebElementId = jsonWebElement.ELEMENT - - browser.elementIdText(jsonWebElementId, (jsonElement) => { - const key = jsonElement.value.trim() - - logs[key] = null - }) - }) - }) - .elements('css selector', `*[data-shared="pair_${txHash}"]`, (res) => { - res.value.forEach(function (jsonWebElement, index) { - const jsonWebElementId = jsonWebElement.ELEMENT - - browser.elementIdText(jsonWebElementId, (jsonElement) => { - let value = jsonElement.value - - try{ - value = JSON.parse(jsonElement.value) - setLog(index, value) - }catch(e){ - setLog(index, value) - } - }) - }) - }) - - browser.perform(() => { - Object.keys(expectedValue).forEach(key => { - const equal = deepequal(logs[key], expectedValue[key]) - - if (!equal) { - browser.assert.fail(`Expected ${expectedValue[key]} but got ${logs[key]}`) - }else{ - browser.assert.ok(true, `Expected value matched returned value ${expectedValue[key]}`) - } - }) - this.emit('complete') - }) - return this - } -} - -module.exports = testTransactionLog \ No newline at end of file From bc4fc906db91a3d745517ffe5769573e6bbbfdc8 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 24 Mar 2020 13:14:34 +0000 Subject: [PATCH 10/10] Removed log to console in txLogger --- src/app/ui/txLogger.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/ui/txLogger.js b/src/app/ui/txLogger.js index fe20ca1d1f..237b63fe3b 100644 --- a/src/app/ui/txLogger.js +++ b/src/app/ui/txLogger.js @@ -384,7 +384,6 @@ function txDetails (e, tx, data, obj) { } function createTable (opts) { - console.log('opts: ', opts) var table = yo`
` if (!opts.isCall) { var msg = ''