Updated transaction execution test with improved testFunction

pull/5370/head
ioedeveloper 5 years ago committed by yann300
parent cf2632c3b7
commit dd9b0ba8cc
  1. 2
      src/app/panels/terminal.js
  2. 2
      src/app/tabs/runTab/contractDropdown.js
  3. 2
      src/app/tabs/runTab/settings.js
  4. 3
      src/app/ui/universal-dapp-ui.js
  5. 25
      test-browser/commands/testFunction.js
  6. 40
      test-browser/tests/ballot.js
  7. 92
      test-browser/tests/transactionExecution.js

@ -165,7 +165,7 @@ class Terminal extends Plugin {
${self._view.dragbar}
<div class="${css.menu} border-top border-dark bg-light" data-id="terminalToggleMenu">
${self._view.icon}
<div class=${css.clear} id="clearConsole" onclick=${clear}>
<div class=${css.clear} id="clearConsole" data-id="terminalClearConsole" onclick=${clear}>
<i class="fas fa-ban" aria-hidden="true" title="Clear console"
onmouseenter=${hover} onmouseleave=${hover}></i>
</div>

@ -54,7 +54,7 @@ class ContractDropdownUI {
this.createPanel = yo`<div class="${css.deployDropdown}"></div>`
this.orLabel = yo`<div class="${css.orLabel}">or</div>`
let el = yo`
<div class="${css.container}">
<div class="${css.container}" data-id="contractDropdownContainer">
<label class="${css.settingsLabel}">Contract</label>
<div class="${css.subcontainer}">
${this.selectContractNames} ${this.compFails} ${info}

@ -69,7 +69,7 @@ class SettingsUI {
title="Execution environment has been provided by Metamask or similar provider."
value="injected" name="executionContext"> Injected Web3
</option>
<option id="web3-mode"
<option id="web3-mode" data-id="settingsWeb3Mode"
title="Execution environment connects to node at localhost (or via IPC if available), transactions will be sent to the network and can cause loss of money or worse!
If this page is served via https and you access your node via http, it might not work. In this case, try cloning the repository and serving it via http."
value="web3" name="executionContext"> Web3 Provider

@ -79,6 +79,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
var close = yo`
<button
class="${css.udappClose} p-1 btn btn-secondary"
data-id="universalDappUiUdappClose"
onclick=${remove}
title="Remove from the list"
>
@ -87,7 +88,7 @@ UniversalDAppUI.prototype.renderInstanceFromABI = function (contractABI, address
title.querySelector('.btn-group').appendChild(close)
var contractActionsWrapper = yo`
<div class="${css.cActionsWrapper}">
<div class="${css.cActionsWrapper}" data-id="universalDappUiContractActionWrapper">
</div>
`

@ -2,25 +2,12 @@ const EventEmitter = require('events')
const deepequal = require('deep-equal')
class TestFunction extends EventEmitter {
command (fnFullName, txHash, expectedReturn, input) {
command (txHash, expectedValue) {
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}"]`)
browser.waitForElementVisible(`*[data-id="txLogger${txHash}"]`)
.click(`*[data-id="txLogger${txHash}"]`)
.waitForElementVisible(`*[data-id="txLoggerTable${txHash}"]`)
.click(`*[data-id="txLoggerTable${txHash}"]`)
@ -55,13 +42,13 @@ class TestFunction extends EventEmitter {
})
browser.perform(() => {
Object.keys(expectedReturn).forEach(key => {
const equal = deepequal(logs[key], expectedReturn[key])
Object.keys(expectedValue).forEach(key => {
const equal = deepequal(logs[key], expectedValue[key])
if (!equal) {
browser.assert.fail(`Expected ${expectedReturn[key]} but got ${logs[key]}`)
browser.assert.fail(`Expected ${expectedValue[key]} but got ${logs[key]}`)
}else{
browser.assert.ok(true, `Expected value matched returned value ${expectedReturn[key]}`)
browser.assert.ok(true, `Expected value matched returned value ${expectedValue[key]}`)
}
})
this.emit('complete')

@ -23,25 +23,23 @@ module.exports = {
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c')
.setValue('input[placeholder="bytes32[] proposalNames"]', '["0x48656c6c6f20576f726c64210000000000000000000000000000000000000000"]')
.click('*[data-id="Deploy - transact (not payable)"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.waitForElementPresent('*[data-id="universalDappUiContractActionWrapper"]')
.click('*[data-id="universalDappUiTitleExpander"]')
.testFunction(
'delegate - transact (not payable)',
'0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3',
.clickFunction('delegate - transact (not payable)', {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'})
.testFunction('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) {
browser.pause(500)
.click('span#tx0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3 button[class^="debug"]')
.click('*[data-id="txLoggerDebugButton0x41fab8ea5b1d9fba5e0a6545ca1a2d62fff518578802c033c2b9a031a01c31b3"]')
.pause(2000)
.clickLaunchIcon('debugger')
.click('#jumppreviousbreakpoint')
.click('*[data-id="buttonNavigatorJumpPreviousBreakpoint"]')
.pause(2000)
.goToVMTraceStep(79)
.pause(1000)
@ -51,36 +49,34 @@ module.exports = {
'Access Ballot via at address': function (browser) {
browser.clickLaunchIcon('udapp')
.click('button[class^="udappClose"]')
.click('*[data-id="universalDappUiUdappClose"]')
.addFile('ballot.abi', { content: ballotABI })
.addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3B', true, false)
.clickLaunchIcon('fileExplorers')
.addAtAddressInstance('0x692a70D2e424a56D2C6C27aA97D1a86395877b3A', true, true)
.pause(500)
.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' ]
}
.waitForElementPresent('*[data-id="universalDappUiContractActionWrapper"]')
.click('*[data-id="universalDappUiTitleExpander"]')
.clickFunction('delegate - transact (not payable)', {types: 'address to', values: '"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db"'})
.testFunction('0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803',
{
status: '0x0 Transaction mined but execution failed',
'transaction hash': '0xca58080c8099429caeeffe43b8104df919c2c543dceb9edf9242fa55f045c803',
'decoded input': { 'address to': '0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB' }
})
},
'Deploy and use Ballot using external web3': function (browser) {
browser
.click('#selectExEnvOptions #web3-mode')
.click('*[data-id="settingsWeb3Mode"]')
.modalFooterOKClick()
.clickLaunchIcon('solidity')
.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['Ballot'])
.clickLaunchIcon('udapp')
.setValue('input[placeholder="bytes32[] proposalNames"]', '["0x48656c6c6f20576f726c64210000000000000000000000000000000000000000"]')
.click('#runTabView button[class^="instanceButton"]')
.click('*[data-id="Deploy - transact (not payable)"]')
.clickInstance(0)
.click('#clearConsole')
.click('*[data-id="terminalClearConsole"]')
.clickFunction('delegate - transact (not payable)', {types: 'address to', values: '0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'})
.journalLastChildIncludes('Ballot.delegate(address)')
.journalLastChildIncludes('data:0x5c1...a733c')

@ -19,22 +19,27 @@ module.exports = {
.click('.instance:nth-of-type(2) > div > button')
.click('#runTabView .instance div[class^="title"]')
.click('#runTabView .instance div[class^="title"]')
.testFunction('f - transact (not payable)',
'0x38bb944fa4709ed9e163d6c670259f97284b4defd916d512a2fcc3f35bb53e03',
`[vm]\nfrom:0xca3...a733c\nto:TestContract.f() 0x692...77b3a\nvalue:0 wei\ndata:0x261...21ff0\nlogs:0\nhash:0x38b...53e03`, null,
`{
"0": "uint256: 8"
}`)
.clickFunction('f - transact (not payable)')
.testFunction('0x38bb944fa4709ed9e163d6c670259f97284b4defd916d512a2fcc3f35bb53e03',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0x38bb944fa4709ed9e163d6c670259f97284b4defd916d512a2fcc3f35bb53e03',
'decoded output': { "0": "uint256: 8" }
})
.pause(500)
.checkTerminalFilter('0x12332162e2e31397dc1e07ed0a1cf08f728e9b4487c6f9ed79d2f39410c92782', '')
.testFunction('g - transact (not payable)',
'0xab4f794ca0b531f27fc6eace623666b440facbf20e77615a057d728c67b500f0',
`[vm]\nfrom:0xca3...a733c\nto:TestContract.g() 0x692...77b3a\nvalue:0 wei\ndata:0xe21...79b8e\nlogs:0\nhash:0xab4...500f0`, null, `{
.clickFunction('g - transact (not payable)')
.testFunction('0xab4f794ca0b531f27fc6eace623666b440facbf20e77615a057d728c67b500f0',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0xab4f794ca0b531f27fc6eace623666b440facbf20e77615a057d728c67b500f0',
'decoded output': {
"0": "uint256: 345",
"1": "string: comment_comment_",
"2": "bool: true",
"3": "uint256: 4"
}`)
}
})
.click('i[class^="clearinstance"]')
},
@ -44,19 +49,24 @@ module.exports = {
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
.testFunction('retunValues1 - transact (not payable)',
'0x09c6716a67f0f8c7a0ca2b3ddf59c25982da856a95aefd640b767f9b9feee39d',
`[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues1() 0x5e7...26e9f\nvalue:0 wei\ndata:0x9ed...59eb7\nlogs:0\nhash:0x09c...ee39d`,
null,
`{
.clickFunction('retunValues1 - transact (not payable)')
.testFunction('0x09c6716a67f0f8c7a0ca2b3ddf59c25982da856a95aefd640b767f9b9feee39d',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0x09c6716a67f0f8c7a0ca2b3ddf59c25982da856a95aefd640b767f9b9feee39d',
'decoded output': {
"0": "bool: _b true",
"1": "uint256: _u 345",
"2": "int256: _i -345",
"3": "address: _a 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"
}`)
.testFunction('retunValues2 - transact (not payable)',
'0xe884953e0695399d60914af3e1ea2dad59fe41f3c0c20665c130fa40dd0fb6bf',
`[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues2() 0x5e7...26e9f\nvalue:0 wei\ndata:0xf57...4036c\nlogs:0\nhash:0xe88...fb6bf`, null, `{
}
})
.clickFunction('retunValues2 - transact (not payable)', )
.testFunction('0xe884953e0695399d60914af3e1ea2dad59fe41f3c0c20665c130fa40dd0fb6bf',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0xe884953e0695399d60914af3e1ea2dad59fe41f3c0c20665c130fa40dd0fb6bf',
'decoded output': {
"0": "bytes1: _b 0x12",
"1": "bytes2: _b2 0x1223",
"2": "bytes3: _b3 0x000000",
@ -67,12 +77,18 @@ module.exports = {
"7": "bytes7: _b7 0x03252353253253",
"8": "bytes22: _b22 0x32523523532532532523532500000000000000000000",
"9": "bytes32: _b32 0x0325235325325235325235325235320000000000000000000000000000000000"
}`).pause(500).testFunction('retunValues3 - transact (not payable)',
'0xb4108649d5e65a4a0776d6ac98c2c356540a7e99d641705a82352a845d467eb5',
'[vm]\nfrom:0xca3...a733c\nto:testReturnValues.retunValues3() 0x5e7...26e9f\nvalue:0 wei\ndata:0x033...e0a7d\nlogs:0\nhash:0xb41...67eb5', null, `{
}
}).pause(500)
.clickFunction('retunValues3 - transact (not payable)')
.testFunction('0xb4108649d5e65a4a0776d6ac98c2c356540a7e99d641705a82352a845d467eb5',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0xb4108649d5e65a4a0776d6ac98c2c356540a7e99d641705a82352a845d467eb5',
'decoded output': {
"0": "uint8: _en 2",
"1": "int256[5][]: _a1 1,-45,-78,56,60,-1,42,334,-45455,-446,1,10,-5435,45,-7"
}`).click('i[class^="clearinstance"]')
}
}).click('i[class^="clearinstance"]')
},
'Test Complex Input Values': function (browser) {
@ -81,24 +97,27 @@ module.exports = {
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
.testFunction('inputValue1 - transact (not payable)',
'0xe9678b5486674a0425301a1d7e925c22cfb9f7f7ec6242697d742009f7ef5b97',
`[vm]\nfrom:0xca3...a733c\nto:test.inputValue1(uint256,int256,string) 0x8c1...401f5\nvalue:0 wei\ndata:0xd69...00000\nlogs:0\nhash:0xe96...f5b97`,
{types: 'uint256 _u, int256 _i, string _str', values: '"2343242", "-4324324", "string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"'},
`{
.clickFunction('inputValue1 - transact (not payable)', {types: 'uint256 _u, int256 _i, string _str', values: '"2343242", "-4324324", "string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"'})
.testFunction('0xe9678b5486674a0425301a1d7e925c22cfb9f7f7ec6242697d742009f7ef5b97',
{
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0xe9678b5486674a0425301a1d7e925c22cfb9f7f7ec6242697d742009f7ef5b97',
'decoded output': {
"0": "uint256: _uret 2343242",
"1": "int256: _iret -4324324",
"2": "string: _strret string _ string _ string _ string _ string _ string _ string _ string _ string _ string _"
}`)
}
})
.pause(500)
.testFunction('inputValue2 - transact (not payable)',
'0x21724b08c3699bda8375803f8dc842194aea370f2aac284e55144b452dca321f',
`[vm]\nfrom:0xca3...a733c\nto:test.inputValue2(uint256[3],bytes8[4]) 0x8c1...401f5\nvalue:0 wei\ndata:0x1b7...00000\nlogs:1\nhash:0x217...a321f`,
{types: 'uint256[3] _n, bytes8[4] _b8', values: '[1,2,3], ["0x1234000000000000", "0x1234000000000000","0x1234000000000000","0x1234000000000000"]'},
`{
.clickFunction('inputValue2 - transact (not payable)', {types: 'uint256[3] _n, bytes8[4] _b8', values: '[1,2,3], ["0x1234000000000000", "0x1234000000000000","0x1234000000000000","0x1234000000000000"]'})
.testFunction('0x21724b08c3699bda8375803f8dc842194aea370f2aac284e55144b452dca321f', {
status: '0x1 Transaction mined and execution succeed',
'transaction hash': '0x21724b08c3699bda8375803f8dc842194aea370f2aac284e55144b452dca321f',
'decoded output': {
"0": "uint256[3]: _nret 1,2,3",
"1": "bytes8[4]: _b8ret 0x1234000000000000,0x1234000000000000,0x1234000000000000,0x1234000000000000"
}`, `[
},
logs: [
{
"from": "0x8c1ed7e19abaa9f23c476da86dc1577f1ef401f5",
"topic": "0xd30981760edbf605bda8689e945f622877f230c9a77cbfbd448aa4b7d8ac6e7f",
@ -123,7 +142,8 @@ module.exports = {
"length": 5
}
}
]`)
]
})
.click('i[class^="clearinstance"]')
.end()
},

Loading…
Cancel
Save