Improve transaction log tests

pull/5370/head
ioedeveloper 5 years ago committed by yann300
parent e7df29cbd7
commit 9806a205d4
  1. 56
      src/app/ui/txLogger.js
  2. 55
      test-browser/commands/testFunction.js
  3. 60
      test-browser/commands/testTransactionLog.js
  4. 23
      test-browser/tests/ballot.js

@ -399,15 +399,15 @@ function createTable (opts) {
}
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> status </td>
<td class="${css.td}" data-id="txLoggerTableStatus${opts.hash}">${opts.status}${msg}</td>
<td class="${css.td}" data-shared="key_${opts.hash}"> status </td>
<td class="${css.td}" data-shared="pair_${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}" data-id="txLoggerTableHash${opts.hash}">${opts.hash}
<td class="${css.td}" data-shared="key_${opts.hash}"> transaction hash </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.hash}
${copyToClipboard(() => opts.hash)}
</td>
</tr>
@ -416,8 +416,8 @@ function createTable (opts) {
var contractAddress = yo`
<tr class="${css.tr}">
<td class="${css.td}"> contract address </td>
<td class="${css.td}" data-id="txLoggerTableContractAddress${opts.hash}">${opts.contractAddress}
<td class="${css.td}" data-shared="key_${opts.hash}"> contract address </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.contractAddress}
${copyToClipboard(() => opts.contractAddress)}
</td>
</tr>
@ -426,8 +426,8 @@ function createTable (opts) {
var from = yo`
<tr class="${css.tr}">
<td class="${css.td} ${css.tableTitle}"> from </td>
<td class="${css.td}" data-id="txLoggerTableFrom${opts.hash}">${opts.from}
<td class="${css.td} ${css.tableTitle}" data-shared="key_${opts.hash}"> from </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.from}
${copyToClipboard(() => opts.from)}
</td>
</tr>
@ -443,8 +443,8 @@ function createTable (opts) {
}
var to = yo`
<tr class="${css.tr}">
<td class="${css.td}"> to </td>
<td class="${css.td}" data-id="txLoggerTableTo${opts.hash}">${toHash}
<td class="${css.td}" data-shared="key_${opts.hash}"> to </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${toHash}
${copyToClipboard(() => data.to ? data.to : toHash)}
</td>
</tr>
@ -453,8 +453,8 @@ function createTable (opts) {
var gas = yo`
<tr class="${css.tr}">
<td class="${css.td}"> gas </td>
<td class="${css.td}" data-id="txLoggerTableGas${opts.hash}">${opts.gas} gas
<td class="${css.td}" data-shared="key_${opts.hash}"> gas </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.gas} gas
${copyToClipboard(() => opts.gas)}
</td>
</tr>
@ -468,8 +468,8 @@ function createTable (opts) {
if (opts.transactionCost) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> transaction cost </td>
<td class="${css.td}" data-id="txLoggerTableTransactionCost${opts.hash}">${opts.transactionCost} gas ${callWarning}
<td class="${css.td}" data-shared="key_${opts.hash}"> transaction cost </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.transactionCost} gas ${callWarning}
${copyToClipboard(() => opts.transactionCost)}
</td>
</tr>`)
@ -478,8 +478,8 @@ function createTable (opts) {
if (opts.executionCost) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> execution cost </td>
<td class="${css.td}" data-id="txLoggerTableExecutionHash${opts.hash}">${opts.executionCost} gas ${callWarning}
<td class="${css.td}" data-shared="key_${opts.hash}"> execution cost </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.executionCost} gas ${callWarning}
${copyToClipboard(() => opts.executionCost)}
</td>
</tr>`)
@ -487,8 +487,8 @@ function createTable (opts) {
var hash = yo`
<tr class="${css.tr}">
<td class="${css.td}"> hash </td>
<td class="${css.td}" data-id="txLoggerTableHash${opts.hash}">${opts.hash}
<td class="${css.td}" data-shared="key_${opts.hash}"> hash </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts.hash}
${copyToClipboard(() => opts.hash)}
</td>
</tr>
@ -497,8 +497,8 @@ function createTable (opts) {
var input = yo`
<tr class="${css.tr}">
<td class="${css.td}"> input </td>
<td class="${css.td}" data-id="txLoggerTableInput${opts.hash}">${helper.shortenHexData(opts.input)}
<td class="${css.td}" data-shared="key_${opts.hash}"> input </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${helper.shortenHexData(opts.input)}
${copyToClipboard(() => opts.input)}
</td>
</tr>
@ -508,8 +508,8 @@ function createTable (opts) {
if (opts['decoded input']) {
var inputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded input </td>
<td class="${css.td}" data-id="txLoggerTableDecodedInput${opts.hash}">${opts['decoded input']}
<td class="${css.td}" data-shared="key_${opts.hash}"> decoded input </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${opts['decoded input']}
${copyToClipboard(() => opts['decoded input'])}
</td>
</tr>`
@ -519,8 +519,8 @@ function createTable (opts) {
if (opts['decoded output']) {
var outputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded output </td>
<td class="${css.td}" id="decodedoutput" data-id="txLoggerTableDecodedOutput${opts.hash}">${opts['decoded output']}
<td class="${css.td}" data-shared="key_${opts.hash}"> decoded output </td>
<td class="${css.td}" id="decodedoutput" data-shared="pair_${opts.hash}">${opts['decoded output']}
${copyToClipboard(() => opts['decoded output'])}
</td>
</tr>`
@ -533,8 +533,8 @@ function createTable (opts) {
}
var logs = yo`
<tr class="${css.tr}">
<td class="${css.td}"> logs </td>
<td class="${css.td}" id="logs" data-id="txLoggerTableLogs${opts.hash}">
<td class="${css.td}" data-shared="key_${opts.hash}"> logs </td>
<td class="${css.td}" id="logs" data-shared="pair_${opts.hash}">
${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`
<tr class="${css.tr}">
<td class="${css.td}"> value </td>
<td class="${css.td}" data-id="txLoggerTableValue${opts.hash}">${val} wei
<td class="${css.td}" data-shared="key_${opts.hash}"> value </td>
<td class="${css.td}" data-shared="pair_${opts.hash}">${val} wei
${copyToClipboard(() => `${val} wei`)}
</td>
</tr>

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

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

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

Loading…
Cancel
Save