parent
61f5bd7737
commit
63b075636f
@ -0,0 +1,32 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class CreateContract extends EventEmitter { |
||||
command (this: NightwatchBrowser, inputParams: string): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
createContract(this.api, inputParams, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function createContract (browser: NightwatchBrowser, inputParams: string, callback: VoidFunction) { |
||||
if (inputParams) { |
||||
browser.clickLaunchIcon('settings').clickLaunchIcon('udapp') |
||||
.setValue('div[class^="contractActionsContainerSingle"] input', inputParams, function () { |
||||
browser.click('#runTabView button[class^="instanceButton"]').pause(500).perform(function () { callback() }) |
||||
}) |
||||
} else { |
||||
browser |
||||
.clickLaunchIcon('settings') |
||||
.clickLaunchIcon('udapp') |
||||
.click('#runTabView button[class^="instanceButton"]') |
||||
.pause(500) |
||||
.perform(function () { callback() }) |
||||
} |
||||
} |
||||
|
||||
module.exports = CreateContract |
@ -0,0 +1,29 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class GetAddressAtPosition extends EventEmitter { |
||||
command (this: NightwatchBrowser, index: number, cb: (pos: string) => void): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
getAddressAtPosition(this.api, index, (pos) => { |
||||
done() |
||||
cb(pos) |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function getAddressAtPosition (browser: NightwatchBrowser, index: number, callback: (pos: string) => void) { |
||||
browser.waitForElementPresent('*[data-shared="universalDappUiInstance"]') |
||||
.execute(function (index) { |
||||
const deployedContracts = document.querySelectorAll('*[data-shared="universalDappUiInstance"]') |
||||
const id = deployedContracts[index].getAttribute('id') |
||||
|
||||
return id.replace('instance', '') |
||||
}, [index], function (result) { |
||||
typeof result.value === 'string' && callback(result.value) |
||||
}) |
||||
} |
||||
|
||||
module.exports = GetAddressAtPosition |
@ -0,0 +1,21 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class GetEditorValue extends EventEmitter { |
||||
command (this: NightwatchBrowser, callback: (content: string) => void): NightwatchBrowser { |
||||
this.api.perform((client, done) => { |
||||
this.api.execute(function () { |
||||
const elem: any = document.getElementById('input') |
||||
|
||||
elem.editor.getValue() |
||||
}, [], (result) => { |
||||
done() |
||||
callback(typeof result.value === 'string' ? result.value : '') |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = GetEditorValue |
@ -0,0 +1,23 @@ |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class SelectContract extends EventEmitter { |
||||
command (this: NightwatchBrowser, contractName: string): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
selectContract(this.api, contractName, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function selectContract (browser: NightwatchBrowser, contractName: string, callback: VoidFunction) { |
||||
browser.clickLaunchIcon('settings').clickLaunchIcon('udapp') |
||||
.setValue('#runTabView select[class^="contractNames"]', contractName).perform(() => { |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
module.exports = SelectContract |
@ -0,0 +1,37 @@ |
||||
import { NightwatchBrowser, NightwatchTestConstantFunctionExpectedInput } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class TestConstantFunction extends EventEmitter { |
||||
command (this: NightwatchBrowser, address: string, fnFullName: string, expectedInput: NightwatchTestConstantFunctionExpectedInput | null, expectedOutput: string): NightwatchBrowser { |
||||
console.log('TestConstantFunction ' + address + ' fnFullName') |
||||
this.api.perform((done) => { |
||||
testConstantFunction(this.api, address, fnFullName, expectedInput, expectedOutput, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function testConstantFunction (browser: NightwatchBrowser, address: string, fnFullName: string, expectedInput: NightwatchTestConstantFunctionExpectedInput, expectedOutput: string, cb: VoidFunction) { |
||||
browser.waitForElementPresent('.instance button[title="' + fnFullName + '"]').perform(function (client, done) { |
||||
client.execute(function () { |
||||
document.querySelector('#runTabView').scrollTop = document.querySelector('#runTabView').scrollHeight |
||||
}, [], function () { |
||||
if (expectedInput) { |
||||
client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values) |
||||
} |
||||
done() |
||||
}) |
||||
}) |
||||
.click('.instance button[title="' + fnFullName + '"]') |
||||
.pause(1000) |
||||
.waitForElementPresent('#instance' + address + ' div[class^="contractActionsContainer"] div[class^="value"]') |
||||
.scrollInto('#instance' + address + ' div[class^="contractActionsContainer"] div[class^="value"]') |
||||
.assert.containsText('#instance' + address + ' div[class^="contractActionsContainer"] div[class^="value"]', expectedOutput).perform(() => { |
||||
cb() |
||||
}) |
||||
} |
||||
|
||||
module.exports = TestConstantFunction |
@ -0,0 +1,124 @@ |
||||
'use strict' |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import init from '../helpers/init' |
||||
import sauce from './sauce' |
||||
|
||||
module.exports = { |
||||
before: function (browser: NightwatchBrowser, done: VoidFunction) { |
||||
init(browser, done) |
||||
}, |
||||
|
||||
'@sources': function () { |
||||
return sources |
||||
}, |
||||
|
||||
'Add Lib Test File': function (browser: NightwatchBrowser) { |
||||
browser.addFile('Untitled5.sol', sources[0]['browser/Untitled5.sol']) |
||||
.clickLaunchIcon('udapp') |
||||
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
|
||||
}, |
||||
|
||||
'Test Auto Deploy Lib': function (browser: NightwatchBrowser) { |
||||
let addressRef: string |
||||
browser.verifyContracts(['test']) |
||||
.selectContract('test') |
||||
.createContract('') |
||||
.getAddressAtPosition(0, (address) => { |
||||
console.log('testAutoDeployLib ' + address) |
||||
addressRef = address |
||||
}) |
||||
.waitForElementPresent('.instance:nth-of-type(2)') |
||||
.click('.instance:nth-of-type(2) > div > button') |
||||
.perform((done) => { |
||||
browser.testConstantFunction(addressRef, 'get - call', null, '0:\nuint256: 45').perform(() => { |
||||
done() |
||||
}) |
||||
}) |
||||
}, |
||||
|
||||
'Test Manual Deploy Lib': function (browser: NightwatchBrowser) { |
||||
console.log('testManualDeployLib') |
||||
browser.click('*[data-id="deployAndRunClearInstances"]') |
||||
.pause(5000) |
||||
.clickLaunchIcon('settings') |
||||
.click('#generatecontractmetadata') |
||||
.clickLaunchIcon('solidity') |
||||
.click('#compileTabView button[title="Compile"]') // that should generate the JSON artefact
|
||||
.verifyContracts(['test']) |
||||
.selectContract('lib') // deploy lib
|
||||
.createContract('') |
||||
.perform((done) => { |
||||
browser.getAddressAtPosition(0, (address) => { |
||||
console.log(address) |
||||
checkDeployShouldFail(browser, () => { |
||||
checkDeployShouldSucceed(browser, address, () => { |
||||
done() |
||||
}) |
||||
}) |
||||
}) |
||||
}) |
||||
.end() |
||||
}, |
||||
|
||||
tearDown: sauce |
||||
} |
||||
|
||||
function checkDeployShouldFail (browser: NightwatchBrowser, callback: VoidFunction) { |
||||
let config |
||||
browser.openFile('browser/artifacts').openFile('browser/artifacts/test.json') |
||||
.getEditorValue((content) => { |
||||
config = JSON.parse(content) |
||||
config.deploy['VM:-'].autoDeployLib = false |
||||
}) |
||||
.perform(() => { |
||||
browser.setEditorValue(JSON.stringify(config)) |
||||
}) |
||||
.openFile('browser/Untitled5.sol') |
||||
.selectContract('test') // deploy lib
|
||||
.createContract('') |
||||
.assert.containsText('div[class^="terminal"]', '<address> is not a valid address') |
||||
.perform(() => { callback() }) |
||||
} |
||||
|
||||
function checkDeployShouldSucceed (browser: NightwatchBrowser, address: string, callback: VoidFunction) { |
||||
let addressRef: string |
||||
let config |
||||
browser.openFile('browser/artifacts').openFile('browser/artifacts/test.json') |
||||
.getEditorValue((content) => { |
||||
config = JSON.parse(content) |
||||
config.deploy['VM:-'].autoDeployLib = false |
||||
config.deploy['VM:-']['linkReferences']['browser/Untitled5.sol'].lib = address |
||||
}) |
||||
.perform(() => { |
||||
browser.setEditorValue(JSON.stringify(config)) |
||||
}) |
||||
.openFile('browser/Untitled5.sol') |
||||
.selectContract('test') // deploy lib
|
||||
.createContract('') |
||||
.getAddressAtPosition(1, (address) => { |
||||
addressRef = address |
||||
}) |
||||
.waitForElementPresent('.instance:nth-of-type(3)') |
||||
.click('.instance:nth-of-type(3) > div > button') |
||||
.perform(() => { |
||||
browser |
||||
.testConstantFunction(addressRef, 'get - call', null, '0:\nuint256: 45') |
||||
.perform(() => { callback() }) |
||||
}) |
||||
} |
||||
|
||||
const sources = [ |
||||
{ |
||||
'browser/Untitled5.sol': {content: `library lib {
|
||||
function getInt () public view returns (uint) { |
||||
return 45; |
||||
} |
||||
} |
||||
|
||||
contract test { |
||||
function get () public view returns (uint) { |
||||
return lib.getInt(); |
||||
} |
||||
}`}
|
||||
} |
||||
] |
Loading…
Reference in new issue