parent
e7df29cbd7
commit
9806a205d4
@ -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 |
Loading…
Reference in new issue