From baf36196b38875f633cde79415e62d034314ff68 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 6 Jan 2022 18:04:04 +0100 Subject: [PATCH 1/4] fix add and remove provider --- apps/remix-ide-e2e/src/tests/plugin_api.ts | 23 ++++++++++++++++++ .../src/app/tabs/hardhat-provider.tsx | 4 ++-- .../remix-ui/run-tab/src/lib/actions/index.ts | 2 +- .../run-tab/src/lib/reducers/runTab.ts | 24 ++++++++++++++----- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.ts b/apps/remix-ide-e2e/src/tests/plugin_api.ts index 2ad4d82144..d3ce74a639 100644 --- a/apps/remix-ide-e2e/src/tests/plugin_api.ts +++ b/apps/remix-ide-e2e/src/tests/plugin_api.ts @@ -324,5 +324,28 @@ module.exports = { 'Should get compilationresults #group6': async function (browser: NightwatchBrowser) { await clickAndCheckLog(browser, 'solidity:getCompilationResult', 'contracts/1_Storage.sol', null, null) + }, + + // PROVIDER + + 'Should switch to hardhat provider (provider plugin)': async function (browser: NightwatchBrowser) { + browser + .clickLaunchIcon('udapp') + .click('*[data-id="Hardhat provider"]') + .modalFooterOKClick('hardhatprovider') + .waitForElementContainsText('*[data-id="settingsNetworkEnv"]', 'Custom') // e.g Custom (1337) network + .getValue('*[data-id="settingsNetworkEnv"]', (result) => { + browser.assert.ok((result.value as string).match(/^Custom \(\d+\) network$/) !== undefined, 'Expected to ') + }) + .perform(async () => { + const request = { + id: 9999, + jsonrpc: "2.0", + method: "net_listening", + params: [] + } + const result = true + await clickAndCheckLog(browser, 'hardhat-provider:sendAsync', {}, result, request) + }) } } diff --git a/apps/remix-ide/src/app/tabs/hardhat-provider.tsx b/apps/remix-ide/src/app/tabs/hardhat-provider.tsx index abb5eabddf..c84a6d09c2 100644 --- a/apps/remix-ide/src/app/tabs/hardhat-provider.tsx +++ b/apps/remix-ide/src/app/tabs/hardhat-provider.tsx @@ -66,7 +66,7 @@ export class HardhatProvider extends Plugin { value = await ((): Promise => { return new Promise((resolve, reject) => { const modalContent: AppModal = { - id: 'harrhatprovider', + id: 'hardhatprovider', title: 'Hardhat node request', message: this.hardhatProviderDialogBody(), modalType: ModalTypes.prompt, @@ -110,7 +110,7 @@ export class HardhatProvider extends Plugin { } catch (error) { this.blocked = true const modalContent: AlertModal = { - id: 'harrhatprovider', + id: 'hardhatprovider', title: 'Hardhat Provider', message: `Error while connecting to the hardhat provider: ${error.message}`, } diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index ea12ad7efa..97c5c4c7f9 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -237,7 +237,7 @@ export const setExecutionContext = (executionContext: { context: string, fork: s }, () => { setFinalContext() })) }, (alertMsg) => { dispatch(displayPopUp(alertMsg)) - }, setFinalContext()) + }, () => { setFinalContext() }) } export const setWeb3Endpoint = (endpoint: string) => { diff --git a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts index c932202aa5..9f0624d561 100644 --- a/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts +++ b/libs/remix-ui/run-tab/src/lib/reducers/runTab.ts @@ -171,6 +171,11 @@ export const runTabInitialState: RunTabState = { web3Dialog: null } +type AddProvider = { + name: string, + provider: any +} + export const runTabReducer = (state: RunTabState = runTabInitialState, action: Action) => { switch (action.type) { case 'FETCH_ACCOUNTS_LIST_REQUEST': { @@ -328,25 +333,32 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A } case 'ADD_PROVIDER': { - const payload: string = action.payload - + const payload: AddProvider = action.payload + const id = action.payload.name + state.providers.providerList.push({ + content: payload.name, + dataId: id, + id, + title: payload.name, + value: id + }) return { ...state, providers: { ...state.providers, - providerList: { ...state.providers.providerList, payload } + providerList: state.providers.providerList } } } case 'REMOVE_PROVIDER': { - const payload: string = action.payload - + const id: string = action.payload + const providers = state.providers.providerList.filter((el) => el.id !== id) return { ...state, providers: { ...state.providers, - providerList: delete state.providers.providerList[payload] ? state.providers.providerList : state.providers.providerList + providerList: providers } } } From 65de849f9820ee4ea98011a73963c947d7cb58a5 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 10 Jan 2022 16:19:20 +0100 Subject: [PATCH 2/4] fix using web3Dialog --- libs/remix-ui/run-tab/src/lib/actions/index.ts | 2 +- libs/remix-ui/run-tab/src/lib/actions/payload.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libs/remix-ui/run-tab/src/lib/actions/index.ts b/libs/remix-ui/run-tab/src/lib/actions/index.ts index 97c5c4c7f9..c659b2a802 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/index.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/index.ts @@ -110,7 +110,7 @@ const setupEvents = () => { export const initWebDialogs = (envToasterContent: (env: { context: string, fork: string }, from: string) => void, web3Dialog: () => void) => async (dispatch: React.Dispatch) => { dispatch(setEnvToasterContent(envToasterContent)) - dispatch(setWeb3Dialog) + dispatch(setWeb3Dialog(web3Dialog)) } const updateAccountBalances = () => { diff --git a/libs/remix-ui/run-tab/src/lib/actions/payload.ts b/libs/remix-ui/run-tab/src/lib/actions/payload.ts index bf1194c85b..4d70582ce3 100644 --- a/libs/remix-ui/run-tab/src/lib/actions/payload.ts +++ b/libs/remix-ui/run-tab/src/lib/actions/payload.ts @@ -278,9 +278,10 @@ export const setEnvToasterContent = (content: (env: { context: string, fork: str } } -export const setWeb3Dialog = () => { +export const setWeb3Dialog = (web3Dialog: () => void) => { return { - type: 'SET_WEB3_DIALOG' + type: 'SET_WEB3_DIALOG', + payload: web3Dialog } } From dd27d443b092154883bf24bbedb73cfa51192027 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 10 Jan 2022 16:49:19 +0100 Subject: [PATCH 3/4] linting --- apps/remix-ide-e2e/src/tests/plugin_api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.ts b/apps/remix-ide-e2e/src/tests/plugin_api.ts index d3ce74a639..1741a5a66b 100644 --- a/apps/remix-ide-e2e/src/tests/plugin_api.ts +++ b/apps/remix-ide-e2e/src/tests/plugin_api.ts @@ -340,8 +340,8 @@ module.exports = { .perform(async () => { const request = { id: 9999, - jsonrpc: "2.0", - method: "net_listening", + jsonrpc: '2.0', + method: 'net_listening', params: [] } const result = true From 51e969d4a6bbdc7ab989b81221aa99449de4fd06 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 10 Jan 2022 17:00:27 +0100 Subject: [PATCH 4/4] fix E2E test --- .../src/local-plugin/src/app/app.tsx | 2 +- apps/remix-ide-e2e/src/tests/plugin_api.ts | 21 ++++++++++++------- apps/remix-ide/ci/browser_tests_plugin_api.sh | 1 + 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx index 50c4699997..d1a559764e 100644 --- a/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx +++ b/apps/remix-ide-e2e/src/local-plugin/src/app/app.tsx @@ -33,7 +33,7 @@ function App () { useEffect(() => { client.onload(async () => { - const customProfiles = ['menuicons', 'tabs', 'solidityUnitTesting'] + const customProfiles = ['menuicons', 'tabs', 'solidityUnitTesting', 'hardhat-provider'] client.testCommand = async (data: any) => { console.log(data) diff --git a/apps/remix-ide-e2e/src/tests/plugin_api.ts b/apps/remix-ide-e2e/src/tests/plugin_api.ts index 1741a5a66b..b303864438 100644 --- a/apps/remix-ide-e2e/src/tests/plugin_api.ts +++ b/apps/remix-ide-e2e/src/tests/plugin_api.ts @@ -10,7 +10,7 @@ declare global { const localPluginData: Profile & LocationProfile & ExternalProfile = { name: 'localPlugin', displayName: 'Local Plugin', - canActivate: ['dGitProvider', 'flattener', 'solidityUnitTesting', 'udapp'], + canActivate: ['dGitProvider', 'flattener', 'solidityUnitTesting', 'udapp', 'hardhat-provider'], url: 'http://localhost:2020', location: 'sidePanel' } @@ -328,15 +328,20 @@ module.exports = { // PROVIDER - 'Should switch to hardhat provider (provider plugin)': async function (browser: NightwatchBrowser) { + 'Should switch to hardhat provider (provider plugin) #group8': function (browser: NightwatchBrowser) { browser + .frameParent() + .useCss() + .clickLaunchIcon('pluginManager') + .scrollAndClick('[data-id="pluginManagerComponentActivateButtonhardhat-provider"]') .clickLaunchIcon('udapp') - .click('*[data-id="Hardhat provider"]') + .click('*[data-id="Hardhat Provider"]') .modalFooterOKClick('hardhatprovider') .waitForElementContainsText('*[data-id="settingsNetworkEnv"]', 'Custom') // e.g Custom (1337) network - .getValue('*[data-id="settingsNetworkEnv"]', (result) => { - browser.assert.ok((result.value as string).match(/^Custom \(\d+\) network$/) !== undefined, 'Expected to ') - }) + .clickLaunchIcon('localPlugin') + .useXpath() + // @ts-ignore + .frame(0) .perform(async () => { const request = { id: 9999, @@ -344,8 +349,8 @@ module.exports = { method: 'net_listening', params: [] } - const result = true - await clickAndCheckLog(browser, 'hardhat-provider:sendAsync', {}, result, request) + const result = '{"jsonrpc":"2.0","result":true,"id":9999}' + await clickAndCheckLog(browser, 'hardhat-provider:sendAsync', result, null, request) }) } } diff --git a/apps/remix-ide/ci/browser_tests_plugin_api.sh b/apps/remix-ide/ci/browser_tests_plugin_api.sh index eae0d5b389..282b979c98 100755 --- a/apps/remix-ide/ci/browser_tests_plugin_api.sh +++ b/apps/remix-ide/ci/browser_tests_plugin_api.sh @@ -6,6 +6,7 @@ BUILD_ID=${CIRCLE_BUILD_NUM:-${TRAVIS_JOB_NUMBER}} echo "$BUILD_ID" TEST_EXITCODE=0 +npm run ganache-cli & npm run serve:production & npx nx serve remix-ide-e2e-src-local-plugin &