Merge branch 'master' of https://github.com/ethereum/remix-project into e2epluginapi2

pull/5370/head
bunsenstraat 3 years ago
parent 1bc8b3befd
commit c30077e14e
  1. 8
      apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx
  2. 193
      apps/remix-ide-e2e/src/tests/plugin_api.ts
  3. 1
      apps/remix-ide/src/assets/css/intro.js/2.7.0/introjs.min.css
  4. 2
      apps/remix-ide/src/assets/css/intro.js/4.1.0/introjs.min.css
  5. 2
      apps/remix-ide/src/remixEngine.js

@ -46,7 +46,8 @@ function App () {
profiles.map((profile: Profile) => { profiles.map((profile: Profile) => {
if (profile.events) { if (profile.events) {
profile.events.map((event: string) => { profile.events.map((event: string) => {
client.on(profile.name as any, event, (...args:any) => { client.on(profile.name as any, event, (...args: any) => {
console.log('event :', event, args)
setEvents({ setEvents({
event: event, event: event,
args: args args: args
@ -67,9 +68,12 @@ function App () {
let ob: any = null let ob: any = null
try { try {
ob = JSON.parse(payload) ob = JSON.parse(payload)
} catch (e) {} if (ob && !Array.isArray(ob)) { ob = [ob] }
} catch (e) { }
const args = ob || [payload] const args = ob || [payload]
console.log('calling :', profile.name, method, ...args)
const result = await client.call(profile.name as any, method, ...args) const result = await client.call(profile.name as any, method, ...args)
console.log('result :', result)
setLog(result) setLog(result)
} catch (e) { } catch (e) {
setLog(e.message) setLog(e.message)

@ -1,6 +1,7 @@
'use strict' 'use strict'
import { ExternalProfile, LocationProfile, Profile } from '@remixproject/plugin-utils' import { ExternalProfile, LocationProfile, Profile } from '@remixproject/plugin-utils'
import { NightwatchBrowser } from 'nightwatch' import { NightwatchBrowser } from 'nightwatch'
import { resolve } from 'url'
import init from '../helpers/init' import init from '../helpers/init'
declare global { declare global {
@ -15,7 +16,7 @@ const localPluginData: Profile & LocationProfile & ExternalProfile = {
location: 'sidePanel' location: 'sidePanel'
} }
const getBrowserLogs = function (browser: NightwatchBrowser) { const getBrowserLogs = async function (browser: NightwatchBrowser) {
browser.getLog('browser', (logEntries) => { browser.getLog('browser', (logEntries) => {
if (logEntries && logEntries.length > 0) { if (logEntries && logEntries.length > 0) {
console.log('Browser log:') console.log('Browser log:')
@ -23,37 +24,72 @@ const getBrowserLogs = function (browser: NightwatchBrowser) {
} }
}) })
} }
const debugValues = function (browser: NightwatchBrowser, field: string, expected: string) { const debugValues = async function (browser: NightwatchBrowser, field: string, expected: any) {
browser.waitForElementVisible(`//*[@id="${field}"]`).getText(`//*[@id="${field}"]`, (result) => { return new Promise((resolve) => {
if (!result.value.toString().includes(expected)) { if (!expected) {
console.log('Actual result:') resolve(true)
console.log(result.value.toString()) return
console.log('Expected result:')
console.log(expected)
getBrowserLogs(browser)
} }
browser.waitForElementVisible(`//*[@id="${field}"]`).getText(`//*[@id="${field}"]`, (result) => {
console.log(result)
if (!result.value.toString().includes(expected)) {
console.log('Actual result:')
console.log(result.value.toString())
console.log('Expected result:')
console.log(expected)
getBrowserLogs(browser)
browser.assert.ok(false, 'Returned value from call does not match expected value.')
} else {
browser.assert.ok(true)
}
resolve(true)
})
}) })
} }
const clickAndCheckLog = function (browser: NightwatchBrowser, buttonText: string, methodResult: any, eventResult: any, payload: any) { const setPayload = async (browser: NightwatchBrowser, payload: any) => {
if (payload) { return new Promise((resolve) => {
if (typeof payload !== 'string') payload = JSON.stringify(payload) if (typeof payload !== 'string') payload = JSON.stringify(payload)
browser.clearValue('//*[@id="payload"]').setValue('//*[@id="payload"]', payload).pause(1000) browser.clearValue('//*[@id="payload"]').setValue('//*[@id="payload"]', payload, (result) => {
} resolve(result)
if (methodResult && typeof methodResult !== 'string') methodResult = JSON.stringify(methodResult) })
if (eventResult && typeof eventResult !== 'string') eventResult = JSON.stringify(eventResult) })
browser }
.useXpath().waitForElementVisible(`//*[@data-id='${buttonText}']`).click(`//*[@data-id='${buttonText}']`)
.pause(2000) const clickButton = async (browser: NightwatchBrowser, buttonText: string) => {
return new Promise((resolve) => {
if (methodResult) { browser.useXpath().waitForElementVisible(`//*[@data-id='${buttonText}']`)
debugValues(browser, 'methods', methodResult) .click(`//*[@data-id='${buttonText}']`)
browser.waitForElementVisible('//*[@id="methods"]').verify.containsText('//*[@id="methods"]', methodResult) .pause(2000, () => resolve(true))
} })
if (eventResult) { }
debugValues(browser, 'events', eventResult)
browser.waitForElementVisible('//*[@id="events"]').verify.containsText('//*[@id="events"]', eventResult) const checkForAcceptAndRemember = async function (browser: NightwatchBrowser) {
return new Promise((resolve) => {
browser.frameParent().element('xpath', '//*[@data-id="modalDialogModalBody"]', (visible:any) => {
if (visible.status && visible.status === -1) {
// @ts-ignore
browser.frame(0, () => { resolve(true) })
} else {
browser.click('//*[@id="remember"]').click('//*[@id="modal-footer-ok"]', () => {
// @ts-ignore
browser.frame(0, () => { resolve(true) })
})
}
})
})
}
const clickAndCheckLog = async (browser: NightwatchBrowser, buttonText: string, methodResult: any, eventResult: any, payload: any) => {
if (payload) {
await setPayload(browser, payload)
} }
if (methodResult && typeof methodResult !== 'string') { methodResult = JSON.stringify(methodResult) }
if (eventResult && typeof eventResult !== 'string') { eventResult = JSON.stringify(eventResult) }
await clickButton(browser, buttonText)
await checkForAcceptAndRemember(browser)
await debugValues(browser, 'methods', methodResult)
await debugValues(browser, 'events', eventResult)
} }
const assertPluginIsActive = function (browser: NightwatchBrowser, id: string) { const assertPluginIsActive = function (browser: NightwatchBrowser, id: string) {
@ -67,7 +103,7 @@ module.exports = {
afterEach: function (browser: NightwatchBrowser) { afterEach: function (browser: NightwatchBrowser) {
browser.getLog('browser', (logEntries) => { browser.getLog('browser', (logEntries) => {
console.log(logEntries) // console.log(logEntries)
}) })
}, },
@ -79,70 +115,93 @@ module.exports = {
// FILESYSTEM // FILESYSTEM
'Should get current workspace': function (browser: NightwatchBrowser) { 'Should get current workspace': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'filePanel:getCurrentWorkspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null, null) await clickAndCheckLog(browser, 'filePanel:getCurrentWorkspace', { name: 'default_workspace', isLocalhost: false, absolutePath: '.workspaces/default_workspace' }, null, null)
}, },
'Should get current files': function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null, null) 'Should get current files': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'fileManager:readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null, null)
}, },
'Should throw error on current file': function (browser: NightwatchBrowser) { 'Should throw error on current file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'Error from IDE : Error: No such file or directory No file selected', null, null) await clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'Error from IDE : Error: No such file or directory No file selected', null, null)
}, },
'Should open readme.txt': function (browser: NightwatchBrowser) { 'Should open readme.txt': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:open', null, { event: 'currentFileChanged', args: ['README.txt'] }, 'README.txt') await clickAndCheckLog(browser, 'fileManager:open', null, { event: 'currentFileChanged', args: ['README.txt'] }, 'README.txt')
}, },
'Should have current file': function (browser: NightwatchBrowser) { 'Should have current file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'README.txt', null, null) await clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'README.txt', null, null)
}, },
'Should create dir': function (browser: NightwatchBrowser) { 'Should create dir': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:mkdir', null, null, 'testdir') await clickAndCheckLog(browser, 'fileManager:mkdir', null, null, 'testdir')
clickAndCheckLog(browser, 'fileManager:readdir', 'testdir', null, '/') await clickAndCheckLog(browser, 'fileManager:readdir', 'testdir', null, '/')
}, },
'Should get file': function (browser: NightwatchBrowser) { 'Should get file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:getFile', 'REMIX EXAMPLE PROJECT', null, 'README.txt') await clickAndCheckLog(browser, 'fileManager:getFile', 'REMIX EXAMPLE PROJECT', null, 'README.txt')
}, },
'Should close all files': function (browser: NightwatchBrowser) { 'Should close all files': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:closeAllFiles', null, { event: 'noFileSelected', args: [] }, null) await clickAndCheckLog(browser, 'fileManager:closeAllFiles', null, { event: 'noFileSelected', args: [] }, null)
}, },
'Should switch to file': function (browser: NightwatchBrowser) { 'Should switch to file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:switchFile', null, { event: 'currentFileChanged', args: ['contracts/1_Storage.sol'] }, 'contracts/1_Storage.sol') await clickAndCheckLog(browser, 'fileManager:switchFile', null, { event: 'currentFileChanged', args: ['contracts/1_Storage.sol'] }, 'contracts/1_Storage.sol')
clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'contracts/1_Storage.sol', null, null) await clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'contracts/1_Storage.sol', null, null)
clickAndCheckLog(browser, 'fileManager:switchFile', null, { event: 'currentFileChanged', args: ['README.txt'] }, 'README.txt') await clickAndCheckLog(browser, 'fileManager:switchFile', null, { event: 'currentFileChanged', args: ['README.txt'] }, 'README.txt')
clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'README.txt', null, null) await clickAndCheckLog(browser, 'fileManager:getCurrentFile', 'README.txt', null, null)
}, },
'Should write to file': function (browser: NightwatchBrowser) { 'Should write to file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'fileManager:writeFile', null, { event: 'fileSaved', args: ['README.txt'] }, ['README.txt', 'test']) await clickAndCheckLog(browser, 'fileManager:writeFile', null, { event: 'fileSaved', args: ['README.txt'] }, ['README.txt', 'test'])
// @ts-ignore await clickAndCheckLog(browser, 'fileManager:readFile', 'test', null, 'README.txt')
browser.frameParent().acceptAndRemember(true, true).frame(0) },
clickAndCheckLog(browser, 'fileManager:readFile', 'test', null, 'README.txt') 'Should write to new file': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'fileManager:writeFile', null, { event: 'fileAdded', args: ['testing.txt'] }, ['testing.txt', 'test'])
await clickAndCheckLog(browser, 'fileManager:readFile', 'test', null, 'testing.txt')
},
'Should rename file': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'fileManager:rename', null, null, ['testing.txt', 'testrename.txt'])
await clickAndCheckLog(browser, 'fileManager:readFile', 'test', null, 'testrename.txt')
}, },
'Should create workspace': function (browser: NightwatchBrowser) { 'Should create empty workspace': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'filePanel:createWorkspace', null, null, 'testspace') await clickAndCheckLog(browser, 'filePanel:createWorkspace', null, null, ['emptyworkspace', false])
clickAndCheckLog(browser, 'filePanel:getCurrentWorkspace', { name: 'testspace', isLocalhost: false, absolutePath: '.workspaces/testspace' }, null, null) await clickAndCheckLog(browser, 'filePanel:getCurrentWorkspace', { name: 'emptyworkspace', isLocalhost: false, absolutePath: '.workspaces/emptyworkspace' }, null, null)
clickAndCheckLog(browser, 'fileManager:readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null, null) await clickAndCheckLog(browser, 'fileManager:readdir', {}, null, '/')
},
'Should create workspace': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'filePanel:createWorkspace', null, null, 'testspace')
await clickAndCheckLog(browser, 'filePanel:getCurrentWorkspace', { name: 'testspace', isLocalhost: false, absolutePath: '.workspaces/testspace' }, null, null)
await clickAndCheckLog(browser, 'fileManager:readdir', { contracts: { isDirectory: true }, scripts: { isDirectory: true }, tests: { isDirectory: true }, 'README.txt': { isDirectory: false } }, null, null)
}, },
// COMPILER // COMPILER
'Should compile a file': function (browser: NightwatchBrowser) { 'Should compile a file': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'solidity:compile', null, null, 'contracts/1_Storage.sol') await clickAndCheckLog(browser, 'solidity:compile', null, null, 'contracts/1_Storage.sol')
}, },
'Should get compilationresults': function (browser: NightwatchBrowser) { 'Should get compilationresults': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'solidity:getCompilationResult', 'contracts/1_Storage.sol', null, null) await clickAndCheckLog(browser, 'solidity:getCompilationResult', 'contracts/1_Storage.sol', null, null)
}, },
// DGIT // DGIT
'Should have changes on new workspace': function (browser: NightwatchBrowser) { 'Should have changes on new workspace': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'filePanel:createWorkspace', null, null, 'dgit') await clickAndCheckLog(browser, 'filePanel:createWorkspace', null, null, 'dgit')
clickAndCheckLog(browser, 'dGitProvider:status', [['README.txt', 0, 2, 0], ['contracts/1_Storage.sol', 0, 2, 0], ['contracts/2_Owner.sol', 0, 2, 0], ['contracts/3_Ballot.sol', 0, 2, 0], ['scripts/deploy_ethers.js', 0, 2, 0], ['scripts/deploy_web3.js', 0, 2, 0], ['tests/4_Ballot_test.sol', 0, 2, 0]], null, null) await clickAndCheckLog(browser, 'dGitProvider:status', [['README.txt', 0, 2, 0], ['contracts/1_Storage.sol', 0, 2, 0], ['contracts/2_Owner.sol', 0, 2, 0], ['contracts/3_Ballot.sol', 0, 2, 0], ['scripts/deploy_ethers.js', 0, 2, 0], ['scripts/deploy_web3.js', 0, 2, 0], ['tests/4_Ballot_test.sol', 0, 2, 0]], null, null)
},
'Should stage contract': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'dGitProvider:add', null, null, {
filepath: 'contracts/1_Storage.sol'
})
await clickAndCheckLog(browser, 'dGitProvider:status', [['README.txt', 0, 2, 0], ['contracts/1_Storage.sol', 0, 2, 2], ['contracts/2_Owner.sol', 0, 2, 0], ['contracts/3_Ballot.sol', 0, 2, 0], ['scripts/deploy_ethers.js', 0, 2, 0], ['scripts/deploy_web3.js', 0, 2, 0], ['tests/4_Ballot_test.sol', 0, 2, 0]], null, null)
},
'Should commit changes': async function (browser: NightwatchBrowser) {
await clickAndCheckLog(browser, 'dGitProvider:commit', null, null, { author: { name: 'Remix', email: 'Remix' }, message: 'commit-message' })
await clickAndCheckLog(browser, 'dGitProvider:log', 'commit-message', null, null)
}, },
// UNIT TESTING // UNIT TESTING
'Should activate solidityUnitTesting': function (browser: NightwatchBrowser) { 'Should activate solidityUnitTesting': async function (browser: NightwatchBrowser) {
clickAndCheckLog(browser, 'manager:activatePlugin', null, null, 'solidityUnitTesting') await clickAndCheckLog(browser, 'manager:activatePlugin', null, null, 'solidityUnitTesting')
browser.frameParent() browser.frameParent()
assertPluginIsActive(browser, 'solidityUnitTesting') assertPluginIsActive(browser, 'solidityUnitTesting')
// @ts-ignore // @ts-ignore

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -13,7 +13,7 @@ export class RemixEngine extends Engine {
if (name === 'dGitProvider') return { queueTimeout: 60000 * 4 } if (name === 'dGitProvider') return { queueTimeout: 60000 * 4 }
if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed if (name === 'slither') return { queueTimeout: 60000 * 4 } // Requires when a solc version is installed
if (name === 'hardhat') return { queueTimeout: 60000 * 4 } if (name === 'hardhat') return { queueTimeout: 60000 * 4 }
if (name === 'solidityUnitTesting') return { queueTimeout: 60000 * 4 } if (name === 'localPlugin') return { queueTimeout: 60000 * 4 }
return { queueTimeout: 10000 } return { queueTimeout: 10000 }
} }

Loading…
Cancel
Save