add test recorder

pull/3094/head
yann300 7 years ago
parent 98b1890077
commit c9538c0dfb
  1. 4
      src/app/tabs/run-tab.js
  2. 4
      src/universal-dapp.js
  3. 56
      test-browser/helpers/contracts.js
  4. 4
      test-browser/tests/compiling.js
  5. 118
      test-browser/tests/units/testRecorder.js

@ -269,8 +269,8 @@ function makeRecorder (appAPI, appEvents) {
width: 135px;
}
`
var recordButton = yo`<button class=${css.transaction}>save transactions</button>`
var runButton = yo`<button class=${css.transaction}>run transactions</button>`
var recordButton = yo`<button class="${css.transaction} savetransaction">save transactions</button>`
var runButton = yo`<button class="${css.transaction} runtransaction">run transactions</button>`
var el = yo`
<div class=${css2.container}>
${recordButton}

@ -290,10 +290,10 @@ UniversalDApp.prototype.renderInstanceFromABI = function (contractABI, address,
function remove () { instance.remove() }
var instance = yo`<div class="instance ${css.instance}"></div>`
address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex')
var instance = yo`<div class="instance ${css.instance}" id="instance${address}"></div>`
var context = executionContext.isVM() ? 'memory' : 'blockchain'
address = (address.slice(0, 2) === '0x' ? '' : '0x') + address.toString('hex')
var shortAddress = helper.shortenAddress(address)
var title = yo`<div class="${css.title}" onclick=${toggleClass}>
<div class="${css.titleText}"> ${contractName} at ${shortAddress} (${context}) </div>

@ -11,7 +11,9 @@ module.exports = {
checkDebug,
goToVMtraceStep,
useFilter,
addInstance
addInstance,
clickFunction,
verifyCallReturnValue
}
function getCompiledContracts (browser, compiled, callback) {
@ -65,6 +67,46 @@ function testContracts (browser, fileName, contractCode, compiledContractNames,
})
}
function clickFunction (fnFullName, expectedInput) {
this.waitForElementPresent('.instance button[title="' + fnFullName + '"]')
.perform(function (client, done) {
client.execute(function () {
document.querySelector('#optionViews').scrollTop = document.querySelector('#optionViews').scrollHeight
}, [], function () {
if (expectedInput) {
client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, function () {})
}
done()
})
})
.click('.instance button[title="' + fnFullName + '"]')
.pause(500)
return this
}
function verifyCallReturnValue (browser, address, checks, done) {
browser.execute(function (address, checks) {
var nodes = document.querySelectorAll('#instance' + address + ' div[class^="contractProperty"] div[class^="value"]')
var ret = {sucess: true}
for (var k in checks) {
var text = nodes[k].innerText ? nodes[k].innerText : nodes[k].textContent
text = text.replace('\n', '')
if (checks[k] !== text) {
ret.sucess = false
ret.expected = checks[k]
ret.got = text
return ret
}
}
return ret
}, [address, checks], function (result) {
if (!result.value.sucess) {
browser.assert.fail('verifyCallReturnValue failed', JSON.stringify(result.value), '')
}
done()
})
}
function testFunction (fnFullName, txHash, log, expectedInput, expectedReturn, expectedEvent) {
// this => browser
this.waitForElementPresent('.instance button[title="' + fnFullName + '"]')
@ -101,13 +143,13 @@ function testFunction (fnFullName, txHash, log, expectedInput, expectedReturn, e
function addInstance (browser, address, done) {
browser.setValue('.ataddressinput', address, function () {
browser.click('div[class^="atAddress"]')
.perform((client) => {
browser.execute(function () {
document.querySelector('#modal-footer-ok').click()
}, [], function (result) {
done()
.perform((client) => {
browser.execute(function () {
document.querySelector('#modal-footer-ok').click()
}, [], function (result) {
done()
})
})
})
})
}

@ -3,6 +3,7 @@ var contractHelper = require('../helpers/contracts')
var init = require('../helpers/init')
var sauce = require('./sauce')
var async = require('async')
var testRecorder = require('./units/testRecorder')
module.exports = {
before: function (browser, done) {
@ -19,12 +20,13 @@ module.exports = {
function runTests (browser) {
browser.testFunction = contractHelper.testFunction
browser.clickFunction = contractHelper.clickFunction
browser
.waitForElementVisible('.newFile', 10000)
.click('.compileView')
.perform(() => {
// the first fn is used to pass browser to the other ones.
async.waterfall([function (callback) { callback(null, browser) }, testSimpleContract, testReturnValues, testInputValues], function () {
async.waterfall([function (callback) { callback(null, browser) }, testSimpleContract, testReturnValues, testInputValues, testRecorder], function () {
browser.end()
})
})

@ -0,0 +1,118 @@
'use strict'
var contractHelper = require('../../helpers/contracts')
module.exports = function (browser, callback) {
contractHelper.addFile(browser, 'scenario.json', {content: records}, () => {
browser
.click('.runView')
.click('#runTabView .runtransaction')
.clickFunction('getInt - call')
.clickFunction('getAddress - call')
.waitForElementPresent('div[class^="contractProperty"] div[class^="value"]')
.perform(() => {
contractHelper.verifyCallReturnValue(browser, '0xec5bee2dbb67da8757091ad3d9526ba3ed2e2137', ['0: uint256: 1', '0: address: 0xca35b7d915458ef540ade6068dfe2f44e8fa733c'], () => { callback() })
})
})
}
var records = `{
"accounts": {
"account{0}": "0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
},
"transactions": [
{
"timestamp": 1512661974836,
"record": {
"value": "0",
"parameters": [
23
],
"abi": "0xe8e77626586f73b955364c7b4bbf0bb7f7685ebd40e852b164633a4acbd3244c",
"contractName": "test",
"bytecode": "6060604052341561000f57600080fd5b6040516020806102098339810160405280805190602001909190505080600081905550506101c7806100426000396000f300606060405260043610610057576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632f30c6f61461005c57806338cc48311461009e57806362738998146100f3575b600080fd5b341561006757600080fd5b61009c600480803590602001909190803573ffffffffffffffffffffffffffffffffffffffff1690602001909190505061011c565b005b34156100a957600080fd5b6100b1610168565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156100fe57600080fd5b610106610192565b6040518082815260200191505060405180910390f35b8160008190555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b600080549050905600a165627a7a7230582021de204df5493bae860efacfbdea0118cbb3d73760ad48ee0838d07d37fe3c9e0029",
"linkReferences": {},
"name": "",
"type": "constructor",
"from": "account{0}"
}
},
{
"timestamp": 1512661987446,
"record": {
"value": "0",
"parameters": [
1,
"0xca35b7d915458ef540ade6068dfe2f44e8fa733c"
],
"to": "created-contract{1512661974836}",
"abi": "0xe8e77626586f73b955364c7b4bbf0bb7f7685ebd40e852b164633a4acbd3244c",
"name": "set",
"type": "function",
"from": "account{0}"
}
}
],
"linkReferences": {},
"abis": {
"0xe8e77626586f73b955364c7b4bbf0bb7f7685ebd40e852b164633a4acbd3244c": [
{
"constant": true,
"inputs": [],
"name": "getInt",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getAddress",
"outputs": [
{
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_t",
"type": "uint256"
},
{
"name": "_add",
"type": "address"
}
],
"name": "set",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"name": "_r",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "constructor"
}
]
}
}`
Loading…
Cancel
Save