You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
71 lines
2.5 KiB
5 years ago
|
import { NightwatchBrowser, NightwatchVerifyContractOpts, NightwatchCallbackResult } from 'nightwatch'
|
||
|
|
||
|
const EventEmitter = require('events')
|
||
|
|
||
|
export class VerifyContracts extends EventEmitter {
|
||
|
command (this: NightwatchBrowser,compiledContractNames: string[], opts = { wait: 1000, version: null }): NightwatchBrowser {
|
||
|
this.api.perform((done: VoidFunction) => {
|
||
|
verifyContracts(this.api, compiledContractNames, opts, () => {
|
||
|
done()
|
||
|
this.emit('complete')
|
||
|
})
|
||
|
})
|
||
|
return this
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getCompiledContracts (browser: NightwatchBrowser, opts: NightwatchVerifyContractOpts, callback: CallableFunction) {
|
||
|
browser
|
||
|
.clickLaunchIcon('solidity')
|
||
|
.pause(opts.wait)
|
||
|
.waitForElementPresent('*[data-id="compiledContracts"] option')
|
||
|
.perform((done: VoidFunction) => {
|
||
|
if (opts.version) {
|
||
|
browser
|
||
|
.click('*[data-id="compilation-details"]')
|
||
|
.waitForElementVisible('*[data-id="treeViewDivcompiler"]')
|
||
|
.pause(2000)
|
||
|
.click('*[data-id="treeViewDivcompiler"]')
|
||
|
.waitForElementVisible('*[data-id="treeViewLicompiler/version"]')
|
||
|
.assert.containsText('*[data-id="treeViewLicompiler/version"]', `version:\n ${opts.version}`)
|
||
|
.perform(done)
|
||
|
} else done()
|
||
|
})
|
||
|
.execute(function () {
|
||
|
const contracts = document.querySelectorAll('*[data-id="compiledContracts"] option') as NodeListOf<HTMLInputElement>
|
||
|
|
||
|
if (!contracts) {
|
||
|
return null
|
||
|
} else {
|
||
|
const ret = []
|
||
|
|
||
|
for (let c = 0; c < contracts.length; c++) {
|
||
|
ret.push(contracts[c].value)
|
||
|
}
|
||
|
return ret
|
||
|
}
|
||
|
}, [], function (result) {
|
||
|
callback(result)
|
||
|
})
|
||
|
}
|
||
|
|
||
|
function verifyContracts (browser: NightwatchBrowser, compiledContractNames: string[], opts: NightwatchVerifyContractOpts, callback: VoidFunction) {
|
||
|
getCompiledContracts(browser, opts, (result: NightwatchCallbackResult<any>) => {
|
||
|
if (result.value) {
|
||
|
for (const contract in compiledContractNames) {
|
||
|
console.log(' - ' + compiledContractNames[contract], result.value)
|
||
|
if (result.value.indexOf(compiledContractNames[contract]) === -1) {
|
||
|
browser.assert.fail('compiled contract ' + compiledContractNames + ' not found', 'info about error', '')
|
||
|
browser.end()
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
} else {
|
||
|
browser.assert.fail('compiled contract ' + compiledContractNames + ' not found - none found', 'info about error', '')
|
||
|
browser.end()
|
||
|
}
|
||
|
console.log('contracts all found ' + compiledContractNames)
|
||
|
callback()
|
||
|
})
|
||
|
}
|