pull/3598/head
yann300 2 years ago
parent 221d562d7e
commit 55b07e00db
  1. 8
      apps/remix-ide-e2e/src/commands/verifyCallReturnValue.ts
  2. 59
      apps/remix-ide-e2e/src/tests/blockchain.test.ts
  3. 3
      apps/remix-ide-e2e/src/types/index.d.ts

@ -1,5 +1,6 @@
import { NightwatchBrowser } from 'nightwatch'
import EventEmitter from 'events'
import { callbackCheckVerifyCallReturnValue } from '../types/index'
class VerifyCallReturnValue extends EventEmitter {
command (this: NightwatchBrowser, address: string, checks: string[]): NightwatchBrowser {
@ -13,7 +14,7 @@ class VerifyCallReturnValue extends EventEmitter {
}
}
function verifyCallReturnValue (browser: NightwatchBrowser, address: string, checks: string[], done: VoidFunction) {
function verifyCallReturnValue (browser: NightwatchBrowser, address: string, checks: string[] | callbackCheckVerifyCallReturnValue, done: VoidFunction) {
browser.execute(function (address: string) {
const nodes = document.querySelectorAll('#instance' + address + ' [data-id="udapp_value"]') as NodeListOf<HTMLElement>
const ret = []
@ -23,9 +24,14 @@ function verifyCallReturnValue (browser: NightwatchBrowser, address: string, che
}
return ret
}, [address], function (result) {
if (typeof checks === 'function') {
const ret = checks(result.value as string[])
browser.assert.equal(ret.pass, ret.message)
} else {
for (const k in checks) {
browser.assert.equal(result.value[k].trim(), checks[k].trim())
}
}
done()
})
}

@ -0,0 +1,59 @@
'use strict'
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
module.exports = {
'@disabled': true,
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done)
},
'@sources': function () {
return ''
},
'Execute a call that retrieve previous block hashes #group1': function (browser: NightwatchBrowser) {
const code = `
contract A {
function foo(uint p) public view returns(bytes32) {
return blockhash(p);
}
}`
browser.testContracts('test.sol',{ content: code } , ['A'])
.clickLaunchIcon('udapp')
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
.click('.udapp_contractActionsContainerSingle > button')
.clickInstance(0)
.clickFunction('foo - call', { types: 'uint256 p', values: '0' })
.perform((done) => {
browser.getAddressAtPosition(0, (address) => {
browser
.verifyCallReturnValue(address, (values: string[]) => {
// should be looking like: ['0:bytes32: 0x0391a96b0b74805e5fbb79a18840548c5b6c0f1c5e933fc5e3ee015823856e00']
const value = values[0].replace('0:bytes32: ', '')
let pass = value !== '0x0000000000000000000000000000000000000000000000000000000000000000' && value !== '0x'
return {
pass,
message: pass ? 'pass' : 'a non empty blockhash should be returned'
}
})
.perform(done)
})
})
.clickFunction('foo - call', { types: 'uint256 p', values: '1' })
.perform((done) => {
browser.getAddressAtPosition(0, (address) => {
browser
.verifyCallReturnValue(address, (values: string[]) => {
// should be looking like: ['0:bytes32: 0x0391a96b0b74805e5fbb79a18840548c5b6c0f1c5e933fc5e3ee015823856e00']
const value = values[0].replace('0:bytes32: ', '')
let pass = value !== '0x0000000000000000000000000000000000000000000000000000000000000000' && value !== '0x'
return {
pass,
message: pass ? 'pass' : 'a non empty blockhash should be returned'
}
})
.perform(done)
})
}).end()
}
}

@ -1,6 +1,7 @@
// Merge custom command types with nightwatch types
/* eslint-disable no-use-before-define */
import { NightwatchBrowser } from 'nightwatch' // eslint-disable-line @typescript-eslint/no-unused-vars
export type callbackCheckVerifyCallReturnValue = (values: string[]) => { message: string, pass: boolean }
declare module 'nightwatch' {
export interface NightwatchCustomCommands {
@ -41,7 +42,7 @@ declare module 'nightwatch' {
testConstantFunction(address: string, fnFullName: string, expectedInput: NightwatchTestConstantFunctionExpectedInput | null, expectedOutput: string): NightwatchBrowser,
getEditorValue(callback: (content: string) => void): NightwatchBrowser,
getInstalledPlugins(cb: (plugins: string[]) => void): NightwatchBrowser,
verifyCallReturnValue(address: string, checks: string[]): NightwatchBrowser,
verifyCallReturnValue(address: string, checks: string[] | callbackCheckVerifyCallReturnValue): NightwatchBrowser,
testEditorValue(testvalue: string): NightwatchBrowser,
removeFile(path: string, workspace: string): NightwatchBrowser,
switchBrowserWindow(url: string, windowName: string, cb: (browser: NightwatchBrowser, window?: NightwatchCallbackResult<Window>) => void): NightwatchBrowser,

Loading…
Cancel
Save