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 0cebb4ba5e..5add4d96b6 100644 --- a/test-browser/tests/ballot.js +++ b/test-browser/tests/ballot.js @@ -55,6 +55,7 @@ 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"'}) @@ -64,6 +65,19 @@ 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) {