Skip to content

Commit 8ccdd09

Browse files
authored
Merge pull request #6074 from ethereum/yann300-patch-60
fix returning error
2 parents bced4b5 + a63c0a8 commit 8ccdd09

File tree

13 files changed

+50
-42
lines changed

13 files changed

+50
-42
lines changed

apps/remix-ide-e2e/src/commands/switchEnvironment.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NightwatchBrowser } from 'nightwatch'
22
import EventEmitter from 'events'
33

44
class switchEnvironment extends EventEmitter {
5-
command (this: NightwatchBrowser, provider: string): NightwatchBrowser {
5+
command (this: NightwatchBrowser, provider: string, returnWhenInitialized?: boolean): NightwatchBrowser {
66
this.api.useCss().waitForElementVisible('[data-id="settingsSelectEnvOptions"]')
77
.perform((done) => {
88
this.api.isPresent({ selector: `[data-id="selected-provider-${provider}"]`, suppressNotFoundErrors: true, timeout: 5000 }, (result) => {
@@ -20,11 +20,25 @@ class switchEnvironment extends EventEmitter {
2020
.click('[data-id="settingsSelectEnvOptions"] button')
2121
.waitForElementVisible(`[data-id="dropdown-item-${provider}"]`)
2222
.click(`[data-id="dropdown-item-${provider}"]`)
23+
.perform((done) => {
24+
if (returnWhenInitialized) {
25+
browser.waitForElementVisible(`[data-id="selected-provider-${provider}"]`).perform(() => done())
26+
} else {
27+
done()
28+
}
29+
})
2330
.perform(() => done())
2431
} else {
2532
browser.click('[data-id="settingsSelectEnvOptions"] button')
2633
.waitForElementVisible(`[data-id="dropdown-item-${provider}"]`)
2734
.click(`[data-id="dropdown-item-${provider}"]`)
35+
.perform((done) => {
36+
if (returnWhenInitialized) {
37+
browser.waitForElementVisible(`[data-id="selected-provider-${provider}"]`).perform(() => done())
38+
} else {
39+
done()
40+
}
41+
})
2842
.perform(() => done())
2943
}
3044
})

apps/remix-ide-e2e/src/tests/providers.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ module.exports = {
2525
selector: "//span[@class='text-danger' and contains(., 'Error while querying the provider')]",
2626
timeout: 10000
2727
})
28-
.waitForElementPresent({ selector: `[data-id="selected-provider-ganache-provider"]`, timeout: 5000 })
29-
.pause(1000)
3028
},
3129

3230
'Should switch to ganache provider, use the default ganache URL and succeed to connect #group1': function (browser: NightwatchBrowser) {

apps/remix-ide-e2e/src/tests/transactionExecution.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module.exports = {
167167
browser.testContracts('customError.sol', sources[4]['customError.sol'], ['C'])
168168
.clickLaunchIcon('udapp')
169169
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
170-
.click('.udapp_contractActionsContainerSingle > div')
170+
.createContract('')
171171
.clickInstance(0)
172172
.clickFunction('g - transact (not payable)')
173173
.journalLastChildIncludes('Error provided by the contract:')
@@ -188,9 +188,9 @@ module.exports = {
188188
.click('.remixui_compilerConfigSection')
189189
.setValue('#evmVersionSelector', 'london') // Set EVM version as fork version
190190
.clearTransactions()
191-
.switchEnvironment('vm-london') // switch to London fork
191+
.switchEnvironment('vm-london', true) // switch to London fork
192192
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
193-
.click('.udapp_contractActionsContainerSingle > div')
193+
.createContract('')
194194
.clickInstance(0)
195195
.clickFunction('g - transact (not payable)')
196196
.journalLastChildIncludes('Error provided by the contract:')

apps/remix-ide-e2e/src/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ declare module 'nightwatch' {
6969
getBrowserLogs(this: NightwatchBrowser): NightwatchBrowser
7070
currentSelectedFileIs(name: string): NightwatchBrowser
7171
switchWorkspace: (workspaceName: string) => NightwatchBrowser
72-
switchEnvironment: (provider: string) => NightwatchBrowser
72+
switchEnvironment: (provider: string, returnWhenInitialized?: boolean) => NightwatchBrowser
7373
pinGrid: (provider: string, status: boolean) => NightwatchBrowser
7474
connectToExternalHttpProvider: (url: string, identifier: string) => NightwatchBrowser
7575
waitForElementNotContainsText: (id: string, value: string, timeout: number = 10000) => NightwatchBrowser

apps/remix-ide/src/app/udapp/run-tab.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -364,27 +364,12 @@ class Provider {
364364
return new Promise((resolve, reject) => {
365365
this.udapp.call(this.name, 'sendAsync', payload).then((response) => {
366366
if (response.error) {
367-
reject(response.error.message)
367+
reject(response.error)
368368
} else {
369369
resolve(response.result? response.result : response)
370370
}
371371
}).catch((err) => {
372-
if (typeof err === 'string') {
373-
reject(err)
374-
} else if (err.error && err.error.message) {
375-
reject(err.error.message)
376-
} else if (err.error && typeof err.error === 'string') {
377-
reject(err.error)
378-
} else {
379-
let e
380-
try {
381-
e = JSON.stringify(err)
382-
} catch (e) {
383-
reject('unknown error')
384-
return
385-
}
386-
reject(e)
387-
}
372+
reject(err)
388373
})
389374
})
390375
}

apps/remix-ide/src/blockchain/execution-context.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class ExecutionContext {
3434
this.latestBlockNumber = 0
3535
this.txs = {}
3636
this.customWeb3 = {} // mapping between a context name and a web3.js instance
37+
this.isConnected = false
3738
}
3839

3940
init (config) {
@@ -143,13 +144,14 @@ export class ExecutionContext {
143144
if (!confirmCb) confirmCb = () => { /* Do nothing. */ }
144145
if (!infoCb) infoCb = () => { /* Do nothing. */ }
145146
if (this.customNetWorks[context]) {
147+
this.isConnected = false
146148
var network = this.customNetWorks[context]
147149
await network.init()
148150
this.currentFork = network.config.fork
149-
this.executionContext = context
150151
// injected
151152
web3.setProvider(network.provider)
152-
await this._updateChainContext()
153+
this.executionContext = context
154+
this.isConnected = await this._updateChainContext()
153155
this.event.trigger('contextChanged', [context])
154156
cb()
155157
}
@@ -181,8 +183,10 @@ export class ExecutionContext {
181183
} catch (e) {
182184
console.error(e)
183185
this.blockGasLimit = this.blockGasLimitDefault
186+
return false
184187
}
185188
}
189+
return true
186190
}
187191

188192
listenOnLastBlock () {

apps/remix-ide/src/blockchain/providers/node.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@ export class NodeProvider {
1414
}
1515

1616
getAccounts (cb) {
17+
if (!this.executionContext.isConnected) {
18+
return cb('Not connected to a node')
19+
}
1720
if (this.config.get('settings/personal-mode')) {
18-
return this.executionContext.web3().eth.personal.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
21+
this.executionContext.web3().eth.personal.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
22+
return
1923
}
20-
return this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
24+
this.executionContext.web3().eth.getAccounts().then(res => cb(null, res)).catch(err => cb(err))
2125
}
2226

2327
newAccount (passwordPromptCb, cb) {
28+
if (!this.executionContext.isConnected) {
29+
return cb('Not connected to a node')
30+
}
2431
if (!this.config.get('settings/personal-mode')) {
2532
return cb('Not running in personal mode')
2633
}
@@ -44,6 +51,9 @@ export class NodeProvider {
4451
}
4552

4653
signMessage (message, account, passphrase, cb) {
54+
if (!this.executionContext.isConnected) {
55+
return cb('Not connected to a node')
56+
}
4757
const messageHash = hashPersonalMessage(Buffer.from(message))
4858
try {
4959
const personal = new Personal(this.executionContext.web3().currentProvider)

libs/remix-ui/run-tab/src/lib/actions/account.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const fillAccountsList = async (plugin: RunTab, dispatch: React.Dispatch<
5555
}
5656
} catch (e) {
5757
plugin.call('notification', 'toast', `Cannot get account list: ${e}`)
58+
dispatch(fetchAccountsListFailed(e.message))
5859
}
5960
}
6061

@@ -78,9 +79,7 @@ export const setExecutionContext = (plugin: RunTab, dispatch: React.Dispatch<any
7879
} else {
7980
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
8081
plugin.call('notification', 'toast', alertMsg)
81-
}, async () => {
82-
setFinalContext(plugin, dispatch)
83-
})
82+
}, async () => {})
8483
}
8584
}
8685
}
@@ -315,9 +314,7 @@ const setWalletConnectExecutionContext = (plugin: RunTab, dispatch: React.Dispat
315314
plugin.on('walletconnect', 'connectionSuccessful', () => {
316315
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
317316
plugin.call('notification', 'toast', alertMsg)
318-
}, async () => {
319-
setFinalContext(plugin, dispatch)
320-
})
317+
}, async () => {})
321318
})
322319
plugin.on('walletconnect', 'connectionFailed', (msg) => {
323320
plugin.call('notification', 'toast', msg)

libs/remix-ui/run-tab/src/lib/actions/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { envChangeNotification } from "@remix-ui/helper"
22
import { RunTab } from "../types/run-tab"
33
import { setExecutionContext, setFinalContext, updateAccountBalances, fillAccountsList } from "./account"
4-
import { addExternalProvider, addInstance, addNewProxyDeployment, removeExternalProvider, setNetworkNameFromProvider, setPinnedChainId } from "./actions"
5-
import { addDeployOption, clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetProxyDeployments, resetUdapp, setCurrentContract, setCurrentFile, setLoadType, setRecorderCount, setRemixDActivated, setSendValue, fetchAccountsListSuccess } from "./payload"
4+
import { addExternalProvider, addInstance, addNewProxyDeployment, removeExternalProvider, setNetworkNameFromProvider, setPinnedChainId, setExecEnv } from "./actions"
5+
import { addDeployOption, clearAllInstances, clearRecorderCount, fetchContractListSuccess, resetProxyDeployments, resetUdapp, setCurrentContract, setCurrentFile, setLoadType, setRecorderCount, setRemixDActivated, setSendValue, fetchAccountsListSuccess, fetchAccountsListRequest } from "./payload"
66
import { updateInstanceBalance } from './deploy'
77
import { CompilerAbstract } from '@remix-project/remix-solidity'
88
import BN from 'bn.js'

libs/remix-ui/run-tab/src/lib/components/dropdownLabel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type DropDownLabelProps = {
77
label: string
88
bridges: any
99
currentProvider: any
10-
chainId: string
10+
envLabel: string
1111
runTabState: RunTabState
1212
setExecutionEnv: (executionContext: {
1313
context: string;
@@ -16,7 +16,7 @@ export type DropDownLabelProps = {
1616
plugin: any
1717
}
1818

19-
export function DropdownLabel({ label, bridges, currentProvider, chainId, runTabState, setExecutionEnv, isL2, plugin }: DropDownLabelProps) {
19+
export function DropdownLabel({ label, bridges, currentProvider, envLabel, runTabState, setExecutionEnv, isL2, plugin }: DropDownLabelProps) {
2020

2121
const [renderLabel, setRenderLabel] = useState(label)
2222

@@ -32,7 +32,7 @@ export function DropdownLabel({ label, bridges, currentProvider, chainId, runTab
3232
}
3333
}
3434
checkEnvLabels()
35-
}, [chainId])
35+
}, [envLabel])
3636

3737
return (
3838
<>

0 commit comments

Comments
 (0)