From e3a94d54e30fb17fa833b3c95d6e9ae30eeb04b3 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 16 Dec 2019 19:14:15 -0500 Subject: [PATCH 1/4] update remix-analyzer syntax to use const, let and this --- remix-analyzer/index.js | 2 +- remix-analyzer/src/solidity-analyzer/index.js | 23 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/remix-analyzer/index.js b/remix-analyzer/index.js index 01345200d8..539f26dd35 100644 --- a/remix-analyzer/index.js +++ b/remix-analyzer/index.js @@ -1,4 +1,4 @@ -var CodeAnalysis = require('./src/solidity-analyzer') +const CodeAnalysis = require('./src/solidity-analyzer') module.exports = { CodeAnalysis: CodeAnalysis diff --git a/remix-analyzer/src/solidity-analyzer/index.js b/remix-analyzer/src/solidity-analyzer/index.js index 8f3083d712..7eb5e7cdcd 100644 --- a/remix-analyzer/src/solidity-analyzer/index.js +++ b/remix-analyzer/src/solidity-analyzer/index.js @@ -1,14 +1,13 @@ 'use strict' -var AstWalker = require('remix-lib').AstWalker -var list = require('./modules/list') +const AstWalker = require('remix-lib').AstWalker +const list = require('./modules/list') function staticAnalysisRunner () { } staticAnalysisRunner.prototype.run = function (compilationResult, toRun, callback) { - var self = this - var modules = toRun.map(function (i) { - var m = self.modules()[i] + const modules = toRun.map((i) => { + const m = this.modules()[i] return { 'name': m.name, 'mod': new m.Module() } }) @@ -16,12 +15,12 @@ staticAnalysisRunner.prototype.run = function (compilationResult, toRun, callbac } staticAnalysisRunner.prototype.runWithModuleList = function (compilationResult, modules, callback) { - var reports = [] + let reports = [] // Also provide convenience analysis via the AST walker. - var walker = new AstWalker() - for (var k in compilationResult.sources) { - walker.walk(compilationResult.sources[k].legacyAST, {'*': function (node) { - modules.map(function (item, i) { + const walker = new AstWalker() + for (let k in compilationResult.sources) { + walker.walk(compilationResult.sources[k].legacyAST, {'*': (node) => { + modules.map((item, i) => { if (item.mod.visit !== undefined) { try { item.mod.visit(node) @@ -38,8 +37,8 @@ staticAnalysisRunner.prototype.runWithModuleList = function (compilationResult, // Here, modules can just collect the results from the AST walk, // but also perform new analysis. - reports = reports.concat(modules.map(function (item, i) { - var report = null + reports = reports.concat(modules.map((item, i) => { + let report = null try { report = item.mod.report(compilationResult) } catch (e) { From 84efca726286d4717da83b98e2ca9e3458afae49 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 16 Dec 2019 19:14:41 -0500 Subject: [PATCH 2/4] update remix-debug syntax to use const, let and this --- remix-debug/bin/rdb | 20 +- remix-debug/index.js | 16 +- remix-debug/src/Ethdebugger.js | 49 +++-- remix-debug/src/cmdline/contextManager.js | 25 ++- remix-debug/src/cmdline/index.js | 61 +++--- remix-debug/src/debugger/VmDebugger.js | 191 +++++++++--------- remix-debug/src/debugger/debugger.js | 69 +++---- remix-debug/src/debugger/solidityLocals.js | 40 ++-- remix-debug/src/debugger/solidityState.js | 53 +++-- remix-debug/src/debugger/stepManager.js | 63 +++--- remix-debug/src/solidity-decoder/astHelper.js | 40 ++-- .../src/solidity-decoder/decodeInfo.js | 78 +++---- remix-debug/src/solidity-decoder/index.js | 8 +- .../src/solidity-decoder/internalCallTree.js | 63 +++--- .../src/solidity-decoder/localDecoder.js | 14 +- .../src/solidity-decoder/solidityProxy.js | 22 +- .../src/solidity-decoder/stateDecoder.js | 18 +- .../src/solidity-decoder/types/Address.js | 4 +- .../src/solidity-decoder/types/ArrayType.js | 28 +-- .../src/solidity-decoder/types/Bool.js | 4 +- .../types/DynamicByteArray.js | 24 +-- .../src/solidity-decoder/types/Enum.js | 6 +- .../solidity-decoder/types/FixedByteArray.js | 2 +- remix-debug/src/solidity-decoder/types/Int.js | 4 +- .../src/solidity-decoder/types/Mapping.js | 34 ++-- .../src/solidity-decoder/types/RefType.js | 4 +- .../src/solidity-decoder/types/StringType.js | 10 +- .../src/solidity-decoder/types/Struct.js | 12 +- .../src/solidity-decoder/types/Uint.js | 4 +- .../src/solidity-decoder/types/ValueType.js | 4 +- .../src/solidity-decoder/types/util.js | 14 +- remix-debug/src/storage/mappingPreimages.js | 22 +- remix-debug/src/storage/storageResolver.js | 11 +- remix-debug/src/storage/storageViewer.js | 8 +- 34 files changed, 498 insertions(+), 527 deletions(-) diff --git a/remix-debug/bin/rdb b/remix-debug/bin/rdb index 6e0945952a..fcee04b8d8 100755 --- a/remix-debug/bin/rdb +++ b/remix-debug/bin/rdb @@ -25,15 +25,15 @@ program .option('--node [url]', 'node to connect to') .parse(process.argv) -var CmdLine = require('../src/cmdline/index.js') +const CmdLine = require('../src/cmdline/index.js') -var solc = require('solc') -var fs = require('fs') +const solc = require('solc') +const fs = require('fs') -var filename = 'test/sol/simple_storage.sol' -var shortFilename = 'simple_storage.sol' +const filename = 'test/sol/simple_storage.sol' +const shortFilename = 'simple_storage.sol' -var inputJson = { +const inputJson = { language: 'Solidity', sources: { }, @@ -55,17 +55,17 @@ inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString( console.log('compiling...') -let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson))) -var compilation = {} +const compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson))) +const compilation = {} compilation.data = compilationData compilation.source = { sources: inputJson.sources } -var cmdLine = new CmdLine() +const cmdLine = new CmdLine() cmdLine.connect('http', 'http://localhost:8545') cmdLine.loadCompilationResult(compilation) cmdLine.initDebugger() -var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa' +const tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa' cmdLine.startDebug(tx, shortFilename) diff --git a/remix-debug/index.js b/remix-debug/index.js index 6c90d8fb0c..589f40391e 100644 --- a/remix-debug/index.js +++ b/remix-debug/index.js @@ -1,15 +1,15 @@ 'use strict' -var EthDebugger = require('./src/Ethdebugger') -var TransactionDebugger = require('./src/debugger/debugger') -var CmdLine = require('./src/cmdline') +const EthDebugger = require('./src/Ethdebugger') +const TransactionDebugger = require('./src/debugger/debugger') +const CmdLine = require('./src/cmdline') -var StorageViewer = require('./src/storage/storageViewer') -var StorageResolver = require('./src/storage/storageResolver') +const StorageViewer = require('./src/storage/storageViewer') +const StorageResolver = require('./src/storage/storageResolver') -var SolidityDecoder = require('./src/solidity-decoder') +const SolidityDecoder = require('./src/solidity-decoder') -var remixLib = require('remix-lib') -var BreakpointManager = remixLib.code.BreakpointManager +const remixLib = require('remix-lib') +const BreakpointManager = remixLib.code.BreakpointManager /* Use of breakPointManager : diff --git a/remix-debug/src/Ethdebugger.js b/remix-debug/src/Ethdebugger.js index 157cc10e1b..95b8cacba0 100644 --- a/remix-debug/src/Ethdebugger.js +++ b/remix-debug/src/Ethdebugger.js @@ -1,19 +1,19 @@ 'use strict' -var StorageViewer = require('./storage/storageViewer') -var StorageResolver = require('./storage/storageResolver') +const StorageViewer = require('./storage/storageViewer') +const StorageResolver = require('./storage/storageResolver') -var SolidityDecoder = require('./solidity-decoder') -var SolidityProxy = SolidityDecoder.SolidityProxy -var stateDecoder = SolidityDecoder.stateDecoder -var localDecoder = SolidityDecoder.localDecoder -var InternalCallTree = SolidityDecoder.InternalCallTree +const SolidityDecoder = require('./solidity-decoder') +const SolidityProxy = SolidityDecoder.SolidityProxy +const stateDecoder = SolidityDecoder.stateDecoder +const localDecoder = SolidityDecoder.localDecoder +const InternalCallTree = SolidityDecoder.InternalCallTree -var remixLib = require('remix-lib') -var TraceManager = remixLib.trace.TraceManager -var CodeManager = remixLib.code.CodeManager -var traceHelper = remixLib.helpers.trace -var EventManager = remixLib.EventManager +const remixLib = require('remix-lib') +const TraceManager = remixLib.trace.TraceManager +const CodeManager = remixLib.code.CodeManager +const traceHelper = remixLib.helpers.trace +const EventManager = remixLib.EventManager /** * Ethdebugger is a wrapper around a few classes that helps debugging a transaction @@ -75,7 +75,7 @@ Ethdebugger.prototype.sourceLocationFromVMTraceIndex = function (address, stepIn } Ethdebugger.prototype.sourceLocationFromInstructionIndex = function (address, instIndex, callback) { - this.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, instIndex, this.solidityProxy.contracts, function (error, rawLocation) { + this.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, instIndex, this.solidityProxy.contracts, (error, rawLocation) => { callback(error, rawLocation) }) } @@ -98,10 +98,10 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback) step, (error, result) => { if (!error) { - var stack = result[0].value - var memory = result[1].value + const stack = result[0].value + const memory = result[1].value try { - var storageViewer = new StorageViewer({ + const storageViewer = new StorageViewer({ stepIndex: step, tx: this.tx, address: result[2].value @@ -124,7 +124,7 @@ Ethdebugger.prototype.decodeLocalsAt = function (step, sourceLocation, callback) /* decode state */ Ethdebugger.prototype.extractStateAt = function (step, callback) { - this.solidityProxy.extractStateVariablesAt(step, function (error, stateVars) { + this.solidityProxy.extractStateVariablesAt(step, (error, stateVars) => { callback(error, stateVars) }) } @@ -132,7 +132,7 @@ Ethdebugger.prototype.extractStateAt = function (step, callback) { Ethdebugger.prototype.decodeStateAt = function (step, stateVars, callback) { this.traceManager.getCurrentCalledAddressAt(step, (error, address) => { if (error) return callback(error) - var storageViewer = new StorageViewer({ + const storageViewer = new StorageViewer({ stepIndex: step, tx: this.tx, address: address @@ -175,16 +175,15 @@ Ethdebugger.prototype.debug = function (tx) { } this.setCompilationResult(this.opts.compilationResult()) this.tx = tx - var self = this - this.traceManager.resolveTrace(tx, function (error, result) { + this.traceManager.resolveTrace(tx, (error, result) => { if (result) { - self.event.trigger('newTraceLoaded', [self.traceManager.trace]) - if (self.breakpointManager && self.breakpointManager.hasBreakpoint()) { - self.breakpointManager.jumpNextBreakpoint(false) + this.event.trigger('newTraceLoaded', [this.traceManager.trace]) + if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { + this.breakpointManager.jumpNextBreakpoint(false) } - self.storageResolver = new StorageResolver({web3: self.traceManager.web3}) + this.storageResolver = new StorageResolver({web3: this.traceManager.web3}) } else { - self.statusMessage = error ? error.message : 'Trace not loaded' + this.statusMessage = error ? error.message : 'Trace not loaded' } }) } diff --git a/remix-debug/src/cmdline/contextManager.js b/remix-debug/src/cmdline/contextManager.js index a5cb6ace88..8e2ec5a934 100644 --- a/remix-debug/src/cmdline/contextManager.js +++ b/remix-debug/src/cmdline/contextManager.js @@ -1,9 +1,9 @@ -var remixLib = require('remix-lib') +const remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -var Web3Providers = remixLib.vm.Web3Providers -var DummyProvider = remixLib.vm.DummyProvider -var init = remixLib.init +const EventManager = remixLib.EventManager +const Web3Providers = remixLib.vm.Web3Providers +const DummyProvider = remixLib.vm.DummyProvider +const init = remixLib.init class ContextManager { constructor (executionContext) { @@ -33,23 +33,22 @@ class ContextManager { } switchProvider (type, cb) { - var self = this - this.web3Providers.get(type, function (error, obj) { + this.web3Providers.get(type, (error, obj) => { if (error) { // console.log('provider ' + type + ' not defined') } else { - self.web3 = obj - self.executionContext.detectNetwork((error, network) => { + this.web3 = obj + this.executionContext.detectNetwork((error, network) => { if (error || !network) { - self.web3 = obj + this.web3 = obj } else { var webDebugNode = init.web3DebugNode(network.name) - self.web3 = (!webDebugNode ? obj : webDebugNode) + this.web3 = (!webDebugNode ? obj : webDebugNode) } - self.event.trigger('providerChanged', [type, self.web3]) + this.event.trigger('providerChanged', [type, this.web3]) if (cb) return cb() }) - self.event.trigger('providerChanged', [type, self.web3]) + this.event.trigger('providerChanged', [type, this.web3]) } }) } diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index a9f6a7f730..c34f5596cc 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -1,9 +1,9 @@ -var Web3 = require('web3') -var Debugger = require('../debugger/debugger.js') -var ContextManager = require('./contextManager.js') -var EventManager = require('events') -var remixLib = require('remix-lib') -var executionContext = remixLib.execution.executionContext +const Web3 = require('web3') +const Debugger = require('../debugger/debugger.js') +const ContextManager = require('./contextManager.js') +const EventManager = require('events') +const remixLib = require('remix-lib') +const executionContext = remixLib.execution.executionContext class CmdLine { @@ -20,7 +20,7 @@ class CmdLine { } loadCompilationData (inputJson, outputJson) { - let data = {} + const data = {} data.data = outputJson data.source = { sources: inputJson.sources } this.loadCompilationResult(data) @@ -32,7 +32,6 @@ class CmdLine { } initDebugger (cb) { - const self = this this.contextManager = new ContextManager(this.executionContext) this.debugger = new Debugger({ @@ -41,7 +40,7 @@ class CmdLine { }) this.contextManager.event.register('providerChanged', () => { - self.debugger.updateWeb3(self.contextManager.getWeb3()) + this.debugger.updateWeb3(this.contextManager.getWeb3()) }) this.contextManager.initProviders() @@ -51,15 +50,13 @@ class CmdLine { } getSource () { - const self = this - - let lineColumnPos = this.lineColumnPos + const lineColumnPos = this.lineColumnPos if (!lineColumnPos || !lineColumnPos.start) return [] - let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') + const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') - let source = [] + const source = [] let line line = content[lineColumnPos.start.line - 2] @@ -71,13 +68,13 @@ class CmdLine { source.push(' ' + lineColumnPos.start.line + ': ' + line) } - let currentLineNumber = lineColumnPos.start.line - let currentLine = content[currentLineNumber] + const currentLineNumber = lineColumnPos.start.line + const currentLine = content[currentLineNumber] source.push('=> ' + (currentLineNumber + 1) + ': ' + currentLine) - let startLine = lineColumnPos.start.line + const startLine = lineColumnPos.start.line for (var i = 1; i < 4; i++) { - let line = content[startLine + i] + const line = content[startLine + i] source.push(' ' + (startLine + i + 1) + ': ' + line) } @@ -85,34 +82,33 @@ class CmdLine { } getCurrentLine () { - let lineColumnPos = this.lineColumnPos + const lineColumnPos = this.lineColumnPos if (!lineColumnPos) return '' - let currentLineNumber = lineColumnPos.start.line - let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') + const currentLineNumber = lineColumnPos.start.line + const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') return content[currentLineNumber] } startDebug (txNumber, filename, cb) { - const self = this this.filename = filename this.txHash = txNumber this.debugger.debug(null, txNumber, null, () => { - self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { - self.lineColumnPos = lineColumnPos - self.rawLocation = rawLocation - self.events.emit('source', [lineColumnPos, rawLocation]) + this.debugger.event.register('newSourceLocation', (lineColumnPos, rawLocation) => { + this.lineColumnPos = lineColumnPos + this.rawLocation = rawLocation + this.events.emit('source', [lineColumnPos, rawLocation]) }) - self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => { - self.solidityState = data - self.events.emit('globals', data) + this.debugger.vmDebuggerLogic.event.register('solidityState', (data) => { + this.solidityState = data + this.events.emit('globals', data) }) // TODO: this doesnt work too well, it should request the data instead... - self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => { + this.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => { if (JSON.stringify(data) === '{}') return - self.solidityLocals = data - self.events.emit('locals', data) + this.solidityLocals = data + this.events.emit('locals', data) }) if (cb) { @@ -215,4 +211,3 @@ class CmdLine { } module.exports = CmdLine - diff --git a/remix-debug/src/debugger/VmDebugger.js b/remix-debug/src/debugger/VmDebugger.js index 1ec8029e23..52145e1b92 100644 --- a/remix-debug/src/debugger/VmDebugger.js +++ b/remix-debug/src/debugger/VmDebugger.js @@ -1,11 +1,11 @@ -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -var ui = remixLib.helpers.ui -var StorageResolver = require('../storage/storageResolver') -var StorageViewer = require('../storage/storageViewer') +const remixLib = require('remix-lib') +const EventManager = remixLib.EventManager +const ui = remixLib.helpers.ui +const StorageResolver = require('../storage/storageResolver') +const StorageViewer = require('../storage/storageViewer') -var DebuggerSolidityState = require('./solidityState') -var DebuggerSolidityLocals = require('./solidityLocals') +const DebuggerSolidityState = require('./solidityState') +const DebuggerSolidityLocals = require('./solidityLocals') class VmDebuggerLogic { @@ -36,151 +36,145 @@ class VmDebuggerLogic { } listenToEvents () { - const self = this - this.debugger.event.register('traceUnloaded', function () { - self.event.trigger('traceUnloaded') + this.debugger.event.register('traceUnloaded', () => { + this.event.trigger('traceUnloaded') }) - this.debugger.event.register('newTraceLoaded', function () { - self.event.trigger('newTraceLoaded') + this.debugger.event.register('newTraceLoaded', () => { + this.event.trigger('newTraceLoaded') }) } listenToCodeManagerEvents () { - const self = this - this._codeManager.event.register('changed', function (code, address, index) { - self.event.trigger('codeManagerChanged', [code, address, index]) + this._codeManager.event.register('changed', (code, address, index) => { + this.event.trigger('codeManagerChanged', [code, address, index]) }) } listenToTraceManagerEvents () { - const self = this - - this.event.register('indexChanged', this, function (index) { + this.event.register('indexChanged', this, (index) => { if (index < 0) return - if (self.stepManager.currentStepIndex !== index) return + if (this.stepManager.currentStepIndex !== index) return - self.event.trigger('indexUpdate', [index]) + this.event.trigger('indexUpdate', [index]) - self._traceManager.getCallDataAt(index, function (error, calldata) { + this._traceManager.getCallDataAt(index, (error, calldata) => { if (error) { // console.log(error) - self.event.trigger('traceManagerCallDataUpdate', [{}]) - } else if (self.stepManager.currentStepIndex === index) { - self.event.trigger('traceManagerCallDataUpdate', [calldata]) + this.event.trigger('traceManagerCallDataUpdate', [{}]) + } else if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerCallDataUpdate', [calldata]) } }) - self._traceManager.getMemoryAt(index, function (error, memory) { + this._traceManager.getMemoryAt(index, (error, memory) => { if (error) { // console.log(error) - self.event.trigger('traceManagerMemoryUpdate', [{}]) - } else if (self.stepManager.currentStepIndex === index) { - self.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) + this.event.trigger('traceManagerMemoryUpdate', [{}]) + } else if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) } }) - self._traceManager.getCallStackAt(index, function (error, callstack) { + this._traceManager.getCallStackAt(index, (error, callstack) => { if (error) { // console.log(error) - self.event.trigger('traceManagerCallStackUpdate', [{}]) - } else if (self.stepManager.currentStepIndex === index) { - self.event.trigger('traceManagerCallStackUpdate', [callstack]) + this.event.trigger('traceManagerCallStackUpdate', [{}]) + } else if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerCallStackUpdate', [callstack]) } }) - self._traceManager.getStackAt(index, function (error, callstack) { + this._traceManager.getStackAt(index, (error, callstack) => { if (error) { // console.log(error) - self.event.trigger('traceManagerStackUpdate', [{}]) - } else if (self.stepManager.currentStepIndex === index) { - self.event.trigger('traceManagerStackUpdate', [callstack]) + this.event.trigger('traceManagerStackUpdate', [{}]) + } else if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerStackUpdate', [callstack]) } }) - self._traceManager.getCurrentCalledAddressAt(index, (error, address) => { + this._traceManager.getCurrentCalledAddressAt(index, (error, address) => { if (error) return - if (!self.storageResolver) return + if (!this.storageResolver) return - var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: address }, self.storageResolver, self._traceManager) + var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) storageViewer.storageRange((error, storage) => { if (error) { // console.log(error) - self.event.trigger('traceManagerStorageUpdate', [{}]) - } else if (self.stepManager.currentStepIndex === index) { + this.event.trigger('traceManagerStorageUpdate', [{}]) + } else if (this.stepManager.currentStepIndex === index) { var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...' - self.event.trigger('traceManagerStorageUpdate', [storage, header]) + this.event.trigger('traceManagerStorageUpdate', [storage, header]) } }) }) - self._traceManager.getCurrentStep(index, function (error, step) { - self.event.trigger('traceCurrentStepUpdate', [error, step]) + this._traceManager.getCurrentStep(index, (error, step) => { + this.event.trigger('traceCurrentStepUpdate', [error, step]) }) - self._traceManager.getMemExpand(index, function (error, addmem) { - self.event.trigger('traceMemExpandUpdate', [error, addmem]) + this._traceManager.getMemExpand(index, (error, addmem) => { + this.event.trigger('traceMemExpandUpdate', [error, addmem]) }) - self._traceManager.getStepCost(index, function (error, gas) { - self.event.trigger('traceStepCostUpdate', [error, gas]) + this._traceManager.getStepCost(index, (error, gas) => { + this.event.trigger('traceStepCostUpdate', [error, gas]) }) - self._traceManager.getCurrentCalledAddressAt(index, function (error, address) { - self.event.trigger('traceCurrentCalledAddressAtUpdate', [error, address]) + this._traceManager.getCurrentCalledAddressAt(index, (error, address) => { + this.event.trigger('traceCurrentCalledAddressAtUpdate', [error, address]) }) - self._traceManager.getRemainingGas(index, function (error, remaining) { - self.event.trigger('traceRemainingGasUpdate', [error, remaining]) + this._traceManager.getRemainingGas(index, (error, remaining) => { + this.event.trigger('traceRemainingGasUpdate', [error, remaining]) }) - self._traceManager.getReturnValue(index, function (error, returnValue) { + this._traceManager.getReturnValue(index, (error, returnValue) => { if (error) { - self.event.trigger('traceReturnValueUpdate', [[error]]) - } else if (self.stepManager.currentStepIndex === index) { - self.event.trigger('traceReturnValueUpdate', [[returnValue]]) + this.event.trigger('traceReturnValueUpdate', [[error]]) + } else if (this.stepManager.currentStepIndex === index) { + this.event.trigger('traceReturnValueUpdate', [[returnValue]]) } }) }) } listenToFullStorageChanges () { - const self = this - this.address = [] this.traceLength = 0 - self.debugger.event.register('newTraceLoaded', function (length) { - self._traceManager.getAddresses(function (error, addresses) { + this.debugger.event.register('newTraceLoaded', (length) => { + this._traceManager.getAddresses((error, addresses) => { if (error) return - self.event.trigger('traceAddressesUpdate', [addresses]) - self.addresses = addresses + this.event.trigger('traceAddressesUpdate', [addresses]) + this.addresses = addresses }) - self._traceManager.getLength(function (error, length) { + this._traceManager.getLength((error, length) => { if (error) return - self.event.trigger('traceLengthUpdate', [length]) - self.traceLength = length + this.event.trigger('traceLengthUpdate', [length]) + this.traceLength = length }) }) - self.debugger.event.register('indexChanged', this, function (index) { + this.debugger.event.register('indexChanged', this, (index) => { if (index < 0) return - if (self.stepManager.currentStepIndex !== index) return - if (!self.storageResolver) return + if (this.stepManager.currentStepIndex !== index) return + if (!this.storageResolver) return // Clean up storage update - if (index === self.traceLength - 1) { - return self.event.trigger('traceStorageUpdate', [{}]) + if (index === this.traceLength - 1) { + return this.event.trigger('traceStorageUpdate', [{}]) } var storageJSON = {} - for (var k in self.addresses) { - var address = self.addresses[k] - var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: address }, self.storageResolver, self._traceManager) - storageViewer.storageRange(function (error, result) { + for (var k in this.addresses) { + var address = this.addresses[k] + var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this._traceManager) + storageViewer.storageRange((error, result) => { if (!error) { storageJSON[address] = result - self.event.trigger('traceStorageUpdate', [storageJSON]) + this.event.trigger('traceStorageUpdate', [storageJSON]) } }) } @@ -188,51 +182,48 @@ class VmDebuggerLogic { } listenToNewChanges () { - const self = this - self.debugger.event.register('newTraceLoaded', this, function () { - self.storageResolver = new StorageResolver({web3: self.debugger.web3}) - self.debuggerSolidityState.storageResolver = self.storageResolver - self.debuggerSolidityLocals.storageResolver = self.storageResolver - self.event.trigger('newTrace', []) + this.debugger.event.register('newTraceLoaded', this, () => { + this.storageResolver = new StorageResolver({web3: this.debugger.web3}) + this.debuggerSolidityState.storageResolver = this.storageResolver + this.debuggerSolidityLocals.storageResolver = this.storageResolver + this.event.trigger('newTrace', []) }) - self.debugger.callTree.event.register('callTreeReady', function () { - if (self.debugger.callTree.reducedTrace.length) { - return self.event.trigger('newCallTree', []) + this.debugger.callTree.event.register('callTreeReady', () => { + if (this.debugger.callTree.reducedTrace.length) { + return this.event.trigger('newCallTree', []) } }) } listenToSolidityStateEvents () { - const self = this this.event.register('indexChanged', this.debuggerSolidityState.init.bind(this.debuggerSolidityState)) - this.debuggerSolidityState.event.register('solidityState', function (state) { - self.event.trigger('solidityState', [state]) + this.debuggerSolidityState.event.register('solidityState', (state) => { + this.event.trigger('solidityState', [state]) }) - this.debuggerSolidityState.event.register('solidityStateMessage', function (message) { - self.event.trigger('solidityStateMessage', [message]) + this.debuggerSolidityState.event.register('solidityStateMessage', (message) => { + this.event.trigger('solidityStateMessage', [message]) }) - this.debuggerSolidityState.event.register('solidityStateUpdating', function () { - self.event.trigger('solidityStateUpdating', []) + this.debuggerSolidityState.event.register('solidityStateUpdating', () => { + this.event.trigger('solidityStateUpdating', []) }) this.event.register('traceUnloaded', this.debuggerSolidityState.reset.bind(this.debuggerSolidityState)) this.event.register('newTraceLoaded', this.debuggerSolidityState.reset.bind(this.debuggerSolidityState)) } listenToSolidityLocalsEvents () { - const self = this this.event.register('sourceLocationChanged', this.debuggerSolidityLocals.init.bind(this.debuggerSolidityLocals)) - this.debuggerSolidityLocals.event.register('solidityLocals', function (state) { - self.event.trigger('solidityLocals', [state]) + this.debuggerSolidityLocals.event.register('solidityLocals', (state) => { + this.event.trigger('solidityLocals', [state]) }) - this.debuggerSolidityLocals.event.register('solidityLocalsMessage', function (message) { - self.event.trigger('solidityLocalsMessage', [message]) + this.debuggerSolidityLocals.event.register('solidityLocalsMessage', (message) => { + this.event.trigger('solidityLocalsMessage', [message]) }) - this.debuggerSolidityLocals.event.register('solidityLocalsUpdating', function () { - self.event.trigger('solidityLocalsUpdating', []) + this.debuggerSolidityLocals.event.register('solidityLocalsUpdating', () => { + this.event.trigger('solidityLocalsUpdating', []) }) - this.debuggerSolidityLocals.event.register('traceReturnValueUpdate', function (data, header) { - self.event.trigger('traceReturnValueUpdate', [data, header]) + this.debuggerSolidityLocals.event.register('traceReturnValueUpdate', (data, header) => { + this.event.trigger('traceReturnValueUpdate', [data, header]) }) } diff --git a/remix-debug/src/debugger/debugger.js b/remix-debug/src/debugger/debugger.js index 4f5f5f92c7..a6c795b745 100644 --- a/remix-debug/src/debugger/debugger.js +++ b/remix-debug/src/debugger/debugger.js @@ -1,15 +1,14 @@ 'use strict' -var Ethdebugger = require('../Ethdebugger') -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -var traceHelper = remixLib.helpers.trace -var OffsetToColumnConverter = remixLib.OffsetToColumnConverter +const Ethdebugger = require('../Ethdebugger') +const remixLib = require('remix-lib') +const EventManager = remixLib.EventManager +const traceHelper = remixLib.helpers.trace +const OffsetToColumnConverter = remixLib.OffsetToColumnConverter -var StepManager = require('./stepManager') -var VmDebuggerLogic = require('./VmDebugger') +const StepManager = require('./stepManager') +const VmDebuggerLogic = require('./VmDebugger') function Debugger (options) { - var self = this this.event = new EventManager() this.offsetToLineColumnConverter = options.offsetToLineColumnConverter || (new OffsetToColumnConverter()) @@ -27,38 +26,37 @@ function Debugger (options) { }) this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { - return self.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) + return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) }, (step) => { - self.event.trigger('breakpointStep', [step]) + this.event.trigger('breakpointStep', [step]) }) this.debugger.setBreakpointManager(this.breakPointManager) - this.debugger.event.register('newTraceLoaded', this, function () { - self.event.trigger('debuggerStatus', [true]) + this.debugger.event.register('newTraceLoaded', this, () => { + this.event.trigger('debuggerStatus', [true]) }) - this.debugger.event.register('traceUnloaded', this, function () { - self.event.trigger('debuggerStatus', [false]) + this.debugger.event.register('traceUnloaded', this, () => { + this.event.trigger('debuggerStatus', [false]) }) - this.event.register('breakpointStep', function (step) { - self.step_manager.jumpTo(step) + this.event.register('breakpointStep', (step) => { + this.step_manager.jumpTo(step) }) } Debugger.prototype.registerAndHighlightCodeItem = function (index) { - const self = this // register selected code item, highlight the corresponding source location - if (!self.compiler.lastCompilationResult) return - self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { + if (!this.compiler.lastCompilationResult) return + this.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { if (error) return console.log(error) - self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { - if (!error && self.compiler.lastCompilationResult && self.compiler.lastCompilationResult.data) { - var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self.compiler.lastCompilationResult.source.sources, self.compiler.lastCompilationResult.data.sources) - self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) + this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, this.compiler.lastCompilationResult.data.contracts, (error, rawLocation) => { + if (!error && this.compiler.lastCompilationResult && this.compiler.lastCompilationResult.data) { + var lineColumnPos = this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) + this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) } else { - self.event.trigger('newSourceLocation', [null]) + this.event.trigger('newSourceLocation', [null]) } }) }) @@ -69,7 +67,7 @@ Debugger.prototype.updateWeb3 = function (web3) { } Debugger.prototype.debug = function (blockNumber, txNumber, tx, loadingCb) { - let web3 = this.debugger.web3 + const web3 = this.debugger.web3 return new Promise((resolve, reject) => { if (this.debugger.traceManager.isLoading) { @@ -106,13 +104,12 @@ Debugger.prototype.debug = function (blockNumber, txNumber, tx, loadingCb) { } Debugger.prototype.debugTx = function (tx, loadingCb) { - const self = this this.step_manager = new StepManager(this.debugger, this.debugger.traceManager) this.debugger.codeManager.event.register('changed', this, (code, address, instIndex) => { - self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, this.step_manager.currentStepIndex, this.debugger.solidityProxy.contracts, (error, sourceLocation) => { + this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, this.step_manager.currentStepIndex, this.debugger.solidityProxy.contracts, (error, sourceLocation) => { if (!error) { - self.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation]) + this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation]) } }) }) @@ -120,16 +117,16 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree) this.vmDebuggerLogic.start() - this.step_manager.event.register('stepChanged', this, function (stepIndex) { - if (typeof stepIndex !== 'number' || stepIndex >= self.step_manager.traceLength) { - return self.event.trigger('endDebug') + this.step_manager.event.register('stepChanged', this, (stepIndex) => { + if (typeof stepIndex !== 'number' || stepIndex >= this.step_manager.traceLength) { + return this.event.trigger('endDebug') } - self.debugger.codeManager.resolveStep(stepIndex, tx) - self.step_manager.event.trigger('indexChanged', [stepIndex]) - self.vmDebuggerLogic.event.trigger('indexChanged', [stepIndex]) - self.vmDebuggerLogic.debugger.event.trigger('indexChanged', [stepIndex]) - self.registerAndHighlightCodeItem(stepIndex) + this.debugger.codeManager.resolveStep(stepIndex, tx) + this.step_manager.event.trigger('indexChanged', [stepIndex]) + this.vmDebuggerLogic.event.trigger('indexChanged', [stepIndex]) + this.vmDebuggerLogic.debugger.event.trigger('indexChanged', [stepIndex]) + this.registerAndHighlightCodeItem(stepIndex) }) loadingCb() diff --git a/remix-debug/src/debugger/solidityLocals.js b/remix-debug/src/debugger/solidityLocals.js index fca807e27b..cc9550ea96 100644 --- a/remix-debug/src/debugger/solidityLocals.js +++ b/remix-debug/src/debugger/solidityLocals.js @@ -1,8 +1,8 @@ -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager +const remixLib = require('remix-lib') +const EventManager = remixLib.EventManager -var localDecoder = require('../solidity-decoder/localDecoder') -var StorageViewer = require('../storage/storageViewer') +const localDecoder = require('../solidity-decoder/localDecoder') +const StorageViewer = require('../storage/storageViewer') class DebuggerSolidityLocals { @@ -16,28 +16,26 @@ class DebuggerSolidityLocals { } init (sourceLocation) { - const self = this var decodeTimeout = null if (!this.storageResolver) { - return self.event.trigger('solidityLocalsMessage', ['storage not ready']) + return this.event.trigger('solidityLocalsMessage', ['storage not ready']) } if (decodeTimeout) { window.clearTimeout(decodeTimeout) } - self.event.trigger('solidityLocalsUpdating') - decodeTimeout = setTimeout(function () { - self.decode(sourceLocation) + this.event.trigger('solidityLocalsUpdating') + decodeTimeout = setTimeout(() => { + this.decode(sourceLocation) }, 500) } decode (sourceLocation) { - const self = this - self.event.trigger('solidityLocalsMessage', ['']) - self.traceManager.waterfall([ - self.traceManager.getStackAt, - self.traceManager.getMemoryAt, - self.traceManager.getCurrentCalledAddressAt], - self.stepManager.currentStepIndex, + this.event.trigger('solidityLocalsMessage', ['']) + this.traceManager.waterfall([ + this.traceManager.getStackAt, + this.traceManager.getMemoryAt, + this.traceManager.getCurrentCalledAddressAt], + this.stepManager.currentStepIndex, (error, result) => { if (error) { return error @@ -45,17 +43,17 @@ class DebuggerSolidityLocals { var stack = result[0].value var memory = result[1].value try { - var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: result[2].value }, self.storageResolver, self.traceManager) - localDecoder.solidityLocals(self.stepManager.currentStepIndex, self.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => { + var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: result[2].value }, this.storageResolver, this.traceManager) + localDecoder.solidityLocals(this.stepManager.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => { if (!locals.error) { - self.event.trigger('solidityLocals', [locals]) + this.event.trigger('solidityLocals', [locals]) } if (!Object.keys(locals).length) { - self.event.trigger('solidityLocalsMessage', ['no locals']) + this.event.trigger('solidityLocalsMessage', ['no locals']) } }) } catch (e) { - self.event.trigger('solidityLocalsMessage', [e.message]) + this.event.trigger('solidityLocalsMessage', [e.message]) } }) } diff --git a/remix-debug/src/debugger/solidityState.js b/remix-debug/src/debugger/solidityState.js index a7d9d0e256..880de15cb9 100644 --- a/remix-debug/src/debugger/solidityState.js +++ b/remix-debug/src/debugger/solidityState.js @@ -1,7 +1,7 @@ -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -var stateDecoder = require('../solidity-decoder/stateDecoder') -var StorageViewer = require('../storage/storageViewer') +const remixLib = require('remix-lib') +const EventManager = remixLib.EventManager +const stateDecoder = require('../solidity-decoder/stateDecoder') +const StorageViewer = require('../storage/storageViewer') class DebuggerSolidityState { @@ -17,28 +17,27 @@ class DebuggerSolidityState { } init (index) { - var self = this - var decodeTimeout = null + let decodeTimeout = null if (index < 0) { - return self.event.trigger('solidityStateMessage', ['invalid step index']) + return this.event.trigger('solidityStateMessage', ['invalid step index']) } - if (self.stepManager.currentStepIndex !== index) return - if (!self.solidityProxy.loaded()) { - return self.event.trigger('solidityStateMessage', ['invalid step index']) + if (this.stepManager.currentStepIndex !== index) return + if (!this.solidityProxy.loaded()) { + return this.event.trigger('solidityStateMessage', ['invalid step index']) } - if (!self.storageResolver) { + if (!this.storageResolver) { return } if (decodeTimeout) { window.clearTimeout(decodeTimeout) } - self.event.trigger('solidityStateUpdating') - decodeTimeout = setTimeout(function () { + this.event.trigger('solidityStateUpdating') + decodeTimeout = setTimeout(() => { // necessary due to some states that can crash the debugger try { - self.decode(index) + this.decode(index) } catch (err) { console.dir('====> error') console.dir(err) @@ -51,33 +50,31 @@ class DebuggerSolidityState { } decode (index) { - const self = this - self.traceManager.getCurrentCalledAddressAt(self.stepManager.currentStepIndex, function (error, address) { + this.traceManager.getCurrentCalledAddressAt(this.stepManager.currentStepIndex, (error, address) => { if (error) { - return self.event.trigger('solidityState', [{}]) + return this.event.trigger('solidityState', [{}]) } - if (self.stateVariablesByAddresses[address]) { - return self.extractStateVariables(self.stateVariablesByAddresses[address], address) + if (this.stateVariablesByAddresses[address]) { + return this.extractStateVariables(this.stateVariablesByAddresses[address], address) } - self.solidityProxy.extractStateVariablesAt(index, function (error, stateVars) { + this.solidityProxy.extractStateVariablesAt(index, (error, stateVars) => { if (error) { - return self.event.trigger('solidityState', [{}]) + return this.event.trigger('solidityState', [{}]) } - self.stateVariablesByAddresses[address] = stateVars - self.extractStateVariables(stateVars, address) + this.stateVariablesByAddresses[address] = stateVars + this.extractStateVariables(stateVars, address) }) }) } extractStateVariables (stateVars, address) { - const self = this - var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: address }, self.storageResolver, self.traceManager) + var storageViewer = new StorageViewer({ stepIndex: this.stepManager.currentStepIndex, tx: this.tx, address: address }, this.storageResolver, this.traceManager) stateDecoder.decodeState(stateVars, storageViewer).then((result) => { - self.event.trigger('solidityStateMessage', ['']) + this.event.trigger('solidityStateMessage', ['']) if (result.error) { - return self.event.trigger('solidityStateMessage', [result.error]) + return this.event.trigger('solidityStateMessage', [result.error]) } - self.event.trigger('solidityState', [result]) + this.event.trigger('solidityState', [result]) }) } diff --git a/remix-debug/src/debugger/stepManager.js b/remix-debug/src/debugger/stepManager.js index a49bea7632..78fed1af5a 100644 --- a/remix-debug/src/debugger/stepManager.js +++ b/remix-debug/src/debugger/stepManager.js @@ -1,6 +1,6 @@ -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -var util = remixLib.util +const remixLib = require('remix-lib') +const EventManager = remixLib.EventManager +const util = remixLib.util class DebuggerStepManager { @@ -17,57 +17,54 @@ class DebuggerStepManager { } listenToEvents () { - const self = this - - this.debugger.event.register('newTraceLoaded', this, function () { - self.traceManager.getLength(function (error, newLength) { + this.debugger.event.register('newTraceLoaded', this, () => { + this.traceManager.getLength((error, newLength) => { if (error) { return console.log(error) } - if (self.traceLength !== newLength) { - self.event.trigger('traceLengthChanged', [newLength]) - self.traceLength = newLength - self.codeTraceLength = self.calculateCodeLength() + if (this.traceLength !== newLength) { + this.event.trigger('traceLengthChanged', [newLength]) + this.traceLength = newLength + this.codeTraceLength = this.calculateCodeLength() } - self.jumpTo(0) + this.jumpTo(0) }) }) this.debugger.callTree.event.register('callTreeReady', () => { - if (self.debugger.callTree.functionCallStack.length) { - self.jumpTo(self.debugger.callTree.functionCallStack[0]) + if (this.debugger.callTree.functionCallStack.length) { + this.jumpTo(this.debugger.callTree.functionCallStack[0]) } }) this.event.register('indexChanged', this, (index) => { if (index < 0) return - if (self.currentStepIndex !== index) return + if (this.currentStepIndex !== index) return - self.traceManager.buildCallPath(index, (error, callsPath) => { + this.traceManager.buildCallPath(index, (error, callsPath) => { if (error) { console.log(error) - return self.event.trigger('revertWarning', ['']) + return this.event.trigger('revertWarning', ['']) } - self.currentCall = callsPath[callsPath.length - 1] - if (self.currentCall.reverted) { - let revertedReason = self.currentCall.outofgas ? 'outofgas' : '' - self.revertionPoint = self.currentCall.return - return self.event.trigger('revertWarning', [revertedReason]) + this.currentCall = callsPath[callsPath.length - 1] + if (this.currentCall.reverted) { + let revertedReason = this.currentCall.outofgas ? 'outofgas' : '' + this.revertionPoint = this.currentCall.return + return this.event.trigger('revertWarning', [revertedReason]) } for (var k = callsPath.length - 2; k >= 0; k--) { var parent = callsPath[k] if (!parent.reverted) continue - self.revertionPoint = parent.return - self.event.trigger('revertWarning', ['parenthasthrown']) + this.revertionPoint = parent.return + this.event.trigger('revertWarning', ['parenthasthrown']) } - self.event.trigger('revertWarning', ['']) + this.event.trigger('revertWarning', ['']) }) }) } triggerStepChanged (step) { - const self = this - this.traceManager.getLength(function (error, length) { + this.traceManager.getLength((error, length) => { let stepState = 'valid' if (error) { @@ -78,15 +75,15 @@ class DebuggerStepManager { stepState = 'end' } - let jumpOutDisabled = (step === self.traceManager.findStepOut(step)) + let jumpOutDisabled = (step === this.traceManager.findStepOut(step)) - self.event.trigger('stepChanged', [step, stepState, jumpOutDisabled]) + this.event.trigger('stepChanged', [step, stepState, jumpOutDisabled]) }) } stepIntoBack (solidityMode) { if (!this.traceManager.isLoaded()) return - var step = this.currentStepIndex - 1 + let step = this.currentStepIndex - 1 this.currentStepIndex = step if (solidityMode) { step = this.resolveToReducedTrace(step, -1) @@ -99,7 +96,7 @@ class DebuggerStepManager { stepIntoForward (solidityMode) { if (!this.traceManager.isLoaded()) return - var step = this.currentStepIndex + 1 + let step = this.currentStepIndex + 1 this.currentStepIndex = step if (solidityMode) { step = this.resolveToReducedTrace(step, 1) @@ -112,7 +109,7 @@ class DebuggerStepManager { stepOverBack (solidityMode) { if (!this.traceManager.isLoaded()) return - var step = this.traceManager.findStepOverBack(this.currentStepIndex) + let step = this.traceManager.findStepOverBack(this.currentStepIndex) if (solidityMode) { step = this.resolveToReducedTrace(step, -1) } @@ -122,7 +119,7 @@ class DebuggerStepManager { stepOverForward (solidityMode) { if (!this.traceManager.isLoaded()) return - var step = this.currentStepIndex + 1 + let step = this.currentStepIndex + 1 let scope = this.debugger.callTree.findScope(step) if (scope && scope.firstStep === step) { step = scope.lastStep + 1 diff --git a/remix-debug/src/solidity-decoder/astHelper.js b/remix-debug/src/solidity-decoder/astHelper.js index 88b3a63165..0c5518b9b6 100644 --- a/remix-debug/src/solidity-decoder/astHelper.js +++ b/remix-debug/src/solidity-decoder/astHelper.js @@ -1,6 +1,6 @@ 'use strict' -var remixLib = require('remix-lib') -var AstWalker = remixLib.AstWalker +const remixLib = require('remix-lib') +const AstWalker = remixLib.AstWalker /** * return all contract definitions of the given @astList @@ -9,14 +9,14 @@ var AstWalker = remixLib.AstWalker * @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts */ function extractContractDefinitions (sourcesList) { - var ret = { + const ret = { contractsById: {}, contractsByName: {}, sourcesByContract: {} } - var walker = new AstWalker() - for (var k in sourcesList) { - walker.walk(sourcesList[k].legacyAST, { 'ContractDefinition': function (node) { + const walker = new AstWalker() + for (let k in sourcesList) { + walker.walk(sourcesList[k].legacyAST, { 'ContractDefinition': (node) => { ret.contractsById[node.id] = node ret.sourcesByContract[node.id] = k ret.contractsByName[k + ':' + node.attributes.name] = node @@ -50,16 +50,16 @@ function extractStateDefinitions (contractName, sourcesList, contracts) { if (!contracts) { contracts = extractContractDefinitions(sourcesList) } - var node = contracts.contractsByName[contractName] + const node = contracts.contractsByName[contractName] if (node) { - var stateItems = [] - var stateVar = [] - var baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById) + const stateItems = [] + const stateVar = [] + const baseContracts = getLinearizedBaseContracts(node.id, contracts.contractsById) baseContracts.reverse() - for (var k in baseContracts) { - var ctr = baseContracts[k] - for (var i in ctr.children) { - var item = ctr.children[i] + for (let k in baseContracts) { + const ctr = baseContracts[k] + for (let i in ctr.children) { + const item = ctr.children[i] stateItems.push(item) if (item.name === 'VariableDeclaration') { stateVar.push(item) @@ -85,12 +85,12 @@ function extractStatesDefinitions (sourcesList, contracts) { if (!contracts) { contracts = extractContractDefinitions(sourcesList) } - var ret = {} - for (var contract in contracts.contractsById) { - var name = contracts.contractsById[contract].attributes.name - var source = contracts.sourcesByContract[contract] - var fullName = source + ':' + name - var state = extractStateDefinitions(fullName, sourcesList, contracts) + const ret = {} + for (let contract in contracts.contractsById) { + const name = contracts.contractsById[contract].attributes.name + const source = contracts.sourcesByContract[contract] + const fullName = source + ':' + name + const state = extractStateDefinitions(fullName, sourcesList, contracts) ret[fullName] = state ret[name] = state // solc < 0.4.9 } diff --git a/remix-debug/src/solidity-decoder/decodeInfo.js b/remix-debug/src/solidity-decoder/decodeInfo.js index e65f46ec28..52bdac9c47 100644 --- a/remix-debug/src/solidity-decoder/decodeInfo.js +++ b/remix-debug/src/solidity-decoder/decodeInfo.js @@ -1,17 +1,17 @@ 'use strict' -var AddressType = require('./types/Address') -var ArrayType = require('./types/ArrayType') -var BoolType = require('./types/Bool') -var BytesType = require('./types/DynamicByteArray') -var BytesXType = require('./types/FixedByteArray') -var EnumType = require('./types/Enum') -var StringType = require('./types/StringType') -var StructType = require('./types/Struct') -var IntType = require('./types/Int') -var UintType = require('./types/Uint') -var MappingType = require('./types/Mapping') -var util = require('./types/util') +const AddressType = require('./types/Address') +const ArrayType = require('./types/ArrayType') +const BoolType = require('./types/Bool') +const BytesType = require('./types/DynamicByteArray') +const BytesXType = require('./types/FixedByteArray') +const EnumType = require('./types/Enum') +const StringType = require('./types/StringType') +const StructType = require('./types/Struct') +const IntType = require('./types/Int') +const UintType = require('./types/Uint') +const MappingType = require('./types/Mapping') +const util = require('./types/util') /** * mapping decode the given @arg type @@ -20,12 +20,12 @@ var util = require('./types/util') * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function mapping (type, stateDefinitions, contractName) { - var match = type.match(/mapping\((.*?)=>(.*)\)$/) - var keyTypeName = match[1].trim() - var valueTypeName = match[2].trim() + const match = type.match(/mapping\((.*?)=>(.*)\)$/) + const keyTypeName = match[1].trim() + const valueTypeName = match[2].trim() - var keyType = parseType(keyTypeName, stateDefinitions, contractName, 'storage') - var valueType = parseType(valueTypeName, stateDefinitions, contractName, 'storage') + const keyType = parseType(keyTypeName, stateDefinitions, contractName, 'storage') + const valueType = parseType(valueTypeName, stateDefinitions, contractName, 'storage') var underlyingTypes = { 'keyType': keyType, @@ -42,7 +42,7 @@ function mapping (type, stateDefinitions, contractName) { */ function uint (type) { type === 'uint' ? 'uint256' : type - var storageBytes = parseInt(type.replace('uint', '')) / 8 + const storageBytes = parseInt(type.replace('uint', '')) / 8 return new UintType(storageBytes) } @@ -54,7 +54,7 @@ function uint (type) { */ function int (type) { type === 'int' ? 'int256' : type - var storageBytes = parseInt(type.replace('int', '')) / 8 + const storageBytes = parseInt(type.replace('int', '')) / 8 return new IntType(storageBytes) } @@ -105,7 +105,7 @@ function dynamicByteArray (type, stateDefinitions, contractName, location) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName} */ function fixedByteArray (type) { - var storageBytes = parseInt(type.replace('bytes', '')) + const storageBytes = parseInt(type.replace('bytes', '')) return new BytesXType(storageBytes) } @@ -139,8 +139,8 @@ function stringType (type, stateDefinitions, contractName, location) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray} */ function array (type, stateDefinitions, contractName, location) { - var arraySize - var match = type.match(/(.*)\[(.*?)\]( storage ref| storage pointer| memory| calldata)?$/) + let arraySize + const match = type.match(/(.*)\[(.*?)\]( storage ref| storage pointer| memory| calldata)?$/) if (!match) { console.log('unable to parse type ' + type) return null @@ -149,7 +149,7 @@ function array (type, stateDefinitions, contractName, location) { location = match[3].trim() } arraySize = match[2] === '' ? 'dynamic' : parseInt(match[2]) - var underlyingType = parseType(match[1], stateDefinitions, contractName, location) + const underlyingType = parseType(match[1], stateDefinitions, contractName, location) if (underlyingType === null) { console.log('unable to parse type ' + type) return null @@ -166,8 +166,8 @@ function array (type, stateDefinitions, contractName, location) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName, enum} */ function enumType (type, stateDefinitions, contractName) { - var match = type.match(/enum (.*)/) - var enumDef = getEnum(match[1], stateDefinitions, contractName) + const match = type.match(/enum (.*)/) + const enumDef = getEnum(match[1], stateDefinitions, contractName) if (enumDef === null) { console.log('unable to retrieve decode info of ' + type) return null @@ -185,12 +185,12 @@ function enumType (type, stateDefinitions, contractName) { * @return {Object} returns decoded info about the current type: { storageBytes, typeName, members} */ function struct (type, stateDefinitions, contractName, location) { - var match = type.match(/struct (\S*?)( storage ref| storage pointer| memory| calldata)?$/) + const match = type.match(/struct (\S*?)( storage ref| storage pointer| memory| calldata)?$/) if (match) { if (!location) { location = match[2].trim() } - var memberDetails = getStructMembers(match[1], stateDefinitions, contractName, location) // type is used to extract the ast struct definition + const memberDetails = getStructMembers(match[1], stateDefinitions, contractName, location) // type is used to extract the ast struct definition if (!memberDetails) return null return new StructType(memberDetails, location, match[1]) } else { @@ -207,15 +207,15 @@ function struct (type, stateDefinitions, contractName, location) { * @return {Array} - containing all value declaration of the current enum type */ function getEnum (type, stateDefinitions, contractName) { - var split = type.split('.') + const split = type.split('.') if (!split.length) { type = contractName + '.' + type } else { contractName = split[0] } - var state = stateDefinitions[contractName] + const state = stateDefinitions[contractName] if (state) { - for (var dec of state.stateDefinitions) { + for (let dec of state.stateDefinitions) { if (dec.attributes && dec.attributes.name && type === contractName + '.' + dec.attributes.name) { return dec } @@ -234,17 +234,17 @@ function getEnum (type, stateDefinitions, contractName) { * @return {Array} containing all members of the current struct type */ function getStructMembers (type, stateDefinitions, contractName, location) { - var split = type.split('.') + const split = type.split('.') if (!split.length) { type = contractName + '.' + type } else { contractName = split[0] } - var state = stateDefinitions[contractName] + const state = stateDefinitions[contractName] if (state) { - for (var dec of state.stateDefinitions) { + for (let dec of state.stateDefinitions) { if (dec.name === 'StructDefinition' && type === contractName + '.' + dec.attributes.name) { - var offsets = computeOffsets(dec.children, stateDefinitions, contractName, location) + const offsets = computeOffsets(dec.children, stateDefinitions, contractName, location) if (!offsets) { return null } @@ -275,7 +275,7 @@ function typeClass (fullType) { if (fullType.indexOf(' ') !== -1) { fullType = fullType.split(' ')[0] } - var char = fullType.indexOf('bytes') === 0 ? 'X' : '' + const char = fullType.indexOf('bytes') === 0 ? 'X' : '' return fullType.replace(/[0-9]+/g, char) } @@ -289,7 +289,7 @@ function typeClass (fullType) { * @return {Object} - return the corresponding decoder or null on error */ function parseType (type, stateDefinitions, contractName, location) { - var decodeInfos = { + const decodeInfos = { 'contract': address, 'address': address, 'array': array, @@ -303,7 +303,7 @@ function parseType (type, stateDefinitions, contractName, location) { 'uint': uint, 'mapping': mapping } - var currentType = typeClass(type) + const currentType = typeClass(type) if (currentType === null) { console.log('unable to retrieve decode info of ' + type) return null @@ -325,8 +325,8 @@ function parseType (type, stateDefinitions, contractName, location) { * @return {Array} - return an array of types item: {name, type, location}. location defines the byte offset and slot offset */ function computeOffsets (types, stateDefinitions, contractName, location) { - var ret = [] - var storagelocation = { + const ret = [] + const storagelocation = { offset: 0, slot: 0 } diff --git a/remix-debug/src/solidity-decoder/index.js b/remix-debug/src/solidity-decoder/index.js index ed92273450..ad2d3b753f 100644 --- a/remix-debug/src/solidity-decoder/index.js +++ b/remix-debug/src/solidity-decoder/index.js @@ -1,7 +1,7 @@ -var SolidityProxy = require('./solidityProxy') -var stateDecoder = require('./stateDecoder') -var localDecoder = require('./localDecoder') -var InternalCallTree = require('./internalCallTree') +const SolidityProxy = require('./solidityProxy') +const stateDecoder = require('./stateDecoder') +const localDecoder = require('./localDecoder') +const InternalCallTree = require('./internalCallTree') module.exports = { SolidityProxy: SolidityProxy, diff --git a/remix-debug/src/solidity-decoder/internalCallTree.js b/remix-debug/src/solidity-decoder/internalCallTree.js index 854813e80f..b3274de1b6 100644 --- a/remix-debug/src/solidity-decoder/internalCallTree.js +++ b/remix-debug/src/solidity-decoder/internalCallTree.js @@ -1,12 +1,12 @@ 'use strict' -var remixLib = require('remix-lib') -var SourceLocationTracker = remixLib.SourceLocationTracker -var AstWalker = remixLib.AstWalker -var EventManager = remixLib.EventManager -var decodeInfo = require('./decodeInfo') -var util = remixLib.util -var traceHelper = remixLib.helpers.trace -var typesUtil = require('./types/util.js') +const remixLib = require('remix-lib') +const SourceLocationTracker = remixLib.SourceLocationTracker +const AstWalker = remixLib.AstWalker +const EventManager = remixLib.EventManager +const decodeInfo = require('./decodeInfo') +const util = remixLib.util +const traceHelper = remixLib.helpers.trace +const typesUtil = require('./types/util.js') /** * Tree representing internal jump into function. @@ -79,15 +79,15 @@ class InternalCallTree { * @param {Int} vmtraceIndex - index on the vm trace */ findScope (vmtraceIndex) { - var scopes = Object.keys(this.scopeStarts) + const scopes = Object.keys(this.scopeStarts) if (!scopes.length) { return null } - var scopeId = util.findLowerBoundValue(vmtraceIndex, scopes) + let scopeId = util.findLowerBoundValue(vmtraceIndex, scopes) scopeId = this.scopeStarts[scopeId] - var scope = this.scopes[scopeId] + let scope = this.scopes[scopeId] while (scope.lastStep && scope.lastStep < vmtraceIndex && scope.firstStep > 0) { - var matched = scopeId.match(/(.\d|\d)$/) + const matched = scopeId.match(/(.\d|\d)$/) scopeId = scopeId.replace(matched[1], '') scope = this.scopes[scopeId] } @@ -95,11 +95,10 @@ class InternalCallTree { } extractSourceLocation (step) { - var self = this - return new Promise(function (resolve, reject) { - self.traceManager.getCurrentCalledAddressAt(step, (error, address) => { + return new Promise((resolve, reject) => { + this.traceManager.getCurrentCalledAddressAt(step, (error, address) => { if (!error) { - self.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, step, self.solidityProxy.contracts, (error, sourceLocation) => { + this.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, step, this.solidityProxy.contracts, (error, sourceLocation) => { if (!error) { return resolve(sourceLocation) } else { @@ -135,11 +134,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) { included.file === source.file) } - var currentSourceLocation = {start: -1, length: -1, file: -1} - var previousSourceLocation = currentSourceLocation + let currentSourceLocation = {start: -1, length: -1, file: -1} + let previousSourceLocation = currentSourceLocation while (step < tree.traceManager.trace.length) { - var sourceLocation - var newLocation = false + let sourceLocation + let newLocation = false try { sourceLocation = await tree.extractSourceLocation(step) if (!includedSource(sourceLocation, currentSourceLocation)) { @@ -153,11 +152,11 @@ async function buildTree (tree, step, scopeId, isExternalCall) { if (!sourceLocation) { return { outStep: step, error: 'InternalCallTree - No source Location. ' + step } } - var isCallInstruction = traceHelper.isCallInstruction(tree.traceManager.trace[step]) + const isCallInstruction = traceHelper.isCallInstruction(tree.traceManager.trace[step]) // we are checking if we are jumping in a new CALL or in an internal function if (isCallInstruction || sourceLocation.jump === 'i') { try { - var externalCallResult = await buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, isCallInstruction) + const externalCallResult = await buildTree(tree, step + 1, scopeId === '' ? subScope.toString() : scopeId + '.' + subScope, isCallInstruction) if (externalCallResult.error) { return { outStep: step, error: 'InternalCallTree - ' + externalCallResult.error } } else { @@ -190,7 +189,7 @@ function createReducedTrace (tree, index) { } function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLocation, previousSourceLocation) { - var variableDeclaration = resolveVariableDeclaration(tree, step, sourceLocation) + const variableDeclaration = resolveVariableDeclaration(tree, step, sourceLocation) // using the vm trace step, the current source location and the ast, // we check if the current vm trace step target a new ast node of type VariableDeclaration // that way we know that there is a new local variable from here. @@ -218,7 +217,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc } // we check here if we are at the beginning inside a new function. // if that is the case, we have to add to locals tree the inputs and output params - var functionDefinition = resolveFunctionDefinition(tree, step, previousSourceLocation) + const functionDefinition = resolveFunctionDefinition(tree, step, previousSourceLocation) if (functionDefinition && (newLocation && traceHelper.isJumpDestInstruction(tree.traceManager.trace[step - 1]) || functionDefinition.attributes.isConstructor)) { tree.functionCallStack.push(step) // means: the previous location was a function definition && JUMPDEST @@ -243,7 +242,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId, newLoc // and keep this in a cache function resolveVariableDeclaration (tree, step, sourceLocation) { if (!tree.variableDeclarationByFile[sourceLocation.file]) { - var ast = tree.solidityProxy.ast(sourceLocation) + const ast = tree.solidityProxy.ast(sourceLocation) if (ast) { tree.variableDeclarationByFile[sourceLocation.file] = extractVariableDeclarations(ast, tree.astWalker) } else { @@ -258,7 +257,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) { // and keep this in a cache function resolveFunctionDefinition (tree, step, sourceLocation) { if (!tree.functionDefinitionByFile[sourceLocation.file]) { - var ast = tree.solidityProxy.ast(sourceLocation) + const ast = tree.solidityProxy.ast(sourceLocation) if (ast) { tree.functionDefinitionByFile[sourceLocation.file] = extractFunctionDefinitions(ast, tree.astWalker) } else { @@ -270,7 +269,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) { } function extractVariableDeclarations (ast, astWalker) { - var ret = {} + const ret = {} astWalker.walk(ast, (node) => { if (node.name === 'VariableDeclaration') { ret[node.src] = node @@ -281,7 +280,7 @@ function extractVariableDeclarations (ast, astWalker) { } function extractFunctionDefinitions (ast, astWalker) { - var ret = {} + const ret = {} astWalker.walk(ast, (node) => { if (node.name === 'FunctionDefinition') { ret[node.src] = node @@ -292,11 +291,11 @@ function extractFunctionDefinitions (ast, astWalker) { } function addParams (parameterList, tree, scopeId, states, contractName, sourceLocation, stackLength, stackPosition, dir) { - for (var inputParam in parameterList.children) { - var param = parameterList.children[inputParam] - var stackDepth = stackLength + (dir * stackPosition) + for (let inputParam in parameterList.children) { + const param = parameterList.children[inputParam] + const stackDepth = stackLength + (dir * stackPosition) if (stackDepth >= 0) { - var location = typesUtil.extractLocationFromAstVariable(param) + let location = typesUtil.extractLocationFromAstVariable(param) location = location === 'default' ? 'memory' : location tree.scopes[scopeId].locals[param.attributes.name] = { name: param.attributes.name, diff --git a/remix-debug/src/solidity-decoder/localDecoder.js b/remix-debug/src/solidity-decoder/localDecoder.js index 650f5bcad3..ef415e4bb3 100644 --- a/remix-debug/src/solidity-decoder/localDecoder.js +++ b/remix-debug/src/solidity-decoder/localDecoder.js @@ -1,18 +1,18 @@ 'use strict' async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storageResolver, currentSourceLocation) { - var scope = internalTreeCall.findScope(vmtraceIndex) + const scope = internalTreeCall.findScope(vmtraceIndex) if (!scope) { - var error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' } + const error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' } throw error } - var locals = {} + const locals = {} memory = formatMemory(memory) - var anonymousIncr = 1 - for (var local in scope.locals) { - var variable = scope.locals[local] + let anonymousIncr = 1 + for (let local in scope.locals) { + const variable = scope.locals[local] if (variable.stackDepth < stack.length && variable.sourceLocation.start <= currentSourceLocation.start) { - var name = variable.name + let name = variable.name if (name === '') { name = '<' + anonymousIncr + '>' anonymousIncr++ diff --git a/remix-debug/src/solidity-decoder/solidityProxy.js b/remix-debug/src/solidity-decoder/solidityProxy.js index 1fdb293315..6de5888a83 100644 --- a/remix-debug/src/solidity-decoder/solidityProxy.js +++ b/remix-debug/src/solidity-decoder/solidityProxy.js @@ -1,9 +1,9 @@ 'use strict' -var remixLib = require('remix-lib') -var traceHelper = remixLib.helpers.trace -var stateDecoder = require('./stateDecoder') -var astHelper = require('./astHelper') -var util = remixLib.util +const remixLib = require('remix-lib') +const traceHelper = remixLib.helpers.trace +const stateDecoder = require('./stateDecoder') +const astHelper = require('./astHelper') +const util = remixLib.util class SolidityProxy { constructor (traceManager, codeManager) { @@ -51,7 +51,7 @@ class SolidityProxy { if (error) { cb(error) } else { - var contractName = contractNameFromCode(this.contracts, code.bytecode, address) + const contractName = contractNameFromCode(this.contracts, code.bytecode, address) this.cache.contractNameByAddress[address] = contractName cb(null, contractName) } @@ -113,7 +113,7 @@ class SolidityProxy { * @return {Object} - AST of the current file */ ast (sourceLocation) { - var file = this.fileNameFromIndex(sourceLocation.file) + const file = this.fileNameFromIndex(sourceLocation.file) if (this.sources[file]) { return this.sources[file].legacyAST } else { @@ -134,10 +134,10 @@ class SolidityProxy { } function contractNameFromCode (contracts, code, address) { - var isCreation = traceHelper.isContractCreation(address) - for (var file in contracts) { - for (var contract in contracts[file]) { - var bytecode = isCreation ? contracts[file][contract].evm.bytecode.object : contracts[file][contract].evm.deployedBytecode.object + const isCreation = traceHelper.isContractCreation(address) + for (let file in contracts) { + for (let contract in contracts[file]) { + const bytecode = isCreation ? contracts[file][contract].evm.bytecode.object : contracts[file][contract].evm.deployedBytecode.object if (util.compareByteCode(code, '0x' + bytecode)) { return contract } diff --git a/remix-debug/src/solidity-decoder/stateDecoder.js b/remix-debug/src/solidity-decoder/stateDecoder.js index 43baa32225..dfab44713d 100644 --- a/remix-debug/src/solidity-decoder/stateDecoder.js +++ b/remix-debug/src/solidity-decoder/stateDecoder.js @@ -1,5 +1,5 @@ -var astHelper = require('./astHelper') -var decodeInfo = require('./decodeInfo') +const astHelper = require('./astHelper') +const decodeInfo = require('./decodeInfo') /** * decode the contract state storage @@ -9,11 +9,11 @@ var decodeInfo = require('./decodeInfo') * @return {Map} - decoded state variable */ async function decodeState (stateVars, storageResolver) { - var ret = {} + const ret = {} for (var k in stateVars) { - var stateVar = stateVars[k] + const stateVar = stateVars[k] try { - var decoded = await stateVar.type.decodeFromStorage(stateVar.storagelocation, storageResolver) + const decoded = await stateVar.type.decodeFromStorage(stateVar.storagelocation, storageResolver) decoded.constant = stateVar.constant if (decoded.constant) { decoded.value = '' @@ -35,12 +35,12 @@ async function decodeState (stateVars, storageResolver) { * @return {Object} - return the location of all contract variables in the storage */ function extractStateVariables (contractName, sourcesList) { - var states = astHelper.extractStatesDefinitions(sourcesList) + const states = astHelper.extractStatesDefinitions(sourcesList) if (!states[contractName]) { return [] } - var types = states[contractName].stateVariables - var offsets = decodeInfo.computeOffsets(types, states, contractName, 'storage') + const types = states[contractName].stateVariables + const offsets = decodeInfo.computeOffsets(types, states, contractName, 'storage') if (!offsets) { return [] // TODO should maybe return an error } @@ -56,7 +56,7 @@ function extractStateVariables (contractName, sourcesList) { * @return {Map} - return the state of the contract */ async function solidityState (storageResolver, astList, contractName) { - var stateVars = extractStateVariables(contractName, astList) + const stateVars = extractStateVariables(contractName, astList) try { return await decodeState(stateVars, storageResolver) } catch (e) { diff --git a/remix-debug/src/solidity-decoder/types/Address.js b/remix-debug/src/solidity-decoder/types/Address.js index 9369fd2258..b41952d024 100644 --- a/remix-debug/src/solidity-decoder/types/Address.js +++ b/remix-debug/src/solidity-decoder/types/Address.js @@ -1,6 +1,6 @@ 'use strict' -var util = require('./util') -var ValueType = require('./ValueType') +const util = require('./util') +const ValueType = require('./ValueType') class Address extends ValueType { constructor () { diff --git a/remix-debug/src/solidity-decoder/types/ArrayType.js b/remix-debug/src/solidity-decoder/types/ArrayType.js index d8edede107..78a9c89c01 100644 --- a/remix-debug/src/solidity-decoder/types/ArrayType.js +++ b/remix-debug/src/solidity-decoder/types/ArrayType.js @@ -1,34 +1,34 @@ 'use strict' -var util = require('./util') -var remixLib = require('remix-lib') -var sha3256 = remixLib.util.sha3_256 -var BN = require('ethereumjs-util').BN -var RefType = require('./RefType') +const util = require('./util') +const remixLib = require('remix-lib') +const sha3256 = remixLib.util.sha3_256 +const BN = require('ethereumjs-util').BN +const RefType = require('./RefType') class ArrayType extends RefType { constructor (underlyingType, arraySize, location) { - var storageSlots = null + let storageSlots = null if (arraySize === 'dynamic') { storageSlots = 1 } else { if (underlyingType.storageBytes < 32) { - var itemPerSlot = Math.floor(32 / underlyingType.storageBytes) + const itemPerSlot = Math.floor(32 / underlyingType.storageBytes) storageSlots = Math.ceil(arraySize / itemPerSlot) } else { storageSlots = arraySize * underlyingType.storageSlots } } - var size = arraySize !== 'dynamic' ? arraySize : '' + const size = arraySize !== 'dynamic' ? arraySize : '' super(storageSlots, 32, underlyingType.typeName + '[' + size + ']', location) this.underlyingType = underlyingType this.arraySize = arraySize } async decodeFromStorage (location, storageResolver) { - var ret = [] - var size = null - var slotValue + const ret = [] + let size = null + let slotValue try { slotValue = await util.extractHexValue(location, storageResolver, this.storageBytes) } catch (e) { @@ -38,7 +38,7 @@ class ArrayType extends RefType { type: this.typeName } } - var currentLocation = { + const currentLocation = { offset: 0, slot: location.slot } @@ -77,8 +77,8 @@ class ArrayType extends RefType { } decodeFromMemoryInternal (offset, memory) { - var ret = [] - var length = this.arraySize + const ret = [] + let length = this.arraySize if (this.arraySize === 'dynamic') { length = memory.substr(2 * offset, 64) length = parseInt(length, 16) diff --git a/remix-debug/src/solidity-decoder/types/Bool.js b/remix-debug/src/solidity-decoder/types/Bool.js index 32b63d061e..659ac12d44 100644 --- a/remix-debug/src/solidity-decoder/types/Bool.js +++ b/remix-debug/src/solidity-decoder/types/Bool.js @@ -1,6 +1,6 @@ 'use strict' -var ValueType = require('./ValueType') -var util = require('./util') +const ValueType = require('./ValueType') +const util = require('./util') class Bool extends ValueType { constructor () { diff --git a/remix-debug/src/solidity-decoder/types/DynamicByteArray.js b/remix-debug/src/solidity-decoder/types/DynamicByteArray.js index d879b5ef6a..136c44517f 100644 --- a/remix-debug/src/solidity-decoder/types/DynamicByteArray.js +++ b/remix-debug/src/solidity-decoder/types/DynamicByteArray.js @@ -1,9 +1,9 @@ 'use strict' -var util = require('./util') -var remixLib = require('remix-lib') -var sha3256 = remixLib.util.sha3_256 -var BN = require('ethereumjs-util').BN -var RefType = require('./RefType') +const util = require('./util') +const remixLib = require('remix-lib') +const sha3256 = remixLib.util.sha3_256 +const BN = require('ethereumjs-util').BN +const RefType = require('./RefType') class DynamicByteArray extends RefType { constructor (location) { @@ -11,7 +11,7 @@ class DynamicByteArray extends RefType { } async decodeFromStorage (location, storageResolver) { - var value = '0x0' + let value = '0x0' try { value = await util.extractHexValue(location, storageResolver, this.storageBytes) } catch (e) { @@ -21,12 +21,12 @@ class DynamicByteArray extends RefType { type: this.typeName } } - var bn = new BN(value, 16) + const bn = new BN(value, 16) if (bn.testn(0)) { - var length = bn.div(new BN(2)) - var dataPos = new BN(sha3256(location.slot).replace('0x', ''), 16) - var ret = '' - var currentSlot = '0x' + const length = bn.div(new BN(2)) + let dataPos = new BN(sha3256(location.slot).replace('0x', ''), 16) + let ret = '' + let currentSlot = '0x' try { currentSlot = await util.readFromStorage(dataPos, storageResolver) } catch (e) { @@ -67,7 +67,7 @@ class DynamicByteArray extends RefType { decodeFromMemoryInternal (offset, memory) { offset = 2 * offset - var length = memory.substr(offset, 64) + let length = memory.substr(offset, 64) length = 2 * parseInt(length, 16) return { length: '0x' + length.toString(16), diff --git a/remix-debug/src/solidity-decoder/types/Enum.js b/remix-debug/src/solidity-decoder/types/Enum.js index a170b61c16..3c384e6084 100644 --- a/remix-debug/src/solidity-decoder/types/Enum.js +++ b/remix-debug/src/solidity-decoder/types/Enum.js @@ -1,10 +1,10 @@ 'use strict' -var ValueType = require('./ValueType') +const ValueType = require('./ValueType') class Enum extends ValueType { constructor (enumDef) { - var storageBytes = 0 - var length = enumDef.children.length + let storageBytes = 0 + let length = enumDef.children.length while (length > 1) { length = length / 256 storageBytes++ diff --git a/remix-debug/src/solidity-decoder/types/FixedByteArray.js b/remix-debug/src/solidity-decoder/types/FixedByteArray.js index 3cfe1a7e4c..e0fafa5fe5 100644 --- a/remix-debug/src/solidity-decoder/types/FixedByteArray.js +++ b/remix-debug/src/solidity-decoder/types/FixedByteArray.js @@ -1,5 +1,5 @@ 'use strict' -var ValueType = require('./ValueType') +const ValueType = require('./ValueType') class FixedByteArray extends ValueType { constructor (storageBytes) { diff --git a/remix-debug/src/solidity-decoder/types/Int.js b/remix-debug/src/solidity-decoder/types/Int.js index 6288899e75..8bea14f120 100644 --- a/remix-debug/src/solidity-decoder/types/Int.js +++ b/remix-debug/src/solidity-decoder/types/Int.js @@ -1,6 +1,6 @@ 'use strict' -var util = require('./util') -var ValueType = require('./ValueType') +const util = require('./util') +const ValueType = require('./ValueType') class Int extends ValueType { constructor (storageBytes) { diff --git a/remix-debug/src/solidity-decoder/types/Mapping.js b/remix-debug/src/solidity-decoder/types/Mapping.js index e39f381d15..cac5b3a70e 100644 --- a/remix-debug/src/solidity-decoder/types/Mapping.js +++ b/remix-debug/src/solidity-decoder/types/Mapping.js @@ -1,7 +1,7 @@ 'use strict' -var RefType = require('./RefType') -var util = require('./util') -var ethutil = require('ethereumjs-util') +const RefType = require('./RefType') +const util = require('./util') +const ethutil = require('ethereumjs-util') class Mapping extends RefType { constructor (underlyingTypes, location, fullType) { @@ -12,9 +12,9 @@ class Mapping extends RefType { } async decodeFromStorage (location, storageResolver) { - var corrections = this.valueType.members ? this.valueType.members.map((value) => { return value.storagelocation }) : [] + const corrections = this.valueType.members ? this.valueType.members.map((value) => { return value.storagelocation }) : [] if (!this.initialDecodedState) { // cache the decoded initial storage - var mappingsInitialPreimages + let mappingsInitialPreimages try { mappingsInitialPreimages = await storageResolver.initialMappingsLocation(corrections) this.initialDecodedState = await this.decodeMappingsLocation(mappingsInitialPreimages, location, storageResolver) @@ -25,8 +25,8 @@ class Mapping extends RefType { } } } - var mappingPreimages = await storageResolver.mappingsLocation(corrections) - var ret = await this.decodeMappingsLocation(mappingPreimages, location, storageResolver) // fetch mapping storage changes + const mappingPreimages = await storageResolver.mappingsLocation(corrections) + let ret = await this.decodeMappingsLocation(mappingPreimages, location, storageResolver) // fetch mapping storage changes ret = Object.assign({}, this.initialDecodedState, ret) // merge changes return { value: ret, @@ -45,14 +45,14 @@ class Mapping extends RefType { } async decodeMappingsLocation (preimages, location, storageResolver) { - var mapSlot = util.normalizeHex(ethutil.bufferToHex(location.slot)) + const mapSlot = util.normalizeHex(ethutil.bufferToHex(location.slot)) if (!preimages[mapSlot]) { return {} } - var ret = {} - for (var i in preimages[mapSlot]) { - var mapLocation = getMappingLocation(i, location.slot) - var globalLocation = { + const ret = {} + for (let i in preimages[mapSlot]) { + const mapLocation = getMappingLocation(i, location.slot) + const globalLocation = { offset: location.offset, slot: mapLocation } @@ -68,12 +68,12 @@ function getMappingLocation (key, position) { // > the value corresponding to a mapping key k is located at keccak256(k . p) where . is concatenation. // key should be a hex string, and position an int - var mappingK = ethutil.toBuffer('0x' + key) - var mappingP = ethutil.intToBuffer(position) + const mappingK = ethutil.toBuffer('0x' + key) + let mappingP = ethutil.intToBuffer(position) mappingP = ethutil.setLengthLeft(mappingP, 32) - var mappingKeyBuf = concatTypedArrays(mappingK, mappingP) - var mappingKeyPreimage = '0x' + mappingKeyBuf.toString('hex') - var mappingStorageLocation = ethutil.keccak(mappingKeyPreimage) + const mappingKeyBuf = concatTypedArrays(mappingK, mappingP) + const mappingKeyPreimage = '0x' + mappingKeyBuf.toString('hex') + let mappingStorageLocation = ethutil.keccak(mappingKeyPreimage) mappingStorageLocation = new ethutil.BN(mappingStorageLocation, 16) return mappingStorageLocation } diff --git a/remix-debug/src/solidity-decoder/types/RefType.js b/remix-debug/src/solidity-decoder/types/RefType.js index c33a3d18a1..f10297661c 100644 --- a/remix-debug/src/solidity-decoder/types/RefType.js +++ b/remix-debug/src/solidity-decoder/types/RefType.js @@ -1,5 +1,5 @@ 'use strict' -var util = require('./util') +const util = require('./util') class RefType { constructor (storageSlots, storageBytes, typeName, location) { @@ -26,7 +26,7 @@ class RefType { type: this.typeName } } - var offset = stack[stack.length - 1 - stackDepth] + let offset = stack[stack.length - 1 - stackDepth] if (this.isInStorage()) { offset = util.toBN(offset) try { diff --git a/remix-debug/src/solidity-decoder/types/StringType.js b/remix-debug/src/solidity-decoder/types/StringType.js index f21eac4a51..596caebdbb 100644 --- a/remix-debug/src/solidity-decoder/types/StringType.js +++ b/remix-debug/src/solidity-decoder/types/StringType.js @@ -1,5 +1,5 @@ 'use strict' -var DynamicBytes = require('./DynamicByteArray') +const DynamicBytes = require('./DynamicByteArray') class StringType extends DynamicBytes { constructor (location) { @@ -8,7 +8,7 @@ class StringType extends DynamicBytes { } async decodeFromStorage (location, storageResolver) { - var decoded = '0x' + let decoded = '0x' try { decoded = await super.decodeFromStorage(location, storageResolver) } catch (e) { @@ -28,7 +28,7 @@ class StringType extends DynamicBytes { } decodeFromMemoryInternal (offset, memory) { - var decoded = super.decodeFromMemoryInternal(offset, memory) + const decoded = super.decodeFromMemoryInternal(offset, memory) return format(decoded) } } @@ -37,9 +37,9 @@ function format (decoded) { if (decoded.error) { return decoded } - var value = decoded.value + let value = decoded.value value = value.replace('0x', '').replace(/(..)/g, '%$1') - var ret = { + const ret = { length: decoded.length, raw: decoded.value, type: 'string' diff --git a/remix-debug/src/solidity-decoder/types/Struct.js b/remix-debug/src/solidity-decoder/types/Struct.js index d715caf049..57e9d01789 100644 --- a/remix-debug/src/solidity-decoder/types/Struct.js +++ b/remix-debug/src/solidity-decoder/types/Struct.js @@ -1,6 +1,6 @@ 'use strict' -var util = require('./util') -var RefType = require('./RefType') +const util = require('./util') +const RefType = require('./RefType') class Struct extends RefType { constructor (memberDetails, location, fullType) { @@ -9,10 +9,10 @@ class Struct extends RefType { } async decodeFromStorage (location, storageResolver) { - var ret = {} + const ret = {} for (var k in this.members) { - var item = this.members[k] - var globalLocation = { + const item = this.members[k] + const globalLocation = { offset: location.offset + item.storagelocation.offset, slot: util.add(location.slot, item.storagelocation.slot) } @@ -30,7 +30,7 @@ class Struct extends RefType { } decodeFromMemoryInternal (offset, memory) { - var ret = {} + const ret = {} this.members.map((item, i) => { var contentOffset = offset var member = item.type.decodeFromMemory(contentOffset, memory) diff --git a/remix-debug/src/solidity-decoder/types/Uint.js b/remix-debug/src/solidity-decoder/types/Uint.js index 3bdc4b4976..9b1fdc2652 100644 --- a/remix-debug/src/solidity-decoder/types/Uint.js +++ b/remix-debug/src/solidity-decoder/types/Uint.js @@ -1,6 +1,6 @@ 'use strict' -var util = require('./util') -var ValueType = require('./ValueType') +const util = require('./util') +const ValueType = require('./ValueType') class Uint extends ValueType { constructor (storageBytes) { diff --git a/remix-debug/src/solidity-decoder/types/ValueType.js b/remix-debug/src/solidity-decoder/types/ValueType.js index 44c4c7b536..eefad99c98 100644 --- a/remix-debug/src/solidity-decoder/types/ValueType.js +++ b/remix-debug/src/solidity-decoder/types/ValueType.js @@ -41,7 +41,7 @@ class ValueType { * @return {Object} - decoded value */ async decodeFromStack (stackDepth, stack, memory) { - var value + let value if (stackDepth >= stack.length) { value = this.decodeValue('') } else { @@ -61,7 +61,7 @@ class ValueType { * @return {Object} - decoded value */ decodeFromMemory (offset, memory) { - var value = memory.substr(2 * offset, 64) + let value = memory.substr(2 * offset, 64) return { value: this.decodeValue(value), type: this.typeName diff --git a/remix-debug/src/solidity-decoder/types/util.js b/remix-debug/src/solidity-decoder/types/util.js index 1f0217f70e..c338114fb5 100644 --- a/remix-debug/src/solidity-decoder/types/util.js +++ b/remix-debug/src/solidity-decoder/types/util.js @@ -1,6 +1,6 @@ 'use strict' -var ethutil = require('ethereumjs-util') -var BN = require('ethereumjs-util').BN +const ethutil = require('ethereumjs-util') +const BN = require('ethereumjs-util').BN module.exports = { readFromStorage: readFromStorage, @@ -17,7 +17,7 @@ module.exports = { } function decodeIntFromHex (value, byteLength, signed) { - var bigNumber = new BN(value, 16) + let bigNumber = new BN(value, 16) if (signed) { bigNumber = bigNumber.fromTwos(8 * byteLength) } @@ -25,7 +25,7 @@ function decodeIntFromHex (value, byteLength, signed) { } function readFromStorage (slot, storageResolver) { - var hexSlot = '0x' + normalizeHex(ethutil.bufferToHex(slot)) + const hexSlot = '0x' + normalizeHex(ethutil.bufferToHex(slot)) return new Promise((resolve, reject) => { storageResolver.storageSlot(hexSlot, (error, slot) => { if (error) { @@ -51,7 +51,7 @@ function readFromStorage (slot, storageResolver) { * @param {Int} offsetFromLSB - byte distance from the right end slot value to the right end of the byte slice */ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) { - var offset = slotValue.length - 2 * offsetFromLSB - 2 * byteLength + const offset = slotValue.length - 2 * offsetFromLSB - 2 * byteLength return slotValue.substr(offset, 2 * byteLength) } @@ -63,7 +63,7 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) { * @param {Int} byteLength - Length of the byte slice to extract */ async function extractHexValue (location, storageResolver, byteLength) { - var slotvalue + let slotvalue try { slotvalue = await readFromStorage(location.slot, storageResolver) } catch (e) { @@ -97,7 +97,7 @@ function removeLocation (type) { } function extractLocation (type) { - var match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) + let match = type.match(/( storage ref| storage pointer| memory| calldata)?$/) if (match[1] !== '') { return match[1].trim() } else { diff --git a/remix-debug/src/storage/mappingPreimages.js b/remix-debug/src/storage/mappingPreimages.js index ba21618b59..9280e1fd62 100644 --- a/remix-debug/src/storage/mappingPreimages.js +++ b/remix-debug/src/storage/mappingPreimages.js @@ -1,4 +1,4 @@ -var util = require('../solidity-decoder/types/util') +const util = require('../solidity-decoder/types/util') module.exports = { decodeMappingsKeys: decodeMappingsKeys @@ -14,14 +14,14 @@ module.exports = { * @return {Map} - solidity mapping location (e.g { "" : { "": preimageOf1 }, { "": preimageOf2 }, ... }) */ async function decodeMappingsKeys (web3, storage, corrections, callback) { - var ret = {} + const ret = {} if (!corrections.length) corrections.push({offset: 0, slot: 0}) - for (var hashedLoc in storage) { - var preimage + for (let hashedLoc in storage) { + let preimage try { - var key = storage[hashedLoc].key - for (var k in corrections) { - var corrected = util.sub(key, corrections[k].slot).toString(16) + const key = storage[hashedLoc].key + for (let k in corrections) { + const corrected = util.sub(key, corrections[k].slot).toString(16) preimage = await getPreimage(web3, '0x' + corrected) if (preimage) break } @@ -30,9 +30,9 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) { if (preimage) { // got preimage! // get mapping position (i.e. storage slot), its the last 32 bytes - var slotByteOffset = preimage.length - 64 - var mappingSlot = preimage.substr(slotByteOffset) - var mappingKey = preimage.substr(0, slotByteOffset) + const slotByteOffset = preimage.length - 64 + const mappingSlot = preimage.substr(slotByteOffset) + const mappingKey = preimage.substr(0, slotByteOffset) if (!ret[mappingSlot]) { ret[mappingSlot] = {} } @@ -50,7 +50,7 @@ async function decodeMappingsKeys (web3, storage, corrections, callback) { */ function getPreimage (web3, key) { return new Promise((resolve, reject) => { - web3.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, function (error, preimage) { + web3.debug.preimage(key.indexOf('0x') === 0 ? key : '0x' + key, (error, preimage) => { if (error) { resolve(null) } else { diff --git a/remix-debug/src/storage/storageResolver.js b/remix-debug/src/storage/storageResolver.js index 2105146b92..8467336516 100644 --- a/remix-debug/src/storage/storageResolver.js +++ b/remix-debug/src/storage/storageResolver.js @@ -1,7 +1,7 @@ 'use strict' -var remixLib = require('remix-lib') -var traceHelper = remixLib.helpers.trace -var mappingPreimages = require('./mappingPreimages') +const remixLib = require('remix-lib') +const traceHelper = remixLib.helpers.trace +const mappingPreimages = require('./mappingPreimages') /** * Basically one instance is created for one debugging session. @@ -40,7 +40,6 @@ class StorageResolver { * @return {Function} - callback */ initialPreimagesMappings (tx, stepIndex, address, corrections, callback) { - const self = this if (this.preimagesMappingByAddress[address]) { return callback(null, this.preimagesMappingByAddress[address]) } @@ -48,7 +47,7 @@ class StorageResolver { if (error) { return callback(error) } - mappingPreimages.decodeMappingsKeys(self.web3, storage, corrections, (error, mappings) => { + mappingPreimages.decodeMappingsKeys(this.web3, storage, corrections, (error, mappings) => { if (error) { callback(error) } else { @@ -69,7 +68,7 @@ class StorageResolver { * @param {Function} - callback - {key, hashedKey, value} - */ storageSlot (slot, tx, stepIndex, address, callback) { - this.storageRangeInternal(this, slot, tx, stepIndex, address, function (error, storage) { + this.storageRangeInternal(this, slot, tx, stepIndex, address, (error, storage) => { if (error) { callback(error) } else { diff --git a/remix-debug/src/storage/storageViewer.js b/remix-debug/src/storage/storageViewer.js index a5c9e4d7ea..dbd34335a6 100644 --- a/remix-debug/src/storage/storageViewer.js +++ b/remix-debug/src/storage/storageViewer.js @@ -1,7 +1,7 @@ 'use strict' -var remixLib = require('remix-lib') -var util = remixLib.util -var mappingPreimages = require('./mappingPreimages') +const remixLib = require('remix-lib') +const util = remixLib.util +const mappingPreimages = require('./mappingPreimages') /** * easier access to the storage resolver @@ -46,7 +46,7 @@ class StorageViewer { * @param {Function} - callback - {key, hashedKey, value} - */ storageSlot (slot, callback) { - var hashed = util.sha3_256(slot) + const hashed = util.sha3_256(slot) if (this.storageChanges[hashed]) { return callback(null, this.storageChanges[hashed]) } From ce2caa4da0bd1b059905442b0e32d785f4784499 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Mon, 16 Dec 2019 19:14:59 -0500 Subject: [PATCH 3/4] update remix-simulator syntax to use const, let and this --- remix-simulator/index.js | 2 +- remix-simulator/src/genesis.js | 10 +-- remix-simulator/src/methods/accounts.js | 10 +-- remix-simulator/src/methods/blocks.js | 2 +- remix-simulator/src/methods/filters.js | 2 +- remix-simulator/src/methods/misc.js | 8 +-- remix-simulator/src/methods/net.js | 2 +- remix-simulator/src/methods/transactions.js | 24 +++---- remix-simulator/src/methods/txProcess.js | 14 ++-- remix-simulator/src/provider.js | 8 +-- remix-simulator/src/utils/logs.js | 20 +++--- remix-simulator/test/accounts.js | 30 ++++----- remix-simulator/test/blocks.js | 74 ++++++++++----------- remix-simulator/test/misc.js | 42 ++++++------ 14 files changed, 124 insertions(+), 124 deletions(-) diff --git a/remix-simulator/index.js b/remix-simulator/index.js index 4b17d07532..3ce817f94e 100644 --- a/remix-simulator/index.js +++ b/remix-simulator/index.js @@ -1,4 +1,4 @@ -var Provider = require('./src/provider') +const Provider = require('./src/provider') module.exports = { Provider: Provider diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js index f008ead194..b9674c695e 100644 --- a/remix-simulator/src/genesis.js +++ b/remix-simulator/src/genesis.js @@ -1,9 +1,9 @@ -var EthJSBlock = require('ethereumjs-block') -var ethJSUtil = require('ethereumjs-util') -var BN = ethJSUtil.BN +const EthJSBlock = require('ethereumjs-block') +const ethJSUtil = require('ethereumjs-util') +const BN = ethJSUtil.BN function generateBlock (executionContext) { - var block = new EthJSBlock({ + const block = new EthJSBlock({ header: { timestamp: (new Date().getTime() / 1000 | 0), number: 0, @@ -15,7 +15,7 @@ function generateBlock (executionContext) { uncleHeaders: [] }) - executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(function () { + executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }).then(() => { executionContext.addBlock(block) }) } diff --git a/remix-simulator/src/methods/accounts.js b/remix-simulator/src/methods/accounts.js index c7c369ff80..0bd5d10cc6 100644 --- a/remix-simulator/src/methods/accounts.js +++ b/remix-simulator/src/methods/accounts.js @@ -1,8 +1,8 @@ -var ethJSUtil = require('ethereumjs-util') -var BN = ethJSUtil.BN -var Web3 = require('web3') +const ethJSUtil = require('ethereumjs-util') +const BN = ethJSUtil.BN +const Web3 = require('web3') -var Accounts = function (executionContext) { +const Accounts = function (executionContext) { this.web3 = new Web3() this.executionContext = executionContext // TODO: make it random and/or use remix-libs @@ -23,7 +23,7 @@ Accounts.prototype.init = async function () { if (err) { throw new Error(err) } - var balance = '0x56BC75E2D63100000' + const balance = '0x56BC75E2D63100000' account.balance = balance || '0xf00000000000000001' resolve() }) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index b8fe4e8f07..182a5bf838 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -1,5 +1,5 @@ -var Blocks = function (executionContext, _options) { +const Blocks = function (executionContext, _options) { this.executionContext = executionContext const options = _options || {} this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' diff --git a/remix-simulator/src/methods/filters.js b/remix-simulator/src/methods/filters.js index 7453d615bd..999bf24b12 100644 --- a/remix-simulator/src/methods/filters.js +++ b/remix-simulator/src/methods/filters.js @@ -1,5 +1,5 @@ -var Filters = function (executionContext) { +const Filters = function (executionContext) { this.executionContext = executionContext } diff --git a/remix-simulator/src/methods/misc.js b/remix-simulator/src/methods/misc.js index 590ca5bb1c..045082702f 100644 --- a/remix-simulator/src/methods/misc.js +++ b/remix-simulator/src/methods/misc.js @@ -1,7 +1,7 @@ -var version = require('../../package.json').version -var web3 = require('web3') +const version = require('../../package.json').version +const web3 = require('web3') -var Misc = function () { +const Misc = function () { } Misc.prototype.methods = function () { @@ -41,7 +41,7 @@ Misc.prototype.eth_hashrate = function (payload, cb) { } Misc.prototype.web3_sha3 = function (payload, cb) { - let str = payload.params[0] + const str = payload.params[0] cb(null, web3.utils.sha3(str)) } diff --git a/remix-simulator/src/methods/net.js b/remix-simulator/src/methods/net.js index 83104d772b..1c4819c19a 100644 --- a/remix-simulator/src/methods/net.js +++ b/remix-simulator/src/methods/net.js @@ -1,5 +1,5 @@ -var Net = function () { +const Net = function () { } Net.prototype.methods = function () { diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index 94a211513a..b642f5dc36 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -1,9 +1,9 @@ -var Web3 = require('web3') -var ethJSUtil = require('ethereumjs-util') -var processTx = require('./txProcess.js') -var BN = ethJSUtil.BN +const Web3 = require('web3') +const ethJSUtil = require('ethereumjs-util') +const processTx = require('./txProcess.js') +const BN = ethJSUtil.BN -var Transactions = function (executionContext) { +const Transactions = function (executionContext) { this.executionContext = executionContext } @@ -39,9 +39,9 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { return cb(error) } - var txBlock = this.executionContext.txs[receipt.hash] + const txBlock = this.executionContext.txs[receipt.hash] - var r = { + const r = { 'transactionHash': receipt.hash, 'transactionIndex': '0x00', 'blockHash': '0x' + txBlock.hash().toString('hex'), @@ -111,10 +111,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { return cb(error) } - var txBlock = this.executionContext.txs[receipt.transactionHash] + const txBlock = this.executionContext.txs[receipt.transactionHash] // TODO: params to add later - let r = { + const r = { 'blockHash': '0x' + txBlock.hash().toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'from': receipt.from, @@ -151,7 +151,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { const txIndex = payload.params[1] - var txBlock = this.executionContext.blocks[payload.params[0]] + const txBlock = this.executionContext.blocks[payload.params[0]] const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { @@ -193,7 +193,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { const txIndex = payload.params[1] - var txBlock = this.executionContext.blocks[payload.params[0]] + const txBlock = this.executionContext.blocks[payload.params[0]] const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { @@ -202,7 +202,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo } // TODO: params to add later - let r = { + const r = { 'blockHash': '0x' + txBlock.hash().toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'from': receipt.from, diff --git a/remix-simulator/src/methods/txProcess.js b/remix-simulator/src/methods/txProcess.js index 1126850643..c3c61c3031 100644 --- a/remix-simulator/src/methods/txProcess.js +++ b/remix-simulator/src/methods/txProcess.js @@ -1,9 +1,9 @@ -var RemixLib = require('remix-lib') -var TxExecution = RemixLib.execution.txExecution -var TxRunner = RemixLib.execution.txRunner +const RemixLib = require('remix-lib') +const TxExecution = RemixLib.execution.txExecution +const TxRunner = RemixLib.execution.txRunner function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) { - let finalCallback = function (err, result) { + const finalCallback = function (err, result) { if (err) { return callback(err) } @@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, } function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) { - let finalCallback = function (err, result) { + const finalCallback = function (err, result) { if (err) { return callback(err) } @@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c } function createContract (payload, from, data, value, gasLimit, txRunner, callbacks, callback) { - let finalCallback = function (err, result) { + const finalCallback = function (err, result) { if (err) { return callback(err) } @@ -40,7 +40,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac let txRunnerInstance function processTx (executionContext, accounts, payload, isCall, callback) { - let api = { + const api = { logMessage: (msg) => { }, logHtmlMessage: (msg) => { diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index c7929e297d..7fe1017994 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -1,5 +1,5 @@ -var RemixLib = require('remix-lib') -var executionContext = RemixLib.execution.executionContext +const RemixLib = require('remix-lib') +const executionContext = RemixLib.execution.executionContext const log = require('./utils/logs.js') const merge = require('merge') @@ -40,7 +40,7 @@ Provider.prototype.init = async function () { Provider.prototype.sendAsync = function (payload, callback) { log.info('payload method is ', payload.method) - let method = this.methods[payload.method] + const method = this.methods[payload.method] if (this.options.logDetails) { log.info(payload) } @@ -53,7 +53,7 @@ Provider.prototype.sendAsync = function (payload, callback) { if (err) { return callback(err) } - let response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result} + const response = {'id': payload.id, 'jsonrpc': '2.0', 'result': result} callback(null, response) }) } diff --git a/remix-simulator/src/utils/logs.js b/remix-simulator/src/utils/logs.js index 7139140b97..d6a22b651a 100644 --- a/remix-simulator/src/utils/logs.js +++ b/remix-simulator/src/utils/logs.js @@ -1,8 +1,8 @@ 'use strict' -var gray = require('ansi-gray') -var timestamp = require('time-stamp') -var supportsColor = require('color-support') +const gray = require('ansi-gray') +const timestamp = require('time-stamp') +const supportsColor = require('color-support') function hasFlag (flag) { return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) @@ -24,7 +24,7 @@ function addColor (str) { return str } -let logger = { +const logger = { stdout: function (arg) { if (typeof (process) === 'undefined' || !process.stdout) return process.stdout.write(arg) @@ -36,40 +36,40 @@ let logger = { } function getTimestamp () { - let coloredTimestamp = addColor(timestamp('HH:mm:ss')) + const coloredTimestamp = addColor(timestamp('HH:mm:ss')) return '[' + coloredTimestamp + ']' } function log () { - var time = getTimestamp() + const time = getTimestamp() logger.stdout(time + ' ') console.log.apply(console, arguments) return this } function info () { - var time = getTimestamp() + const time = getTimestamp() logger.stdout(time + ' ') console.info.apply(console, arguments) return this } function dir () { - var time = getTimestamp() + const time = getTimestamp() logger.stdout(time + ' ') console.dir.apply(console, arguments) return this } function warn () { - var time = getTimestamp() + const time = getTimestamp() logger.stderr(time + ' ') console.warn.apply(console, arguments) return this } function error () { - var time = getTimestamp() + const time = getTimestamp() logger.stderr(time + ' ') console.error.apply(console, arguments) return this diff --git a/remix-simulator/test/accounts.js b/remix-simulator/test/accounts.js index 08ad48b1b8..fbe0e6e1eb 100644 --- a/remix-simulator/test/accounts.js +++ b/remix-simulator/test/accounts.js @@ -1,28 +1,28 @@ /* global describe, before, it */ -var Web3 = require('web3') -var RemixSim = require('../index.js') -let web3 = new Web3() -var assert = require('assert') +const Web3 = require('web3') +const RemixSim = require('../index.js') +const web3 = new Web3() +const assert = require('assert') -describe('Accounts', function () { +describe('Accounts', () => { before(function () { - let provider = new RemixSim.Provider() + const provider = new RemixSim.Provider() web3.setProvider(provider) }) describe('eth_getAccounts', () => { it('should get a list of accounts', async function () { - let accounts = await web3.eth.getAccounts() + const accounts = await web3.eth.getAccounts() assert.notEqual(accounts.length, 0) }) }) describe('eth_getBalance', () => { - it('should get a account balance', async function () { - let accounts = await web3.eth.getAccounts() - let balance0 = await web3.eth.getBalance(accounts[0]) - let balance1 = await web3.eth.getBalance(accounts[1]) - let balance2 = await web3.eth.getBalance(accounts[2]) + it('should get a account balance', async () => { + const accounts = await web3.eth.getAccounts() + const balance0 = await web3.eth.getBalance(accounts[0]) + const balance1 = await web3.eth.getBalance(accounts[1]) + const balance2 = await web3.eth.getBalance(accounts[2]) assert.deepEqual(balance0, '100000000000000000000') assert.deepEqual(balance1, '100000000000000000000') @@ -31,9 +31,9 @@ describe('Accounts', function () { }) describe('eth_sign', () => { - it('should sign payloads', async function () { - let accounts = await web3.eth.getAccounts() - let signature = await web3.eth.sign('Hello world', accounts[0]) + it('should sign payloads', async () => { + const accounts = await web3.eth.getAccounts() + const signature = await web3.eth.sign('Hello world', accounts[0]) assert.deepEqual(signature.length, 132) }) diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js index c6c6503016..fb048764de 100644 --- a/remix-simulator/test/blocks.js +++ b/remix-simulator/test/blocks.js @@ -1,22 +1,22 @@ /* global describe, before, it */ -var Web3 = require('web3') -var RemixSim = require('../index.js') -let web3 = new Web3() -var assert = require('assert') +const Web3 = require('web3') +const RemixSim = require('../index.js') +const web3 = new Web3() +const assert = require('assert') -describe('blocks', function () { - before(function () { - let provider = new RemixSim.Provider({ +describe('blocks', () => { + before(() => { + const provider = new RemixSim.Provider({ coinbase: '0x0000000000000000000000000000000000000001' }) web3.setProvider(provider) }) describe('eth_getBlockByNumber', () => { - it('should get block given its number', async function () { - let block = await web3.eth.getBlock(0) + it('should get block given its number', async () => { + const block = await web3.eth.getBlock(0) - let expectedBlock = { + const expectedBlock = { difficulty: '69762765929000', extraData: '0x0', gasLimit: 8000000, @@ -42,56 +42,56 @@ describe('blocks', function () { }) describe('eth_getGasPrice', () => { - it('should get gas price', async function () { - let gasPrice = await web3.eth.getGasPrice() + it('should get gas price', async () => { + const gasPrice = await web3.eth.getGasPrice() assert.equal(gasPrice, 1) }) }) describe('eth_coinbase', () => { - it('should get coinbase', async function () { - let coinbase = await web3.eth.getCoinbase() + it('should get coinbase', async () => { + const coinbase = await web3.eth.getCoinbase() assert.equal(coinbase, '0x0000000000000000000000000000000000000001') }) }) describe('eth_blockNumber', () => { - it('should get current block number', async function () { - let number = await web3.eth.getBlockNumber() + it('should get current block number', async () => { + const number = await web3.eth.getBlockNumber() assert.equal(number, 0) }) }) describe('eth_getBlockByHash', () => { - it('should get block given its hash', async function () { - let correctBlock = await web3.eth.getBlock(0) - let block = await web3.eth.getBlock(correctBlock.hash) + it('should get block given its hash', async () => { + const correctBlock = await web3.eth.getBlock(0) + const block = await web3.eth.getBlock(correctBlock.hash) assert.deepEqual(block, correctBlock) }) }) describe('eth_getBlockTransactionCountByHash', () => { - it('should get block given its hash', async function () { - let correctBlock = await web3.eth.getBlock(0) - let numberTransactions = await web3.eth.getBlockTransactionCount(correctBlock.hash) + it('should get block given its hash', async () => { + const correctBlock = await web3.eth.getBlock(0) + const numberTransactions = await web3.eth.getBlockTransactionCount(correctBlock.hash) assert.deepEqual(numberTransactions, 0) }) }) describe('eth_getBlockTransactionCountByNumber', () => { - it('should get block given its hash', async function () { - let numberTransactions = await web3.eth.getBlockTransactionCount(0) + it('should get block given its hash', async () => { + const numberTransactions = await web3.eth.getBlockTransactionCount(0) assert.deepEqual(numberTransactions, 0) }) }) describe('eth_getUncleCountByBlockHash', () => { - it('should get block given its hash', async function () { - let correctBlock = await web3.eth.getBlock(0) - let numberTransactions = await (new Promise((resolve, reject) => { + it('should get block given its hash', async () => { + const correctBlock = await web3.eth.getBlock(0) + const numberTransactions = await (new Promise((resolve, reject) => { web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => { if (err) return reject(err) resolve(numberTransactions) @@ -102,9 +102,9 @@ describe('blocks', function () { }) describe('eth_getUncleCountByBlockNumber', () => { - it('should get block given its number', async function () { - let correctBlock = await web3.eth.getBlock(0) - let numberTransactions = await (new Promise((resolve, reject) => { + it('should get block given its number', async () => { + const correctBlock = await web3.eth.getBlock(0) + const numberTransactions = await (new Promise((resolve, reject) => { web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => { if (err) return reject(err) resolve(numberTransactions) @@ -115,8 +115,8 @@ describe('blocks', function () { }) describe('eth_getStorageAt', () => { - it('should get storage at position at given address', async function () { - let abi = [ + it('should get storage at position at given address', async () => { + const abi = [ { 'constant': false, 'inputs': [ @@ -198,7 +198,7 @@ describe('blocks', function () { } ] - let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' + const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' const contract = new web3.eth.Contract(abi) const accounts = await web3.eth.getAccounts() @@ -222,8 +222,8 @@ describe('blocks', function () { }) describe('eth_call', () => { - it('should get a value', async function () { - let abi = [ + it('should get a value', async () => { + const abi = [ { 'constant': false, 'inputs': [ @@ -305,7 +305,7 @@ describe('blocks', function () { } ] - let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' + const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' const contract = new web3.eth.Contract(abi) const accounts = await web3.eth.getAccounts() @@ -314,7 +314,7 @@ describe('blocks', function () { contractInstance.currentProvider = web3.eth.currentProvider contractInstance.givenProvider = web3.eth.currentProvider - let value = await contractInstance.methods.get().call({ from: accounts[0] }) + const value = await contractInstance.methods.get().call({ from: accounts[0] }) assert.deepEqual(value, 100) }) }) diff --git a/remix-simulator/test/misc.js b/remix-simulator/test/misc.js index 69d7320fec..134eb90461 100644 --- a/remix-simulator/test/misc.js +++ b/remix-simulator/test/misc.js @@ -1,22 +1,22 @@ /* global describe, before, it */ -var Web3 = require('web3') -var RemixSim = require('../index.js') -let web3 = new Web3() -var assert = require('assert') +const Web3 = require('web3') +const RemixSim = require('../index.js') +const web3 = new Web3() +const assert = require('assert') -describe('Misc', function () { - before(function () { - let provider = new RemixSim.Provider() +describe('Misc', () => { + before(() => { + const provider = new RemixSim.Provider() web3.setProvider(provider) }) describe('web3_clientVersion', () => { - it('should get correct remix simulator version', async function (done) { + it('should get correct remix simulator version', async (done) => { web3._requestManager.send({ method: 'web3_clientVersion', params: [] }, (err, version) => { if (err) { throw new Error(err) } - let remixVersion = require('../package.json').version + const remixVersion = require('../package.json').version assert.equal(version, 'Remix Simulator/' + remixVersion) done() }) @@ -24,7 +24,7 @@ describe('Misc', function () { }) describe('eth_protocolVersion', () => { - it('should get protocol version', async function () { + it('should get protocol version', async () => { web3._requestManager.send({ method: 'eth_protocolVersion', params: [] }, (err, result) => { if (err) { throw new Error(err) @@ -35,28 +35,28 @@ describe('Misc', function () { }) describe('eth_syncing', () => { - it('should get if is syncing', async function () { - let isSyncing = await web3.eth.isSyncing() + it('should get if is syncing', async () => { + const isSyncing = await web3.eth.isSyncing() assert.equal(isSyncing, false) }) }) describe('eth_mining', () => { - it('should get if is mining', async function () { - let isMining = await web3.eth.isMining() + it('should get if is mining', async () => { + const isMining = await web3.eth.isMining() assert.equal(isMining, false) }) }) describe('eth_hashrate', () => { - it('should get hashrate', async function () { - let hashrate = await web3.eth.getHashrate() + it('should get hashrate', async () => { + const hashrate = await web3.eth.getHashrate() assert.equal(hashrate, 0) }) }) describe('web3_sha3', () => { - it('should get result of a sha3', async function () { + it('should get result of a sha3', async () => { web3._requestManager.send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64'] }, (err, result) => { if (err) { throw new Error(err) @@ -67,7 +67,7 @@ describe('Misc', function () { }) describe('eth_getCompilers', () => { - it('should get list of compilers', async function () { + it('should get list of compilers', async () => { web3._requestManager.send({ method: 'eth_getCompilers', params: [] }, (err, result) => { if (err) { throw new Error(err) @@ -78,7 +78,7 @@ describe('Misc', function () { }) describe('eth_compileSolidity', () => { - it('get unsupported result when requesting solidity compiler', async function () { + it('get unsupported result when requesting solidity compiler', async () => { web3._requestManager.send({ method: 'eth_compileSolidity', params: [] }, (err, result) => { if (err) { throw new Error(err) @@ -89,7 +89,7 @@ describe('Misc', function () { }) describe('eth_compileLLL', () => { - it('get unsupported result when requesting LLL compiler', async function () { + it('get unsupported result when requesting LLL compiler', async () => { web3._requestManager.send({ method: 'eth_compileLLL', params: [] }, (err, result) => { if (err) { throw new Error(err) @@ -100,7 +100,7 @@ describe('Misc', function () { }) describe('eth_compileSerpent', () => { - it('get unsupported result when requesting serpent compiler', async function () { + it('get unsupported result when requesting serpent compiler', async () => { web3._requestManager.send({ method: 'eth_compileSerpent', params: [] }, (err, result) => { if (err) { throw new Error(err) From f12b2eb1fc104b74b027077da9031ace0dc08b19 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 24 Dec 2019 10:12:28 -0500 Subject: [PATCH 4/4] update package lock --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 036a188ec5..08950ab1e7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "version": "0.1.24", + "version": "0.1.25", "lockfileVersion": 1, "requires": true, "dependencies": {