Skip to content
This repository has been archived by the owner on Mar 3, 2021. It is now read-only.

Commit

Permalink
update remix-simulator syntax to use const, let and this
Browse files Browse the repository at this point in the history
  • Loading branch information
iurimatias committed Dec 18, 2019
1 parent 60e291b commit 9163281
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 124 deletions.
2 changes: 1 addition & 1 deletion remix-simulator/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Provider = require('./src/provider')
const Provider = require('./src/provider')

module.exports = {
Provider: Provider
Expand Down
10 changes: 5 additions & 5 deletions remix-simulator/src/genesis.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
})
}
Expand Down
10 changes: 5 additions & 5 deletions remix-simulator/src/methods/accounts.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
})
Expand Down
2 changes: 1 addition & 1 deletion remix-simulator/src/methods/blocks.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion remix-simulator/src/methods/filters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var Filters = function (executionContext) {
const Filters = function (executionContext) {
this.executionContext = executionContext
}

Expand Down
8 changes: 4 additions & 4 deletions remix-simulator/src/methods/misc.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion remix-simulator/src/methods/net.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

var Net = function () {
const Net = function () {
}

Net.prototype.methods = function () {
Expand Down
24 changes: 12 additions & 12 deletions remix-simulator/src/methods/transactions.js
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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,
Expand Down
14 changes: 7 additions & 7 deletions remix-simulator/src/methods/txProcess.js
Original file line number Diff line number Diff line change
@@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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) => {
Expand Down
8 changes: 4 additions & 4 deletions remix-simulator/src/provider.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
})
}
Expand Down
20 changes: 10 additions & 10 deletions remix-simulator/src/utils/logs.js
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -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)
Expand All @@ -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
Expand Down
30 changes: 15 additions & 15 deletions remix-simulator/test/accounts.js
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)
})
Expand Down
Loading

0 comments on commit 9163281

Please sign in to comment.