From 5633de3ad2832aaab322d6189fe5a5bcaa6fce54 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 3 Aug 2020 03:01:50 +0100 Subject: [PATCH] Added solidityImport tests --- .../src/commands/addAtAddressInstance.ts | 2 +- .../src/commands/setEditorValue.ts | 2 +- .../commands/setSolidityCompilerVersion.ts | 16 ++++ .../src/tests/solidityImport.test.ts | 89 +++++++++++++++++++ apps/remix-ide-e2e/src/types/index.d.ts | 10 +-- apps/remix-ide-e2e/tsconfig.json | 3 +- 6 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 apps/remix-ide-e2e/src/commands/setSolidityCompilerVersion.ts create mode 100644 apps/remix-ide-e2e/src/tests/solidityImport.test.ts diff --git a/apps/remix-ide-e2e/src/commands/addAtAddressInstance.ts b/apps/remix-ide-e2e/src/commands/addAtAddressInstance.ts index 37e9c325b2..2369b576d8 100644 --- a/apps/remix-ide-e2e/src/commands/addAtAddressInstance.ts +++ b/apps/remix-ide-e2e/src/commands/addAtAddressInstance.ts @@ -3,7 +3,7 @@ import EventEmitter from "events" class addAtAddressInstance extends EventEmitter { command (this: NightwatchBrowser, address: string, isValidFormat: boolean, isValidChecksum: boolean): NightwatchBrowser { - this.api.perform((done) => { + this.api.perform((done: VoidFunction) => { addInstance(this.api, address, isValidFormat, isValidChecksum, () => { done() this.emit('complete') diff --git a/apps/remix-ide-e2e/src/commands/setEditorValue.ts b/apps/remix-ide-e2e/src/commands/setEditorValue.ts index f7bd5d8144..b8e6e51435 100644 --- a/apps/remix-ide-e2e/src/commands/setEditorValue.ts +++ b/apps/remix-ide-e2e/src/commands/setEditorValue.ts @@ -1,5 +1,5 @@ import { NightwatchBrowser } from 'nightwatch' -import EventEmitter from "events" +import EventEmitter from 'events' class SetEditorValue extends EventEmitter { command (this: NightwatchBrowser, value: string, callback?: VoidFunction): NightwatchBrowser { diff --git a/apps/remix-ide-e2e/src/commands/setSolidityCompilerVersion.ts b/apps/remix-ide-e2e/src/commands/setSolidityCompilerVersion.ts new file mode 100644 index 0000000000..e916e41993 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/setSolidityCompilerVersion.ts @@ -0,0 +1,16 @@ +import { NightwatchBrowser } from 'nightwatch' +import EventEmitter from 'events' + +class SetSolidityCompilerVersion extends EventEmitter { + command (this: NightwatchBrowser, version: string): NightwatchBrowser { + this.api + .click(`#compileTabView #versionSelector [value="${version}"]`) + .pause(5000) + .perform(() => { + this.emit('complete') + }) + return this + } +} + +module.exports = SetSolidityCompilerVersion diff --git a/apps/remix-ide-e2e/src/tests/solidityImport.test.ts b/apps/remix-ide-e2e/src/tests/solidityImport.test.ts new file mode 100644 index 0000000000..fa4c9ff375 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/solidityImport.test.ts @@ -0,0 +1,89 @@ +'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 + }, + + 'Test Simple Contract': function (browser: NightwatchBrowser) { + browser.testContracts('Untitled.sol', sources[0]['browser/Untitled.sol'], ['test1', 'test2']) + }, + + 'Test Success Import': function (browser: NightwatchBrowser) { + browser.addFile('Untitled1.sol', sources[1]['browser/Untitled1.sol']) + .addFile('Untitled2.sol', sources[1]['browser/Untitled2.sol']) + .openFile('browser/Untitled1.sol') + .verifyContracts(['test6', 'test4', 'test5']) + }, + + 'Test Failed Import': function (browser: NightwatchBrowser) { + browser.addFile('Untitled3.sol', sources[2]['browser/Untitled3.sol']) + .clickLaunchIcon('solidity') + .assert.containsText('#compileTabView .error pre', 'not found browser/Untitled11.sol') + }, + + 'Test Github Import - from master branch': function (browser: NightwatchBrowser) { + browser + .setSolidityCompilerVersion('soljson-v0.6.2+commit.bacdbe57.js') // open-zeppelin moved to pragma ^0.6.0 (master branch) + .addFile('Untitled4.sol', sources[3]['browser/Untitled4.sol']) + .clickLaunchIcon('fileExplorers') + .verifyContracts(['test7', 'ERC20', 'SafeMath'], {wait: 10000}) + }, + + 'Test Github Import - from other branch': function (browser: NightwatchBrowser) { + browser + .setSolidityCompilerVersion('soljson-v0.5.0+commit.1d4f565a.js') // switch back to 0.5.0 : release-v2.3.0 branch is not solidity 0.6 compliant + .addFile('Untitled5.sol', sources[4]['browser/Untitled5.sol']) + .clickLaunchIcon('fileExplorers') + .verifyContracts(['test8', 'ERC20', 'SafeMath'], {wait: 10000}) + }, + + 'Test Github Import - no branch specified': function (browser: NightwatchBrowser) { + browser + .setSolidityCompilerVersion('soljson-v0.6.2+commit.bacdbe57.js') // open-zeppelin moved to pragma ^0.6.0 (master branch) + .addFile('Untitled6.sol', sources[5]['browser/Untitled6.sol']) + .clickLaunchIcon('fileExplorers') + .verifyContracts(['test10', 'ERC20', 'SafeMath'], {wait: 10000}) + }, + + 'Test Github Import - raw URL': function (browser: NightwatchBrowser) { + browser + .addFile('Untitled7.sol', sources[6]['browser/Untitled7.sol']) + .clickLaunchIcon('fileExplorers') + .verifyContracts(['test11', 'ERC20', 'SafeMath'], {wait: 10000}) + .end() + }, + tearDown: sauce +} + +const sources = [ + { + 'browser/Untitled.sol': {content: 'contract test1 {} contract test2 {}'} + }, + { + 'browser/Untitled1.sol': {content: 'import "./Untitled2.sol"; contract test6 {}'}, + 'browser/Untitled2.sol': {content: 'contract test4 {} contract test5 {}'} + }, + { + 'browser/Untitled3.sol': {content: 'import "./Untitled11.sol"; contract test6 {}'} + }, + { + 'browser/Untitled4.sol': {content: 'import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol"; contract test7 {}'} + }, + { + 'browser/Untitled5.sol': {content: 'import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.3.0/contracts/token/ERC20/ERC20.sol"; contract test8 {}'} + }, + { + 'browser/Untitled6.sol': {content: 'import "https://github.com/OpenZeppelin/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; contract test10 {}'} + }, + { + 'browser/Untitled7.sol': {content: 'import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC20/ERC20.sol"; contract test11 {}'} + } +] diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 6d3ad1f70f..6a7043314b 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -11,7 +11,7 @@ declare module "nightwatch" { 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, + 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, @@ -44,7 +44,8 @@ declare module "nightwatch" { removeFile(path: string): NightwatchBrowser, switchBrowserWindow(url: string, windowName: string, cb: (browser: NightwatchBrowser, window?: NightwatchCallbackResult) => void): NightwatchBrowser, setupMetamask(passphrase: string, password: string): NightwatchBrowser, - signMessage(msg: string, callback: (hash: { value: string }, signature: { value: string }) => void): NightwatchBrowser + signMessage(msg: string, callback: (hash: { value: string }, signature: { value: string }) => void): NightwatchBrowser, + setSolidityCompilerVersion(version: string): NightwatchBrowser } export interface NightwatchBrowser { @@ -58,11 +59,6 @@ declare module "nightwatch" { content: string; } - export interface NightwatchVerifyContractOpts { - wait: number, - version?: string - } - export interface NightwatchClickFunctionExpectedInput { types: string, values: string diff --git a/apps/remix-ide-e2e/tsconfig.json b/apps/remix-ide-e2e/tsconfig.json index abd2e3b893..a26c03d891 100644 --- a/apps/remix-ide-e2e/tsconfig.json +++ b/apps/remix-ide-e2e/tsconfig.json @@ -2,8 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "types": ["node", "nightwatch"], - "esModuleInterop": true, - "strict": true + "esModuleInterop": true }, "include": ["**/*.ts", "**/*.js"] }