commit
eb48c2eb69
@ -0,0 +1,14 @@ |
||||
{ |
||||
"rules": {}, |
||||
"overrides": [ |
||||
{ |
||||
"files": ["**/*.ts"], |
||||
"rules": { |
||||
"no-undef": "off", |
||||
"@typescript-eslint/no-var-requires": 0 |
||||
} |
||||
} |
||||
], |
||||
"extends": ["../../.eslintrc"], |
||||
"ignorePatterns": ["!**/*"] |
||||
} |
@ -0,0 +1,39 @@ |
||||
import { NightwatchBrowser, NightwatchContractContent } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class AddFile extends EventEmitter { |
||||
command (this: NightwatchBrowser, name: string, content: NightwatchContractContent): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
addFile(this.api, name, content, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function addFile (browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) { |
||||
browser.clickLaunchIcon('udapp').clickLaunchIcon('fileExplorers').click('.newFile') |
||||
.waitForElementVisible('#modal-dialog') |
||||
.perform((client, done) => { |
||||
browser.execute(function (fileName) { |
||||
if (fileName !== 'Untitled.sol') { |
||||
document.querySelector('#modal-dialog #prompt_text').setAttribute('value', fileName) |
||||
} |
||||
const elem = document.querySelector('#modal-footer-ok') as HTMLElement |
||||
|
||||
elem.click() |
||||
}, [name], function (result) { |
||||
console.log(result) |
||||
done() |
||||
}) |
||||
}) |
||||
.setEditorValue(content.content) |
||||
.pause(1000) |
||||
.perform(function () { |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = AddFile |
@ -0,0 +1,31 @@ |
||||
import EventEmitter from 'events' |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
|
||||
class checkElementStyle extends EventEmitter { |
||||
command (this: NightwatchBrowser, cssSelector: string, styleProperty: string, expectedResult: string): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
checkStyle(this.api, cssSelector, styleProperty, expectedResult, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function checkStyle (browser: NightwatchBrowser, cssSelector: string, styleProperty: string, expectedResult: string, callback: VoidFunction) { |
||||
browser.execute(function (cssSelector, styleProperty) { |
||||
return window.getComputedStyle(document.querySelector(cssSelector)).getPropertyValue(styleProperty) |
||||
}, [cssSelector, styleProperty], function (result) { |
||||
const value = result.value |
||||
|
||||
if (typeof value === 'string') { |
||||
browser.assert.equal(value.trim().toLowerCase(), expectedResult.toLowerCase()) |
||||
} else { |
||||
browser.assert.fail('Failed with error info :', result.value.toString()) |
||||
} |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
module.exports = checkElementStyle |
@ -0,0 +1,42 @@ |
||||
import { NightwatchBrowser, NightwatchCheckVariableDebugValue } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
const deepequal = require('deep-equal') |
||||
|
||||
class CheckVariableDebug extends EventEmitter { |
||||
command (this: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
checkDebug(this.api, id, debugValue, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function checkDebug (browser: NightwatchBrowser, id: string, debugValue: NightwatchCheckVariableDebugValue, done: VoidFunction) { |
||||
// id is soliditylocals or soliditystate
|
||||
browser.execute(function (id: string) { |
||||
const elem = document.querySelector('#' + id + ' .dropdownrawcontent') as HTMLElement |
||||
|
||||
return elem.innerText |
||||
}, [id], function (result) { |
||||
console.log(id + ' ' + result.value) |
||||
let value |
||||
try { |
||||
value = JSON.parse(<string>result.value) |
||||
} catch (e) { |
||||
browser.assert.fail('cant parse solidity state', e.message, '') |
||||
done() |
||||
return |
||||
} |
||||
const equal = deepequal(debugValue, value) |
||||
if (!equal) { |
||||
browser.assert.fail('checkDebug on ' + id, 'info about error\n ' + JSON.stringify(debugValue) + '\n ' + JSON.stringify(value), '') |
||||
} |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = CheckVariableDebug |
@ -0,0 +1,27 @@ |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from 'events' |
||||
|
||||
class ClickElement extends EventEmitter { |
||||
command (this: NightwatchBrowser, cssSelector: string, index = 0): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
_clickElement(this.api, cssSelector, index, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function _clickElement (browser: NightwatchBrowser, cssSelector: string, index: number, cb: VoidFunction) { |
||||
browser.waitForElementPresent(cssSelector) |
||||
.execute(function (cssSelector: string, index: number) { |
||||
const elem = document.querySelectorAll(cssSelector)[index] as HTMLElement |
||||
|
||||
elem.click() |
||||
}, [cssSelector, index], function () { |
||||
cb() |
||||
}) |
||||
} |
||||
|
||||
module.exports = ClickElement |
@ -1,14 +1,15 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser, NightwatchClickFunctionExpectedInput } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class ClickFunction extends EventEmitter { |
||||
command (fnFullName, expectedInput) { |
||||
command (this: NightwatchBrowser, fnFullName: string, expectedInput?: NightwatchClickFunctionExpectedInput): NightwatchBrowser { |
||||
this.api.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, function () {}) |
||||
client.setValue('#runTabView input[title="' + expectedInput.types + '"]', expectedInput.values, _ => _) |
||||
} |
||||
done() |
||||
}) |
@ -1,9 +1,11 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class ClickInstance extends EventEmitter { |
||||
command (index) { |
||||
command (this: NightwatchBrowser, index: number): NightwatchBrowser { |
||||
index = index + 2 |
||||
let selector = '.instance:nth-of-type(' + index + ') > div > button' |
||||
const selector = '.instance:nth-of-type(' + index + ') > div > button' |
||||
|
||||
this.api.waitForElementPresent(selector).scrollAndClick(selector).perform(() => { this.emit('complete') }) |
||||
return this |
||||
} |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class ClickLaunchIcon extends EventEmitter { |
||||
command (icon) { |
||||
command (this: NightwatchBrowser, icon: string): NightwatchBrowser { |
||||
this.api.waitForElementVisible('#icon-panel div[plugin="' + icon + '"]').click('#icon-panel div[plugin="' + icon + '"]').perform((done) => { |
||||
done() |
||||
this.emit('complete') |
@ -1,8 +1,9 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
// fix for editor scroll
|
||||
class ScrollEditor extends EventEmitter { |
||||
command (direction, numberOfTimes) { |
||||
command (this: NightwatchBrowser, direction: 'up' | 'down', numberOfTimes: number): NightwatchBrowser { |
||||
const browser = this.api |
||||
|
||||
browser.waitForElementPresent('.ace_text-input') |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class ExecuteScript extends EventEmitter { |
||||
command (script) { |
||||
command (this: NightwatchBrowser, script: string): NightwatchBrowser { |
||||
this.api |
||||
.clearEditableContent('*[data-id="terminalCliInput"]') |
||||
.click('*[data-id="terminalCli"]') |
@ -0,0 +1,23 @@ |
||||
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') |
||||
|
||||
return elem.editor.getValue() |
||||
}, [], (result) => { |
||||
done() |
||||
const value = typeof result.value === 'string' ? result.value : null |
||||
|
||||
callback(value) |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = GetEditorValue |
@ -0,0 +1,19 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class GetModalBody extends EventEmitter { |
||||
command (this: NightwatchBrowser, callback: (value: string, cb: VoidFunction) => void) { |
||||
this.api.waitForElementVisible('.modal-body') |
||||
.getText('.modal-body', (result) => { |
||||
console.log(result) |
||||
const value = typeof result.value === 'string' ? result.value : null |
||||
|
||||
callback(value, () => { |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = GetModalBody |
@ -1,21 +1,22 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
/* |
||||
Checks if any child elements of journal (console) contains a matching value. |
||||
*/ |
||||
class JournalChildIncludes extends EventEmitter { |
||||
command (val) { |
||||
command (this: NightwatchBrowser, val: string): NightwatchBrowser { |
||||
let isTextFound = false |
||||
const browser = this.api |
||||
|
||||
this.api.elements('css selector', '*[data-id="terminalJournal"]', (res) => { |
||||
res.value.forEach(function (jsonWebElement) { |
||||
Array.isArray(res.value) && res.value.forEach(function (jsonWebElement) { |
||||
const jsonWebElementId = jsonWebElement.ELEMENT || jsonWebElement[Object.keys(jsonWebElement)[0]] |
||||
|
||||
browser.elementIdText(jsonWebElementId, (jsonElement) => { |
||||
const text = jsonElement.value |
||||
|
||||
if (text.indexOf(val) !== -1) isTextFound = true |
||||
if (typeof text === 'string' && text.indexOf(val) !== -1) isTextFound = true |
||||
}) |
||||
}) |
||||
}) |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class JournalLastChild extends EventEmitter { |
||||
command (val) { |
||||
command (this: NightwatchBrowser, val: string): NightwatchBrowser { |
||||
this.api |
||||
.waitForElementVisible('*[data-id="terminalJournal"] > div:last-child', 10000) |
||||
.assert.containsText('*[data-id="terminalJournal"] > div:last-child', val).perform(() => { |
@ -1,16 +1,17 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
/* |
||||
Check if the last log in the console contains a specific text |
||||
*/ |
||||
class JournalLastChildIncludes extends EventEmitter { |
||||
command (val) { |
||||
command (this: NightwatchBrowser, val: string): NightwatchBrowser { |
||||
this.api |
||||
.waitForElementVisible('*[data-id="terminalJournal"] > div:last-child', 10000) |
||||
.getText('*[data-id="terminalJournal"] > div:last-child', (result) => { |
||||
console.log('JournalLastChildIncludes', result.value) |
||||
if (result.value.indexOf(val) === -1) return this.api.assert.fail(`wait for ${val} in ${result.value}`) |
||||
else this.api.assert.ok(`<*[data-id="terminalJournal"] > div:last-child> contains ${val}.`) |
||||
if (typeof result.value === 'string' && result.value.indexOf(val) === -1) return this.api.assert.fail(`wait for ${val} in ${result.value}`) |
||||
else this.api.assert.ok(true, `<*[data-id="terminalJournal"] > div:last-child> contains ${val}.`) |
||||
this.emit('complete') |
||||
}) |
||||
return this |
@ -1,11 +1,14 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class ModalFooterOKClick extends EventEmitter { |
||||
command () { |
||||
command (this: NightwatchBrowser): NightwatchBrowser { |
||||
this.api.waitForElementVisible('#modal-footer-cancel').perform((client, done) => { |
||||
this.api.execute(function () { |
||||
document.querySelector('#modal-footer-cancel').click() |
||||
}, [], (result) => { |
||||
const elem = document.querySelector('#modal-footer-cancel') as HTMLElement |
||||
|
||||
elem.click() |
||||
}, [], () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
@ -1,11 +1,14 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class ModalFooterOKClick extends EventEmitter { |
||||
command () { |
||||
command (this: NightwatchBrowser): NightwatchBrowser { |
||||
this.api.waitForElementVisible('#modal-footer-ok').perform((client, done) => { |
||||
this.api.execute(function () { |
||||
document.querySelector('#modal-footer-ok').click() |
||||
}, [], (result) => { |
||||
const elem = document.querySelector('#modal-footer-ok') as HTMLElement |
||||
|
||||
elem.click() |
||||
}, [], () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
@ -0,0 +1,19 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
class NotContainsText extends EventEmitter { |
||||
command (this: NightwatchBrowser, cssSelector: string, text: string): NightwatchBrowser { |
||||
const browser = this.api |
||||
|
||||
browser.getText(cssSelector, (result) => { |
||||
if (typeof result.value === 'string' && result.value.includes(text)) return this.api.assert.fail(`${cssSelector} contains ${text}.`) |
||||
else this.api.assert.ok(true, `${cssSelector} does not contains ${text}.`) |
||||
}) |
||||
.perform(() => { |
||||
this.emit('complete') |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = NotContainsText |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class scrollAndClick extends EventEmitter { |
||||
command (target) { |
||||
command (this: NightwatchBrowser, target: string): NightwatchBrowser { |
||||
this.api |
||||
.scrollInto(target) |
||||
.click(target) |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class SelectAccount extends EventEmitter { |
||||
command (account) { |
||||
command (this: NightwatchBrowser, account?: string): NightwatchBrowser { |
||||
if (account) { |
||||
this.api |
||||
.click(`select[data-id="runTabSelectAccount"] [value="${account}"]`) |
@ -1,6 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class sendLowLevelTx extends EventEmitter { |
||||
command (address, value, callData) { |
||||
command (this: NightwatchBrowser, address: string, value: string, callData: string): NightwatchBrowser { |
||||
console.log('low level transact to ', address, value, callData) |
||||
this.api.waitForElementVisible(`#instance${address} #deployAndRunLLTxSendTransaction`, 1000) |
||||
.clearValue(`#instance${address} #deployAndRunLLTxCalldata`) |
@ -1,11 +1,14 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from 'events' |
||||
|
||||
class SetEditorValue extends EventEmitter { |
||||
command (value, callback) { |
||||
command (this: NightwatchBrowser, value: string, callback?: VoidFunction): NightwatchBrowser { |
||||
this.api.perform((client, done) => { |
||||
this.api.execute(function (value) { |
||||
document.getElementById('input').editor.session.setValue(value) |
||||
}, [value], (result) => { |
||||
const elem: any = document.getElementById('input') |
||||
|
||||
elem.editor.session.setValue(value) |
||||
}, [value], () => { |
||||
done() |
||||
if (callback) { |
||||
callback.call(this.api) |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from 'events' |
||||
|
||||
class SetSolidityCompilerVersion extends EventEmitter { |
||||
command (version) { |
||||
command (this: NightwatchBrowser, version: string): NightwatchBrowser { |
||||
this.api |
||||
.click(`#compileTabView #versionSelector [value="${version}"]`) |
||||
.pause(5000) |
@ -1,12 +1,13 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser, NightwatchAPI } from "nightwatch" |
||||
import EventEmitter from "events" |
||||
|
||||
/* |
||||
Switches between browser tabs |
||||
*/ |
||||
|
||||
class SwitchBrowserTab extends EventEmitter { |
||||
command (index) { |
||||
this.api.perform((browser, done) => { |
||||
command (this: NightwatchBrowser, index: number): NightwatchBrowser { |
||||
this.api.perform((browser: NightwatchAPI, done) => { |
||||
browser.windowHandles((result) => { |
||||
browser.switchWindow(result.value[index]) |
||||
done() |
@ -0,0 +1,27 @@ |
||||
import { NightwatchBrowser, NightwatchContractContent } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class TestContracts extends EventEmitter { |
||||
command (this: NightwatchBrowser,fileName: string, contractCode: NightwatchContractContent, compiledContractNames: string[]): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
testContracts(this.api, fileName, contractCode, compiledContractNames, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function testContracts (browser: NightwatchBrowser, fileName: string, contractCode: NightwatchContractContent, compiledContractNames: string[], callback: VoidFunction) { |
||||
browser |
||||
.clickLaunchIcon('solidity') |
||||
.addFile(fileName, contractCode) |
||||
.pause(1000) |
||||
.verifyContracts(compiledContractNames) |
||||
.perform(() => { |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
module.exports = TestContracts |
@ -1,7 +1,8 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class TestEditorValue extends EventEmitter { |
||||
command (testvalue) { |
||||
command (this: NightwatchBrowser, testvalue: string): NightwatchBrowser { |
||||
this.api.getEditorValue((value) => { |
||||
this.api.assert.equal(testvalue, value) |
||||
this.emit('complete') |
@ -0,0 +1,34 @@ |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from "events" |
||||
|
||||
class VerifyCallReturnValue extends EventEmitter { |
||||
command (this: NightwatchBrowser, address: string, checks: string[]): NightwatchBrowser { |
||||
this.api.perform((done) => { |
||||
verifyCallReturnValue(this.api, address, checks, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function verifyCallReturnValue (browser: NightwatchBrowser, address: string, checks: string[], done: VoidFunction) { |
||||
browser.execute(function (address: string) { |
||||
const nodes = document.querySelectorAll('#instance' + address + ' div[class^="contractActionsContainer"] div[class^="value"]') as NodeListOf<HTMLElement> |
||||
const ret = [] |
||||
for (let k = 0; k < nodes.length; k++) { |
||||
const text = nodes[k].innerText ? nodes[k].innerText : nodes[k].textContent |
||||
ret.push(text.replace('\n', '')) |
||||
} |
||||
return ret |
||||
}, [address], function (result) { |
||||
console.log('verifyCallReturnValue', result) |
||||
for (const k in checks) { |
||||
browser.assert.equal(result.value[k].trim(), checks[k].trim()) |
||||
} |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = VerifyCallReturnValue |
@ -1,11 +1,12 @@ |
||||
const EventEmitter = require('events') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import EventEmitter from 'events' |
||||
|
||||
class WaitForElementContainsText extends EventEmitter { |
||||
command (id, value) { |
||||
command (this: NightwatchBrowser, id: string, value: string): NightwatchBrowser { |
||||
let incr = 0 |
||||
let runid = setInterval(() => { |
||||
const runid = setInterval(() => { |
||||
this.api.getText(id, (result) => { |
||||
if (value.indexOf(result.value || '') !== -1) { |
||||
if (typeof result.value === 'string' && value.indexOf(result.value || '') !== -1) { |
||||
clearInterval(runid) |
||||
this.api.assert.ok(true, `WaitForElementContainsText ${id} contains ${value}`) |
||||
this.emit('complete') |
@ -0,0 +1,249 @@ |
||||
'use strict' |
||||
|
||||
const storage = `pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
/** |
||||
* @title Storage |
||||
* @dev Store & retreive value in a variable |
||||
*/ |
||||
contract Storage { |
||||
|
||||
uint256 number; |
||||
|
||||
/** |
||||
* @dev Store value in variable |
||||
* @param num value to store |
||||
*/ |
||||
function store(uint256 num) public { |
||||
number = num; |
||||
} |
||||
|
||||
/** |
||||
* @dev Return value
|
||||
* @return value of 'number' |
||||
*/ |
||||
function retreive() public view returns (uint256){ |
||||
return number; |
||||
} |
||||
}` |
||||
|
||||
const owner = `pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
/** |
||||
* @title Owner |
||||
* @dev Set & change owner |
||||
*/ |
||||
contract Owner { |
||||
|
||||
address private owner; |
||||
|
||||
// event for EVM logging
|
||||
event OwnerSet(address indexed oldOwner, address indexed newOwner); |
||||
|
||||
// modifier to check if caller is owner
|
||||
modifier isOwner() { |
||||
// If the first argument of 'require' evaluates to 'false', execution terminates and all
|
||||
// changes to the state and to Ether balances are reverted.
|
||||
// This used to consume all gas in old EVM versions, but not anymore.
|
||||
// It is often a good idea to use 'require' to check if functions are called correctly.
|
||||
// As a second argument, you can also provide an explanation about what went wrong.
|
||||
require(msg.sender == owner, "Caller is not owner"); |
||||
_; |
||||
} |
||||
|
||||
/** |
||||
* @dev Set contract deployer as owner |
||||
*/ |
||||
constructor() public { |
||||
owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor
|
||||
emit OwnerSet(address(0), owner); |
||||
} |
||||
|
||||
/** |
||||
* @dev Change owner |
||||
* @param newOwner address of new owner |
||||
*/ |
||||
function changeOwner(address newOwner) public isOwner { |
||||
emit OwnerSet(owner, newOwner); |
||||
owner = newOwner; |
||||
} |
||||
|
||||
/** |
||||
* @dev Return owner address
|
||||
* @return address of owner |
||||
*/ |
||||
function getOwner() external view returns (address) { |
||||
return owner; |
||||
} |
||||
}` |
||||
|
||||
const ballot = `pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
/** |
||||
* @title Ballot |
||||
* @dev Implements voting process along with vote delegation |
||||
*/ |
||||
contract Ballot { |
||||
|
||||
struct Voter { |
||||
uint weight; // weight is accumulated by delegation
|
||||
bool voted; // if true, that person already voted
|
||||
address delegate; // person delegated to
|
||||
uint vote; // index of the voted proposal
|
||||
} |
||||
|
||||
struct Proposal { |
||||
// If you can limit the length to a certain number of bytes,
|
||||
// always use one of bytes1 to bytes32 because they are much cheaper
|
||||
bytes32 name; // short name (up to 32 bytes)
|
||||
uint voteCount; // number of accumulated votes
|
||||
} |
||||
|
||||
address public chairperson; |
||||
|
||||
mapping(address => Voter) public voters; |
||||
|
||||
Proposal[] public proposals; |
||||
|
||||
/** |
||||
* @dev Create a new ballot to choose one of 'proposalNames'. |
||||
* @param proposalNames names of proposals |
||||
*/ |
||||
constructor(bytes32[] memory proposalNames) public { |
||||
chairperson = msg.sender; |
||||
voters[chairperson].weight = 1; |
||||
|
||||
for (uint i = 0; i < proposalNames.length; i++) { |
||||
// 'Proposal({...})' creates a temporary
|
||||
// Proposal object and 'proposals.push(...)'
|
||||
// appends it to the end of 'proposals'.
|
||||
proposals.push(Proposal({ |
||||
name: proposalNames[i], |
||||
voteCount: 0 |
||||
})); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. |
||||
* @param voter address of voter |
||||
*/ |
||||
function giveRightToVote(address voter) public { |
||||
require( |
||||
msg.sender == chairperson, |
||||
"Only chairperson can give right to vote." |
||||
); |
||||
require( |
||||
!voters[voter].voted, |
||||
"The voter already voted." |
||||
); |
||||
require(voters[voter].weight == 0); |
||||
voters[voter].weight = 1; |
||||
} |
||||
|
||||
/** |
||||
* @dev Delegate your vote to the voter 'to'. |
||||
* @param to address to which vote is delegated |
||||
*/ |
||||
function delegate(address to) public { |
||||
Voter storage sender = voters[msg.sender]; |
||||
require(!sender.voted, "You already voted."); |
||||
require(to != msg.sender, "Self-delegation is disallowed."); |
||||
|
||||
while (voters[to].delegate != address(0)) { |
||||
to = voters[to].delegate; |
||||
|
||||
// We found a loop in the delegation, not allowed.
|
||||
require(to != msg.sender, "Found loop in delegation."); |
||||
} |
||||
sender.voted = true; |
||||
sender.delegate = to; |
||||
Voter storage delegate_ = voters[to]; |
||||
if (delegate_.voted) { |
||||
// If the delegate already voted,
|
||||
// directly add to the number of votes
|
||||
proposals[delegate_.vote].voteCount += sender.weight; |
||||
} else { |
||||
// If the delegate did not vote yet,
|
||||
// add to her weight.
|
||||
delegate_.weight += sender.weight; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. |
||||
* @param proposal index of proposal in the proposals array |
||||
*/ |
||||
function vote(uint proposal) public { |
||||
Voter storage sender = voters[msg.sender]; |
||||
require(sender.weight != 0, "Has no right to vote"); |
||||
require(!sender.voted, "Already voted."); |
||||
sender.voted = true; |
||||
sender.vote = proposal; |
||||
|
||||
// If 'proposal' is out of the range of the array,
|
||||
// this will throw automatically and revert all
|
||||
// changes.
|
||||
proposals[proposal].voteCount += sender.weight; |
||||
} |
||||
|
||||
/** |
||||
* @dev Computes the winning proposal taking all previous votes into account. |
||||
* @return winningProposal_ index of winning proposal in the proposals array |
||||
*/ |
||||
function winningProposal() public view |
||||
returns (uint winningProposal_) |
||||
{ |
||||
uint winningVoteCount = 0; |
||||
for (uint p = 0; p < proposals.length; p++) { |
||||
if (proposals[p].voteCount > winningVoteCount) { |
||||
winningVoteCount = proposals[p].voteCount; |
||||
winningProposal_ = p; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then |
||||
* @return winnerName_ the name of the winner |
||||
*/ |
||||
function winnerName() public view |
||||
returns (bytes32 winnerName_) |
||||
{ |
||||
winnerName_ = proposals[winningProposal()].name; |
||||
} |
||||
} |
||||
` |
||||
|
||||
const ballotTest = `pragma solidity >=0.4.22 <0.7.0;
|
||||
import "remix_tests.sol"; // this import is automatically injected by Remix.
|
||||
import "../3_Ballot.sol"; |
||||
|
||||
contract BallotTest { |
||||
|
||||
bytes32[] proposalNames; |
||||
|
||||
Ballot ballotToTest; |
||||
function beforeAll () public { |
||||
proposalNames.push(bytes32("candidate1")); |
||||
ballotToTest = new Ballot(proposalNames); |
||||
} |
||||
|
||||
function checkWinningProposal () public { |
||||
ballotToTest.vote(0); |
||||
Assert.equal(ballotToTest.winningProposal(), uint(0), "proposal at index 0 should be the winning proposal"); |
||||
Assert.equal(ballotToTest.winnerName(), bytes32("candidate1"), "candidate1 should be the winner name"); |
||||
} |
||||
|
||||
function checkWinninProposalWithReturnValue () public view returns (bool) { |
||||
return ballotToTest.winningProposal() == 0; |
||||
} |
||||
} |
||||
` |
||||
|
||||
export default { |
||||
storage: { name: '1_Storage.sol', content: storage }, |
||||
owner: { name: '2_Owner.sol', content: owner }, |
||||
ballot: { name: '3_Ballot.sol', content: ballot }, |
||||
ballot_test: { name: 'tests/4_Ballot_test.sol', content: ballotTest } |
||||
} |
@ -1,29 +1,28 @@ |
||||
import { NightwatchBrowser } from "nightwatch" |
||||
|
||||
require('dotenv').config() |
||||
|
||||
module.exports = function (browser, callback, url, preloadPlugins = true) { |
||||
export default function (browser: NightwatchBrowser, callback: VoidFunction, url?: string, preloadPlugins = true): void { |
||||
browser |
||||
.url(url || 'http://127.0.0.1:8080') |
||||
.pause(5000) |
||||
.switchBrowserTab(0) |
||||
.injectScript('test-browser/helpers/applytestmode.js', function () { |
||||
browser.fullscreenWindow(() => { |
||||
if (preloadPlugins) { |
||||
console.log('preloadPlugins: ', preloadPlugins) |
||||
initModules(browser, () => { |
||||
browser.clickLaunchIcon('solidity') |
||||
.waitForElementVisible('[for="autoCompile"]') |
||||
.click('[for="autoCompile"]') |
||||
.verify.elementPresent('[data-id="compilerContainerAutoCompile"]:checked') |
||||
}) |
||||
} |
||||
}) |
||||
.fullscreenWindow(() => { |
||||
if (preloadPlugins) { |
||||
initModules(browser, () => { |
||||
browser.clickLaunchIcon('solidity') |
||||
.waitForElementVisible('[for="autoCompile"]') |
||||
.click('[for="autoCompile"]') |
||||
.verify.elementPresent('[data-id="compilerContainerAutoCompile"]:checked') |
||||
}) |
||||
} |
||||
}) |
||||
.perform(() => { |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
function initModules (browser, callback) { |
||||
function initModules (browser: NightwatchBrowser, callback: VoidFunction) { |
||||
browser.pause(5000) |
||||
.click('[data-id="verticalIconsKindpluginManager"]') |
||||
.scrollAndClick('[data-id="pluginManagerComponentActivateButtonsolidityStaticAnalysis"]') |
@ -0,0 +1,127 @@ |
||||
'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('') |
||||
.getText('div[class^="terminal"]', (value) => { |
||||
console.log('value: ', value) |
||||
}) |
||||
.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(); |
||||
} |
||||
}`}
|
||||
} |
||||
] |
@ -1,7 +1,7 @@ |
||||
|
||||
// const https = require('https')
|
||||
|
||||
module.exports = function sauce (callback) { |
||||
export default function sauce (callback: VoidFunction): void { |
||||
if (typeof callback === 'function') return callback() |
||||
/* |
||||
const currentTest = this.client.currentTest |
@ -1,21 +1,22 @@ |
||||
'use strict' |
||||
var examples = require('../../src/app/editor/example-contracts') |
||||
var init = require('../helpers/init') |
||||
var sauce = require('./sauce') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import init from '../helpers/init' |
||||
import sauce from './sauce' |
||||
import examples from '../examples/example-contracts' |
||||
|
||||
var sources = [ |
||||
const sources = [ |
||||
{'browser/Untitled.sol': {content: examples.ballot.content}}, |
||||
{'browser/Untitled1.sol': {content: `contract test {}`}} |
||||
] |
||||
|
||||
module.exports = { |
||||
before: function (browser, done) { |
||||
before: function (browser: NightwatchBrowser, done: VoidFunction) { |
||||
init(browser, done) |
||||
}, |
||||
'@sources': function () { |
||||
return sources |
||||
}, |
||||
'The sequence: Compiling / Deploying / Compiling another contract / calling the first contract - should display in the log the transaction with all the decoded information': function (browser) { |
||||
'The sequence: Compiling / Deploying / Compiling another contract / calling the first contract - should display in the log the transaction with all the decoded information': function (browser: NightwatchBrowser) { |
||||
// https://github.com/ethereum/remix-ide/issues/2864
|
||||
browser |
||||
.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000) |
@ -1,17 +1,20 @@ |
||||
'use strict' |
||||
const init = require('../helpers/init') |
||||
const sauce = require('./sauce') |
||||
import { NightwatchBrowser } from 'nightwatch' |
||||
import init from '../helpers/init' |
||||
import sauce from './sauce' |
||||
|
||||
module.exports = { |
||||
before: function (browser, done) { |
||||
before: function (browser: NightwatchBrowser, done: VoidFunction) { |
||||
init(browser, done, 'http://127.0.0.1:8080?plugins=solidity,udapp', false) |
||||
}, |
||||
'CheckSolidityActivatedAndUDapp': function (browser) { |
||||
|
||||
'CheckSolidityActivatedAndUDapp': function (browser: NightwatchBrowser) { |
||||
browser |
||||
.waitForElementVisible('#icon-panel', 10000) |
||||
.clickLaunchIcon('solidity') |
||||
.clickLaunchIcon('udapp') |
||||
.end() |
||||
}, |
||||
|
||||
tearDown: sauce |
||||
} |
@ -0,0 +1,84 @@ |
||||
// Merge custom command types with nightwatch types
|
||||
|
||||
import { NightwatchBrowser, NightwatchBrowser, NightwatchBrowser } from "nightwatch"; |
||||
|
||||
declare module "nightwatch" { |
||||
export interface NightwatchCustomCommands { |
||||
clickLaunchIcon(icon: string): NightwatchBrowser, |
||||
switchBrowserTab(index: number): NightwatchBrowser, |
||||
scrollAndClick(target: string): NightwatchBrowser, |
||||
scrollInto(target: string): NightwatchBrowser, |
||||
testContracts(fileName: string, contractCode: NightwatchContractContent, compiledContractNames: string[]): NightwatchBrowser, |
||||
setEditorValue(value: string, callback?: () => void): NightwatchBrowser, |
||||
addFile(name: string, content: NightwatchContractContent): NightwatchBrowser, |
||||
verifyContracts(compiledContractNames: string[], opts?: { wait: number, version?: string }): NightwatchBrowser, |
||||
selectAccount(account?: string): NightwatchBrowser, |
||||
clickFunction(fnFullName: string, expectedInput?: NightwatchClickFunctionExpectedInput): NightwatchBrowser, |
||||
testFunction(txHash: string, expectedInput: NightwatchTestFunctionExpectedInput): NightwatchBrowser, |
||||
goToVMTraceStep(step: number, incr?: number): NightwatchBrowser, |
||||
checkVariableDebug(id: string, debugValue: NightwatchCheckVariableDebugValue): NightwatchBrowser, |
||||
addAtAddressInstance(address: string, isValidFormat: boolean, isValidChecksum: boolean): NightwatchBrowser, |
||||
modalFooterOKClick(): NightwatchBrowser, |
||||
clickInstance(index: number): NightwatchBrowser, |
||||
journalLastChildIncludes(val: string): NightwatchBrowser, |
||||
executeScript(script: string): NightwatchBrowser, |
||||
clearEditableContent(cssSelector: string): NightwatchBrowser, |
||||
journalChildIncludes(val: string): NightwatchBrowser, |
||||
debugTransaction(index: number): NightwatchBrowser, |
||||
checkElementStyle(cssSelector: string, styleProperty: string, expectedResult: string): NightwatchBrowser, |
||||
openFile(name: string): NightwatchBrowser, |
||||
editorScroll(direction: 'up' | 'down', numberOfTimes: number): NightwatchBrowser, |
||||
renameFile(path: string, newFileName: string, renamedPath: string): NightwatchBrowser, |
||||
rightClick(cssSelector: string): NightwatchBrowser, |
||||
waitForElementContainsText(id: string, value: string): NightwatchBrowser, |
||||
getModalBody(callback: (value: string, cb: VoidFunction) => void): NightwatchBrowser, |
||||
modalFooterCancelClick(): NightwatchBrowser, |
||||
selectContract(contractName: string): NightwatchBrowser, |
||||
createContract(inputParams: string): NightwatchBrowser, |
||||
getAddressAtPosition(index: number, cb: (pos: string) => void): NightwatchBrowser, |
||||
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, |
||||
testEditorValue(testvalue: string): NightwatchBrowser, |
||||
removeFile(path: string): NightwatchBrowser, |
||||
switchBrowserWindow(url: string, windowName: string, cb: (browser: NightwatchBrowser, window?: NightwatchCallbackResult<Window>) => void): NightwatchBrowser, |
||||
setupMetamask(passphrase: string, password: string): NightwatchBrowser, |
||||
signMessage(msg: string, callback: (hash: { value: string }, signature: { value: string }) => void): NightwatchBrowser, |
||||
setSolidityCompilerVersion(version: string): NightwatchBrowser, |
||||
clickElementAtPosition(cssSelector: string, index: number): NightwatchBrowser, |
||||
notContainsText(cssSelector: string, text: string): NightwatchBrowser, |
||||
sendLowLevelTx(address: string, value: string, callData: string): NightwatchBrowser, |
||||
journalLastChild(val: string): NightwatchBrowser, |
||||
checkTerminalFilter(filter: string, test: string): NightwatchBrowser, |
||||
noWorkerErrorFor(version: string): NightwatchBrowser |
||||
} |
||||
|
||||
export interface NightwatchBrowser { |
||||
api: this, |
||||
emit: (status: string) => void, |
||||
fullscreenWindow: (result?: any) => this, |
||||
keys(keysToSend: string, callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void): NightwatchBrowser, |
||||
sendKeys: (selector: string, inputValue: string | string[], callback?: (this: NightwatchAPI, result: NightwatchCallbackResult<void>) => void) => NightwatchBrowser |
||||
} |
||||
|
||||
export interface NightwatchContractContent { |
||||
content: string; |
||||
} |
||||
|
||||
export interface NightwatchClickFunctionExpectedInput { |
||||
types: string, |
||||
values: string |
||||
} |
||||
|
||||
export interface NightwatchTestFunctionExpectedInput { |
||||
[key: string]: any |
||||
} |
||||
|
||||
export interface NightwatchTestConstantFunctionExpectedInput { |
||||
types: string, |
||||
values: string |
||||
} |
||||
|
||||
export type NightwatchCheckVariableDebugValue = NightwatchTestFunctionExpectedInput |
||||
} |
@ -0,0 +1,9 @@ |
||||
{ |
||||
"extends": "./tsconfig.json", |
||||
"compilerOptions": { |
||||
"sourceMap": false, |
||||
"outDir": "../../dist", |
||||
"allowJs": true |
||||
}, |
||||
"include": ["**/*.ts", "**/*.js"] |
||||
} |
@ -0,0 +1,9 @@ |
||||
{ |
||||
"extends": "../../tsconfig.json", |
||||
"compilerOptions": { |
||||
"types": ["node", "nightwatch"], |
||||
"esModuleInterop": true |
||||
}, |
||||
"include": ["**/*.ts", "**/*.js"] |
||||
} |
||||
|
@ -1,101 +0,0 @@ |
||||
'use strict' |
||||
var buildId = process.env.CIRCLE_BUILD_NUM || process.env.TRAVIS_JOB_NUMBER |
||||
|
||||
module.exports = { |
||||
'src_folders': ['./test-browser-debugger/test'], |
||||
'output_folder': './test-browser-debugger/test/reports', |
||||
'custom_commands_path': '', |
||||
'custom_assertions_path': '', |
||||
'globals_path': '', |
||||
'page_objects_path': '', |
||||
|
||||
'selenium': { |
||||
'start_process': false, |
||||
'server_path': '', |
||||
'log_path': '', |
||||
'host': '127.0.0.1', |
||||
'port': 4444, |
||||
'cli_args': { |
||||
'webdriver.chrome.driver': '', |
||||
'webdriver.ie.driver': '', |
||||
'webdriver.firefox.profile': '' |
||||
} |
||||
}, |
||||
|
||||
'test_settings': { |
||||
'default': { |
||||
'launch_url': 'http://ondemand.saucelabs.com:80', |
||||
'selenium_host': 'ondemand.saucelabs.com', |
||||
'selenium_port': 80, |
||||
'silent': true, |
||||
'username': 'yanneth', |
||||
'access_key': '1f5a4560-b02b-41aa-b52b-f033aad30870', |
||||
'use_ssl': false, |
||||
'globals': { |
||||
'waitForConditionTimeout': 10000, |
||||
'asyncHookTimeout': 100000 |
||||
}, |
||||
'screenshots': { |
||||
'enabled': false, |
||||
'path': '' |
||||
}, |
||||
'desiredCapabilities': { |
||||
'browserName': 'firefox', |
||||
'javascriptEnabled': true, |
||||
'acceptSslCerts': true, |
||||
'build': 'build-' + buildId, |
||||
'tunnel-identifier': 'remix_tests_' + buildId |
||||
} |
||||
}, |
||||
|
||||
'chrome': { |
||||
'desiredCapabilities': { |
||||
'browserName': 'chrome', |
||||
'javascriptEnabled': true, |
||||
'acceptSslCerts': true, |
||||
'build': 'build-' + buildId, |
||||
'tunnel-identifier': 'remix_tests_' + buildId |
||||
} |
||||
}, |
||||
|
||||
'safari': { |
||||
'desiredCapabilities': { |
||||
'browserName': 'safari', |
||||
'javascriptEnabled': true, |
||||
'platform': 'OS X 10.11', |
||||
'version': '10.0', |
||||
'acceptSslCerts': true, |
||||
'build': 'build-' + buildId, |
||||
'tunnel-identifier': 'remix_tests_' + buildId |
||||
} |
||||
}, |
||||
|
||||
'ie': { |
||||
'desiredCapabilities': { |
||||
'browserName': 'internet explorer', |
||||
'javascriptEnabled': true, |
||||
'acceptSslCerts': true, |
||||
'platform': 'Windows 10', |
||||
'version': '11.103', |
||||
'build': 'build-' + buildId, |
||||
'tunnel-identifier': 'remix_tests_' + buildId |
||||
} |
||||
}, |
||||
|
||||
'local': { |
||||
'launch_url': 'http://localhost', |
||||
'selenium_host': '127.0.0.1', |
||||
'selenium_port': 4444, |
||||
'silent': true, |
||||
'screenshots': { |
||||
'enabled': false, |
||||
'path': '' |
||||
}, |
||||
'desiredCapabilities': { |
||||
'browserName': 'firefox', |
||||
'javascriptEnabled': true, |
||||
'acceptSslCerts': true |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,36 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class AddFile extends EventEmitter { |
||||
command (name, content) { |
||||
this.api.perform((done) => { |
||||
addFile(this.api, name, content, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function addFile (browser, name, content, done) { |
||||
browser.clickLaunchIcon('udapp').clickLaunchIcon('fileExplorers').click('.newFile') |
||||
.waitForElementVisible('#modal-dialog') |
||||
.perform((client, done) => { |
||||
browser.execute(function (fileName) { |
||||
if (fileName !== 'Untitled.sol') { |
||||
document.querySelector('#modal-dialog #prompt_text').setAttribute('value', fileName) |
||||
} |
||||
document.querySelector('#modal-footer-ok').click() |
||||
}, [name], function (result) { |
||||
console.log(result) |
||||
done() |
||||
}) |
||||
}) |
||||
.setEditorValue(content.content) |
||||
.pause(1000) |
||||
.perform(function () { |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = AddFile |
@ -1,26 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class checkElementStyle extends EventEmitter { |
||||
command (cssSelector, styleProperty, expectedResult) { |
||||
this.api.perform((done) => { |
||||
checkStyle(this.api, cssSelector, styleProperty, expectedResult, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function checkStyle (browser, cssSelector, styleProperty, expectedResult, callback) { |
||||
browser.execute(function (cssSelector, styleProperty) { |
||||
return window.getComputedStyle(document.querySelector(cssSelector)).getPropertyValue(styleProperty) |
||||
}, [cssSelector, styleProperty], function (result) { |
||||
const value = result.value |
||||
|
||||
browser.assert.equal(value.trim().toLowerCase(), expectedResult.toLowerCase()) |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
module.exports = checkElementStyle |
@ -1,38 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
const deepequal = require('deep-equal') |
||||
|
||||
class CreateContract extends EventEmitter { |
||||
command (id, debugValue) { |
||||
this.api.perform((done) => { |
||||
checkDebug(this.api, id, debugValue, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function checkDebug (browser, id, debugValue, done) { |
||||
// id is soliditylocals or soliditystate
|
||||
browser.execute(function (id) { |
||||
return document.querySelector('#' + id + ' .dropdownrawcontent').innerText |
||||
}, [id], function (result) { |
||||
console.log(id + ' ' + result.value) |
||||
var value |
||||
try { |
||||
value = JSON.parse(result.value) |
||||
} catch (e) { |
||||
browser.assert.fail('cant parse solidity state', e.message, '') |
||||
done() |
||||
return |
||||
} |
||||
var equal = deepequal(debugValue, value) |
||||
if (!equal) { |
||||
browser.assert.fail('checkDebug on ' + id, 'info about error\n ' + JSON.stringify(debugValue) + '\n ' + JSON.stringify(value), '') |
||||
} |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = CreateContract |
@ -1,24 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class ClickElement extends EventEmitter { |
||||
command (cssSelector, index = 0) { |
||||
this.api.perform((done) => { |
||||
_clickElement(this.api, cssSelector, index, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function _clickElement (browser, cssSelector, index, cb) { |
||||
browser.waitForElementPresent(cssSelector) |
||||
.execute(function (cssSelector, index) { |
||||
document.querySelectorAll(cssSelector)[index].click() |
||||
}, [cssSelector, index], function () { |
||||
cb() |
||||
}) |
||||
} |
||||
|
||||
module.exports = ClickElement |
@ -1,18 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class GetEditorValue extends EventEmitter { |
||||
command (callback) { |
||||
this.api.perform((client, done) => { |
||||
this.api.execute(function (value) { |
||||
return document.getElementById('input').editor.getValue() |
||||
}, [], (result) => { |
||||
done(result.value) |
||||
callback(result.value) |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = GetEditorValue |
@ -1,16 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class GetModalBody extends EventEmitter { |
||||
command (callback) { |
||||
this.api.waitForElementVisible('.modal-body') |
||||
.getText('.modal-body', (result) => { |
||||
console.log(result) |
||||
callback(result.value, () => { |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = GetModalBody |
@ -1,18 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class NotContainsText extends EventEmitter { |
||||
command (cssSelector, text) { |
||||
const browser = this.api |
||||
|
||||
browser.getText(cssSelector, (result) => { |
||||
if (result.value.includes(text)) return this.api.assert.fail(`${cssSelector} contains ${text}.`) |
||||
else this.api.assert.ok(`${cssSelector} does not contains ${text}.`) |
||||
}) |
||||
.perform(() => { |
||||
this.emit('complete') |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
module.exports = NotContainsText |
@ -1,26 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class SwitchFile extends EventEmitter { |
||||
command (name) { |
||||
this.api.perform((done) => { |
||||
switchFile(this.api, name, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
// click on fileExplorer can toggle it. We go through settings to be sure FE is open
|
||||
function switchFile (browser, name, done) { |
||||
browser.clickLaunchIcon('settings').clickLaunchIcon('fileExplorers') |
||||
.waitForElementVisible('li[key="' + name + '"]') |
||||
.click('li[key="' + name + '"]') |
||||
.pause(2000) |
||||
.perform(() => { |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = SwitchFile |
@ -1,27 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class TestContracts extends EventEmitter { |
||||
command (fileName, contractCode, compiledContractNames) { |
||||
this.api.perform((done) => { |
||||
testContracts(this.api, fileName, contractCode, compiledContractNames, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function testContracts (browser, fileName, contractCode, compiledContractNames, callback) { |
||||
browser |
||||
.clickLaunchIcon('solidity') |
||||
.addFile(fileName, contractCode) |
||||
.pause(1000) |
||||
.verifyContracts(compiledContractNames) |
||||
|
||||
.perform(() => { |
||||
callback() |
||||
}) |
||||
} |
||||
|
||||
module.exports = TestContracts |
@ -1,33 +0,0 @@ |
||||
const EventEmitter = require('events') |
||||
|
||||
class VerifyCallReturnValue extends EventEmitter { |
||||
command (address, checks) { |
||||
this.api.perform((done) => { |
||||
verifyCallReturnValue(this.api, address, checks, () => { |
||||
done() |
||||
this.emit('complete') |
||||
}) |
||||
}) |
||||
return this |
||||
} |
||||
} |
||||
|
||||
function verifyCallReturnValue (browser, address, checks, done) { |
||||
browser.execute(function (address) { |
||||
var nodes = document.querySelectorAll('#instance' + address + ' div[class^="contractActionsContainer"] div[class^="value"]') |
||||
var ret = [] |
||||
for (var k = 0; k < nodes.length; k++) { |
||||
var text = nodes[k].innerText ? nodes[k].innerText : nodes[k].textContent |
||||
ret.push(text.replace('\n', '')) |
||||
} |
||||
return ret |
||||
}, [address], function (result) { |
||||
console.log('verifyCallReturnValue', result) |
||||
for (var k in checks) { |
||||
browser.assert.equal(result.value[k].trim(), checks[k].trim()) |
||||
} |
||||
done() |
||||
}) |
||||
} |
||||
|
||||
module.exports = VerifyCallReturnValue |
@ -1,13 +0,0 @@ |
||||
/** |
||||
* This script is injected by NightWatch just before starting test |
||||
* |
||||
*/ |
||||
console.log('applying test mode') |
||||
var editor = document.getElementById('input').editor |
||||
editor.setBehavioursEnabled(false) // disable bracket auto-match (i.e. automatic injection of closing brackets and other things), so we can enter raw source code.
|
||||
editor.setOptions({ |
||||
enableBasicAutocompletion: false, |
||||
enableSnippets: false, |
||||
enableLiveAutocompletion: false |
||||
}) |
||||
console.log('test mode applied') |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue