diff --git a/apps/remix-ide-e2e/src/commands/clearEditableContent.ts b/apps/remix-ide-e2e/src/commands/clearEditableContent.ts new file mode 100644 index 0000000000..a2fc9d8a15 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/clearEditableContent.ts @@ -0,0 +1,31 @@ +import { NightwatchBrowser } from "nightwatch" +import EventEmitter from "events" + +class clearEditablecontent extends EventEmitter { + command (this: NightwatchBrowser, cssSelector): NightwatchBrowser { + this.api.perform((done) => { + clearContent(this.api, cssSelector, () => { + done() + this.emit('complete') + }) + }) + return this + } +} + +function clearContent (browser, cssSelector, callback) { + browser.execute(function (cssSelector) { + const selection = window.getSelection() + const range = document.createRange() + + range.selectNodeContents(document.querySelector(cssSelector)) + selection.removeAllRanges() + selection.addRange(range) + }, [cssSelector], function () { + browser.sendKeys(cssSelector, browser.Keys.BACK_SPACE) + .pause(5000) + callback() + }) +} + +module.exports = clearEditablecontent diff --git a/apps/remix-ide-e2e/src/commands/executeScript.ts b/apps/remix-ide-e2e/src/commands/executeScript.ts new file mode 100644 index 0000000000..c89f6bd500 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/executeScript.ts @@ -0,0 +1,19 @@ +import { NightwatchBrowser } from "nightwatch" +import EventEmitter from "events" + +class ExecuteScript extends EventEmitter { + command (this: NightwatchBrowser, script: string): NightwatchBrowser { + this.api + .clearEditableContent('*[data-id="terminalCliInput"]') + .click('*[data-id="terminalCli"]') + .sendKeys('*[data-id="terminalCliInput"]', script) + .sendKeys('*[data-id="terminalCliInput"]', this.api.Keys.ENTER) + .sendKeys('*[data-id="terminalCliInput"]', this.api.Keys.ENTER) + .perform(() => { + this.emit('complete') + }) + return this + } +} + +module.exports = ExecuteScript diff --git a/apps/remix-ide-e2e/src/commands/modalFooterOKClick.ts b/apps/remix-ide-e2e/src/commands/modalFooterOKClick.ts index 1f78ff2248..db9cf29df7 100644 --- a/apps/remix-ide-e2e/src/commands/modalFooterOKClick.ts +++ b/apps/remix-ide-e2e/src/commands/modalFooterOKClick.ts @@ -8,7 +8,7 @@ class ModalFooterOKClick extends EventEmitter { const elem = document.querySelector('#modal-footer-ok') as HTMLElement elem.click() - }, [], (result) => { + }, [], () => { done() this.emit('complete') }) diff --git a/apps/remix-ide-e2e/src/tests/compiler_api.test.ts b/apps/remix-ide-e2e/src/tests/compiler_api.test.ts new file mode 100644 index 0000000000..6c26839427 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/compiler_api.test.ts @@ -0,0 +1,103 @@ +'use strict' + +import { NightwatchBrowser } from 'nightwatch' +import init from '../helpers/init' +import sauce from './sauce' +import examples from '../examples/example-contracts' + +const sources = [ + {'browser/Untitled.sol': { content: examples.ballot.content }} +] + + +module.exports = { + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done) + }, + '@sources': function () { + return sources + }, + + 'Should compile using "compileWithParamaters" API': function (browser: NightwatchBrowser) { + browser + .addFile('test_jsCompile.js', { content: jsCompile }) + .executeScript('remix.exeCurrent()') + .pause(5000) + .journalChildIncludes(`version: '0.6.8+commit.0bbfe453'`) + }, + + 'Should update the compiler configuration with "setCompilerConfig" API': function (browser: NightwatchBrowser) { + browser + .addFile('test_updateConfiguration.js', { content: updateConfiguration }) + .executeScript('remix.exeCurrent()') + .pause(5000) + .addFile('test_updateConfiguration.sol', { content: simpleContract }) + .verifyContracts(['StorageTestUpdateConfiguration'], {wait: 5000, version: '0.6.8+commit.0bbfe453'}) + .end() + }, + + tearDown: sauce +} + +const simpleContract = `pragma solidity >=0.4.22 <0.7.0; + +/** +* @title Storage +* @dev Store & retreive value in a variable +*/ +contract StorageTestUpdateConfiguration { + + 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 jsCompile = `(async () => { + + try { + const contract = { + "storage.sol": {content : \`${simpleContract}\` } + } + console.log('compile') + const params = { + optimize: false, + evmVersion: null, + language: 'Solidity', + version: '0.6.8+commit.0bbfe453' + } + const result = await remix.call('solidity', 'compileWithParameters', contract, params) + console.log('result ', result) + } catch (e) { + console.log(e.message) + } +})()` + +const updateConfiguration = `(async () => { + try { + const params = { + optimize: false, + evmVersion: null, + language: 'Solidity', + version: '0.6.8+commit.0bbfe453' + } + await remix.call('solidity', 'setCompilerConfig', params) + } catch (e) { + console.log(e.message) + } +})()` diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 5ab28f82a3..ad0a8d4ed1 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -20,7 +20,8 @@ declare module "nightwatch" { addAtAddressInstance(address: string, isValidFormat: boolean, isValidChecksum: boolean): NightwatchBrowser, modalFooterOKClick(): NightwatchBrowser, clickInstance(index: number): NightwatchBrowser, - journalLastChildIncludes(val: string): NightwatchBrowser + journalLastChildIncludes(val: string): NightwatchBrowser, + executeScript(script: string): NightwatchBrowser } export interface NightwatchBrowser {