Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/debugger/src/app/debugger-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export const DebuggerApiMixin = (Base) => class extends Base {
}
return null
},
debugWithGeneratedSources: false
debugWithGeneratedSources: false,
fork: 'berlin'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the moment, debugger only decode the last fork op codes

})
return await debug.debugger.traceManager.getTrace(hash)
}
Expand Down
14 changes: 7 additions & 7 deletions apps/remix-ide-e2e/src/tests/recorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ contract t2est {

const records = `{
"accounts": {
"account{10}": "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"
"account{2}": "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c"
},
"linkReferences": {
"testLib": "created{1512830014773}"
Expand All @@ -146,7 +146,7 @@ const records = `{
"linkReferences": {},
"inputs": "()",
"type": "constructor",
"from": "account{10}"
"from": "account{2}"
}
},
{
Expand All @@ -172,7 +172,7 @@ const records = `{
"name": "",
"type": "constructor",
"inputs": "(uint256)",
"from": "account{10}"
"from": "account{2}"
}
},
{
Expand All @@ -188,7 +188,7 @@ const records = `{
"name": "set",
"inputs": "(uint256,address)",
"type": "function",
"from": "account{10}"
"from": "account{2}"
}
}
],
Expand Down Expand Up @@ -287,7 +287,7 @@ const records = `{

const scenario = {
accounts: {
'account{10}': '0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'
'account{2}': '0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c'
},
linkReferences: {},
transactions: [
Expand All @@ -305,7 +305,7 @@ const scenario = {
name: '',
type: 'constructor',
inputs: '(uint256)',
from: 'account{10}'
from: 'account{2}'
}
},
{
Expand All @@ -320,7 +320,7 @@ const scenario = {
name: 'set',
inputs: '(uint256)',
type: 'function',
from: 'account{10}'
from: 'account{2}'
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide-e2e/src/tests/terminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
'Call web3.eth.getAccounts() using JavaScript VM': function (browser: NightwatchBrowser) {
browser
.executeScript('web3.eth.getAccounts()')
.waitForElementContainsText('*[data-id="terminalJournal"]', '"0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c", "0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C", "0x4B0897b0513fdC7C541B6d9D7E929C4e5364D2dB", "0x583031D1113aD414F02576BD6afaBfb302140225", "0xdD870fA1b7C4700F2BD7f44238821C26f7392148"', 80000)
.waitForElementContainsText('*[data-id="terminalJournal"]', '"0xAb8483F64d9C6d1EcF9b849Ae677dD3315835cb2", "0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c", "0x4B20993Bc481177ec7E8f571ceCaE8A9e22C02db", "0x78731D3Ca6b7E34aC0F824c42a7cC18A495cabaB", "0x617F2E2fD72FD9D5503197092aC168c91465E7f2", "0x17F6AD8Ef982297579C203069C1DbfFE4348c372", "0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C"', 80000)
},

'Call web3.eth.getAccounts() using Web3 Provider': function (browser: NightwatchBrowser) {
Expand Down
15 changes: 15 additions & 0 deletions apps/remix-ide-e2e/src/tests/transactionExecution.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,21 @@ module.exports = {
.journalLastChildIncludes('Parameters:')
.journalLastChildIncludes('2,3,error_string_2')
.journalLastChildIncludes('Debug the transaction to get more information.')
},

'Should Compile and Deploy a contract which define a custom error, the error should be logged in the terminal , using London VM Fork': function (browser: NightwatchBrowser) {
browser
.click('*[data-id="settingsVMLondonMode"]') // switch to London fork
.selectAccount('0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c') // this account will be used for this test suite
.click('#runTabView button[class^="instanceButton"]')
.waitForElementPresent('.instance:nth-of-type(2)')
.click('.instance:nth-of-type(2) > div > button')
.clickFunction('g - transact (not payable)')
.journalLastChildIncludes('Error provided by the contract:')
.journalLastChildIncludes('CustomError')
.journalLastChildIncludes('Parameters:')
.journalLastChildIncludes('2,3,error_string_2')
.journalLastChildIncludes('Debug the transaction to get more information.')
.end()
}
}
Expand Down
31 changes: 24 additions & 7 deletions apps/remix-ide/src/app/tabs/runTab/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ class SettingsUI {
</label>
<div class="${css.environment}">
<select id="selectExEnvOptions" data-id="settingsSelectEnvOptions" class="form-control ${css.select} custom-select">
<option id="vm-mode"
<option id="vm-mode-berlin" data-id="settingsVMBerlinMode"
title="Execution environment does not connect to any node, everything is local and in memory only."
value="vm" name="executionContext"> JavaScript VM
value="vm-berlin" name="executionContext" fork="berlin" > JavaScript VM (Berlin)
</option>
<option id="injected-mode"
<option id="vm-mode-london" data-id="settingsVMLondonMode"
title="Execution environment does not connect to any node, everything is local and in memory only."
value="vm-london" name="executionContext" fork="london"> JavaScript VM (London)
</option>
<option id="injected-mode" data-id="settingsInjectedMode"
title="Execution environment has been provided by Metamask or similar provider."
value="injected" name="executionContext"> Injected Web3
</option>
Expand Down Expand Up @@ -236,11 +240,14 @@ class SettingsUI {
this.blockchain.event.register('removeProvider', name => removeProvider(name))

selectExEnv.addEventListener('change', (event) => {
const context = selectExEnv.options[selectExEnv.selectedIndex].value
this.setExecutionContext(context)
const provider = selectExEnv.options[selectExEnv.selectedIndex]
const fork = provider.getAttribute('fork') // can be undefined if connected to an external source (web3 provider / injected)
let context = provider.value
context = context.startsWith('vm') ? 'vm' : context // context has to be 'vm', 'web3' or 'injected'
this.setExecutionContext({ context, fork })
})

selectExEnv.value = this.blockchain.getProvider()
selectExEnv.value = this._getProviderDropdownValue()
}

setExecutionContext (context) {
Expand Down Expand Up @@ -278,9 +285,19 @@ class SettingsUI {
`
}

/**
* generate a value used by the env dropdown list.
* @return {String} - can return 'vm-berlin, 'vm-london', 'injected' or 'web3'
*/
_getProviderDropdownValue () {
const provider = this.blockchain.getProvider()
const fork = this.blockchain.getCurrentFork()
return provider === 'vm' ? provider + '-' + fork : provider
}

setFinalContext () {
// set the final context. Cause it is possible that this is not the one we've originaly selected
this.selectExEnv.value = this.blockchain.getProvider()
this.selectExEnv.value = this._getProviderDropdownValue()
this.event.trigger('clearInstance', [])
this.updatePlusButton()
}
Expand Down
8 changes: 8 additions & 0 deletions apps/remix-ide/src/blockchain/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ class Blockchain {
return this.executionContext.getProvider()
}

/**
* return the fork name applied to the current envionment
* @return {String} - fork name
*/
getCurrentFork () {
return this.executionContext.getCurrentFork()
}

isWeb3Provider () {
const isVM = this.getProvider() === 'vm'
const isInjected = this.getProvider() === 'injected'
Expand Down
21 changes: 16 additions & 5 deletions apps/remix-ide/src/blockchain/execution-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class ExecutionContext {
this.executionContext = null
this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault
this.currentFork = 'berlin'
this.defaultFork = 'berlin'
this.currentFork = this.defaultFork
this.mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
this.customNetWorks = {}
this.blocks = {}
Expand All @@ -48,6 +49,10 @@ export class ExecutionContext {
return this.executionContext
}

getCurrentFork () {
return this.currentFork
}

isVM () {
return this.executionContext === 'vm'
}
Expand All @@ -58,7 +63,7 @@ export class ExecutionContext {

web3 () {
if (this.customWeb3[this.executionContext]) return this.customWeb3[this.executionContext]
return this.isVM() ? this.vms[this.currentFork].web3vm : web3
return web3
}

detectNetwork (callback) {
Expand Down Expand Up @@ -118,16 +123,21 @@ export class ExecutionContext {
this.executionContextChange(context, endPointUrl, confirmCb, infoCb, null)
}

executionContextChange (context, endPointUrl, confirmCb, infoCb, cb) {
executionContextChange (value, endPointUrl, confirmCb, infoCb, cb) {
const context = value.context
const fork = value.fork || this.defaultFork
if (!cb) cb = () => {}
if (!confirmCb) confirmCb = () => {}
if (!infoCb) infoCb = () => {}
if (context === 'vm') {
this.executionContext = context
this.currentFork = fork
this.event.trigger('contextChanged', ['vm'])
return cb()
}

this.currentFork = this.defaultFork // in the case of injected and web3, we default to the last fork.

if (context === 'injected') {
if (injectedProvider === undefined) {
infoCb('No injected Web3 provider found. Make sure your provider (e.g. MetaMask) is active and running (when recently activated you may have to reload the page).')
Expand All @@ -147,7 +157,7 @@ export class ExecutionContext {
}
if (this.customNetWorks[context]) {
var network = this.customNetWorks[context]
this.setProviderFromEndpoint(network.provider, network.name, (error) => {
this.setProviderFromEndpoint(network.provider, { context: network.name }, (error) => {
if (error) infoCb(error)
cb()
})
Expand Down Expand Up @@ -184,8 +194,9 @@ export class ExecutionContext {

// TODO: remove this when this function is moved

setProviderFromEndpoint (endpoint, context, cb) {
setProviderFromEndpoint (endpoint, value, cb) {
const oldProvider = web3.currentProvider
const context = value.context

web3.setProvider(endpoint)
web3.eth.net.isListening((err, isConnected) => {
Expand Down
12 changes: 6 additions & 6 deletions apps/remix-ide/src/blockchain/providers/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ const { Provider, extend } = require('@remix-project/remix-simulator')
class VMProvider {
constructor (executionContext) {
this.executionContext = executionContext
this.RemixSimulatorProvider = new Provider({})
this.RemixSimulatorProvider.init()
this.web3 = new Web3(this.RemixSimulatorProvider)
extend(this.web3)
this.accounts = {}
this.executionContext.setWeb3('vm', this.web3)
}

getAccounts (cb) {
Expand All @@ -23,8 +17,14 @@ class VMProvider {
}

resetEnvironment () {
this.accounts = {}
this.RemixSimulatorProvider = new Provider({ fork: this.executionContext.getCurrentFork() })
this.RemixSimulatorProvider.init()
this.RemixSimulatorProvider.Accounts.resetAccounts()
this.web3 = new Web3(this.RemixSimulatorProvider)
extend(this.web3)
this.accounts = {}
this.executionContext.setWeb3('vm', this.web3)
}

// TODO: is still here because of the plugin API
Expand Down
6 changes: 3 additions & 3 deletions libs/remix-analyzer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
}
],
"dependencies": {
"@ethereumjs/block": "^3.2.1",
"@ethereumjs/tx": "^3.1.3",
"@ethereumjs/vm": "^5.3.2",
"@ethereumjs/block": "^3.3.0",
"@ethereumjs/tx": "^3.2.1",
"@ethereumjs/vm": "^5.4.1",
"@remix-project/remix-astwalker": "^0.0.26",
"@remix-project/remix-lib": "^0.5.0",
"async": "^2.6.2",
Expand Down
6 changes: 3 additions & 3 deletions libs/remix-astwalker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
]
},
"dependencies": {
"@ethereumjs/block": "^3.2.1",
"@ethereumjs/tx": "^3.1.3",
"@ethereumjs/vm": "^5.3.2",
"@ethereumjs/block": "^3.3.0",
"@ethereumjs/tx": "^3.2.1",
"@ethereumjs/vm": "^5.4.1",
"@remix-project/remix-lib": "^0.5.0",
"@types/tape": "^4.2.33",
"async": "^2.6.2",
Expand Down
6 changes: 3 additions & 3 deletions libs/remix-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
],
"main": "src/index.js",
"dependencies": {
"@ethereumjs/block": "^3.2.1",
"@ethereumjs/block": "^3.3.0",
"@ethereumjs/common": "^2.2.0",
"@ethereumjs/tx": "^3.1.3",
"@ethereumjs/vm": "^5.3.2",
"@ethereumjs/tx": "^3.2.1",
"@ethereumjs/vm": "^5.4.1",
"@remix-project/remix-astwalker": "^0.0.26",
"@remix-project/remix-lib": "^0.5.0",
"async": "^2.6.2",
Expand Down
4 changes: 2 additions & 2 deletions libs/remix-debug/src/Ethdebugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class Ethdebugger {
this.opts = opts

this.event = new EventManager()
this.traceManager = new TraceManager({ web3: this.web3 })
this.traceManager = new TraceManager({ web3: this.web3, fork: this.opts.fork })
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) })
this.storageResolver = null
Expand All @@ -55,7 +55,7 @@ export class Ethdebugger {
}

setManagers () {
this.traceManager = new TraceManager({ web3: this.web3 })
this.traceManager = new TraceManager({ web3: this.web3, fork: this.opts.fork })
this.codeManager = new CodeManager(this.traceManager)
this.solidityProxy = new SolidityProxy({ getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager) })
this.storageResolver = null
Expand Down
6 changes: 4 additions & 2 deletions libs/remix-debug/src/code/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EventManager } from '../eventManager'
import { isContractCreation } from '../trace/traceHelper'
import { findNodeAtInstructionIndex } from '../source/sourceMappingDecoder'
import { CodeResolver } from './codeResolver'
import { TraceManager } from '../trace/traceManager' // eslint-disable-line

/*
resolve contract code referenced by vmtrace in order to be used by asm listview.
Expand All @@ -15,7 +16,7 @@ import { CodeResolver } from './codeResolver'
export class CodeManager {
event
isLoading: boolean
traceManager
traceManager: TraceManager
codeResolver

constructor (_traceManager) {
Expand All @@ -32,7 +33,8 @@ export class CodeManager {
return resolve(code)
})
})
}
},
fork: this.traceManager.getCurrentFork()
})
}

Expand Down
6 changes: 4 additions & 2 deletions libs/remix-debug/src/code/codeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ export class CodeResolver {
bytecodeByAddress
instructionsByAddress
instructionsIndexByBytesOffset
fork

constructor ({ getCode }) {
constructor ({ getCode, fork }) {
this.getCode = getCode
this.bytecodeByAddress = {} // bytes code by contract addesses
this.instructionsByAddress = {} // assembly items instructions list by contract addesses
this.instructionsIndexByBytesOffset = {} // mapping between bytes offset and instructions index.
this.fork = fork
}

clear () {
Expand Down Expand Up @@ -39,7 +41,7 @@ export class CodeResolver {
}

formatCode (hexCode) {
const [code, instructionsIndexByBytesOffset] = nameOpCodes(Buffer.from(hexCode.substring(2), 'hex'))
const [code, instructionsIndexByBytesOffset] = nameOpCodes(Buffer.from(hexCode.substring(2), 'hex'), this.fork)
return { code, instructionsIndexByBytesOffset }
}

Expand Down
Loading