Change testFunction assertion test

pull/5370/head
ioedeveloper 5 years ago committed by yann300
parent b8ad41d3c4
commit e7df29cbd7
  1. 33
      src/app/ui/txLogger.js
  2. 93
      test-browser/commands/testFunction.js
  3. 2
      test-browser/tests/ballot.js

@ -210,7 +210,7 @@ function renderKnownTransaction (self, data, blockchain) {
var obj = {from, to}
var txType = 'knownTx'
var tx = yo`
<span id="tx${data.tx.hash}">
<span id="tx${data.tx.hash}" data-id="txLogger${data.tx.hash}">
<div class="${css.log}" onclick=${e => 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`<table class="${css.txTable}" id="txTable"></table>`
console.log('opts: ', opts)
var table = yo`<table class="${css.txTable}" id="txTable" data-id="txLoggerTable${opts.hash}"></table>`
if (!opts.isCall) {
var msg = ''
if (opts.status !== undefined && opts.status !== null) {
@ -399,14 +400,14 @@ function createTable (opts) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> status </td>
<td class="${css.td}">${opts.status}${msg}</td>
<td class="${css.td}" data-id="txLoggerTableStatus${opts.hash}">${opts.status}${msg}</td>
</tr>`)
}
var transactionHash = yo`
<tr class="${css.tr}">
<td class="${css.td}"> transaction hash </td>
<td class="${css.td}">${opts.hash}
<td class="${css.td}" data-id="txLoggerTableHash${opts.hash}">${opts.hash}
${copyToClipboard(() => opts.hash)}
</td>
</tr>
@ -416,7 +417,7 @@ function createTable (opts) {
var contractAddress = yo`
<tr class="${css.tr}">
<td class="${css.td}"> contract address </td>
<td class="${css.td}">${opts.contractAddress}
<td class="${css.td}" data-id="txLoggerTableContractAddress${opts.hash}">${opts.contractAddress}
${copyToClipboard(() => opts.contractAddress)}
</td>
</tr>
@ -426,7 +427,7 @@ function createTable (opts) {
var from = yo`
<tr class="${css.tr}">
<td class="${css.td} ${css.tableTitle}"> from </td>
<td class="${css.td}">${opts.from}
<td class="${css.td}" data-id="txLoggerTableFrom${opts.hash}">${opts.from}
${copyToClipboard(() => opts.from)}
</td>
</tr>
@ -443,7 +444,7 @@ function createTable (opts) {
var to = yo`
<tr class="${css.tr}">
<td class="${css.td}"> to </td>
<td class="${css.td}">${toHash}
<td class="${css.td}" data-id="txLoggerTableTo${opts.hash}">${toHash}
${copyToClipboard(() => data.to ? data.to : toHash)}
</td>
</tr>
@ -453,7 +454,7 @@ function createTable (opts) {
var gas = yo`
<tr class="${css.tr}">
<td class="${css.td}"> gas </td>
<td class="${css.td}">${opts.gas} gas
<td class="${css.td}" data-id="txLoggerTableGas${opts.hash}">${opts.gas} gas
${copyToClipboard(() => opts.gas)}
</td>
</tr>
@ -468,7 +469,7 @@ function createTable (opts) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> transaction cost </td>
<td class="${css.td}">${opts.transactionCost} gas ${callWarning}
<td class="${css.td}" data-id="txLoggerTableTransactionCost${opts.hash}">${opts.transactionCost} gas ${callWarning}
${copyToClipboard(() => opts.transactionCost)}
</td>
</tr>`)
@ -478,7 +479,7 @@ function createTable (opts) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> execution cost </td>
<td class="${css.td}">${opts.executionCost} gas ${callWarning}
<td class="${css.td}" data-id="txLoggerTableExecutionHash${opts.hash}">${opts.executionCost} gas ${callWarning}
${copyToClipboard(() => opts.executionCost)}
</td>
</tr>`)
@ -487,7 +488,7 @@ function createTable (opts) {
var hash = yo`
<tr class="${css.tr}">
<td class="${css.td}"> hash </td>
<td class="${css.td}">${opts.hash}
<td class="${css.td}" data-id="txLoggerTableHash${opts.hash}">${opts.hash}
${copyToClipboard(() => opts.hash)}
</td>
</tr>
@ -497,7 +498,7 @@ function createTable (opts) {
var input = yo`
<tr class="${css.tr}">
<td class="${css.td}"> input </td>
<td class="${css.td}">${helper.shortenHexData(opts.input)}
<td class="${css.td}" data-id="txLoggerTableInput${opts.hash}">${helper.shortenHexData(opts.input)}
${copyToClipboard(() => opts.input)}
</td>
</tr>
@ -508,7 +509,7 @@ function createTable (opts) {
var inputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded input </td>
<td class="${css.td}">${opts['decoded input']}
<td class="${css.td}" data-id="txLoggerTableDecodedInput${opts.hash}">${opts['decoded input']}
${copyToClipboard(() => opts['decoded input'])}
</td>
</tr>`
@ -519,7 +520,7 @@ function createTable (opts) {
var outputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded output </td>
<td class="${css.td}" id="decodedoutput" >${opts['decoded output']}
<td class="${css.td}" id="decodedoutput" data-id="txLoggerTableDecodedOutput${opts.hash}">${opts['decoded output']}
${copyToClipboard(() => opts['decoded output'])}
</td>
</tr>`
@ -533,7 +534,7 @@ function createTable (opts) {
var logs = yo`
<tr class="${css.tr}">
<td class="${css.td}"> logs </td>
<td class="${css.td}" id="logs">
<td class="${css.td}" id="logs" data-id="txLoggerTableLogs${opts.hash}">
${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`
<tr class="${css.tr}">
<td class="${css.td}"> value </td>
<td class="${css.td}">${val} wei
<td class="${css.td}" data-id="txLoggerTableValue${opts.hash}">${val} wei
${copyToClipboard(() => `${val} wei`)}
</td>
</tr>

@ -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

@ -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)

Loading…
Cancel
Save