Commit 3c657daa authored by Iuri Matias's avatar Iuri Matias

update remix-simulator syntax to use const, let and this

parent eddc2e38
var Provider = require('./src/provider') const Provider = require('./src/provider')
module.exports = { module.exports = {
Provider: Provider Provider: Provider
......
var EthJSBlock = require('ethereumjs-block') const EthJSBlock = require('ethereumjs-block')
var ethJSUtil = require('ethereumjs-util') const ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN const BN = ethJSUtil.BN
function generateBlock (executionContext) { function generateBlock (executionContext) {
var block = new EthJSBlock({ const block = new EthJSBlock({
header: { header: {
timestamp: (new Date().getTime() / 1000 | 0), timestamp: (new Date().getTime() / 1000 | 0),
number: 0, number: 0,
...@@ -15,7 +15,7 @@ function generateBlock (executionContext) { ...@@ -15,7 +15,7 @@ function generateBlock (executionContext) {
uncleHeaders: [] 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) executionContext.addBlock(block)
}) })
} }
......
var ethJSUtil = require('ethereumjs-util') const ethJSUtil = require('ethereumjs-util')
var BN = ethJSUtil.BN const BN = ethJSUtil.BN
var Web3 = require('web3') const Web3 = require('web3')
var Accounts = function (executionContext) { const Accounts = function (executionContext) {
this.web3 = new Web3() this.web3 = new Web3()
this.executionContext = executionContext this.executionContext = executionContext
// TODO: make it random and/or use remix-libs // TODO: make it random and/or use remix-libs
...@@ -23,7 +23,7 @@ Accounts.prototype.init = async function () { ...@@ -23,7 +23,7 @@ Accounts.prototype.init = async function () {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
} }
var balance = '0x56BC75E2D63100000' const balance = '0x56BC75E2D63100000'
account.balance = balance || '0xf00000000000000001' account.balance = balance || '0xf00000000000000001'
resolve() resolve()
}) })
......
var Blocks = function (executionContext, _options) { const Blocks = function (executionContext, _options) {
this.executionContext = executionContext this.executionContext = executionContext
const options = _options || {} const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000' this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
......
var Filters = function (executionContext) { const Filters = function (executionContext) {
this.executionContext = executionContext this.executionContext = executionContext
} }
......
var version = require('../../package.json').version const version = require('../../package.json').version
var web3 = require('web3') const web3 = require('web3')
var Misc = function () { const Misc = function () {
} }
Misc.prototype.methods = function () { Misc.prototype.methods = function () {
...@@ -41,7 +41,7 @@ Misc.prototype.eth_hashrate = function (payload, cb) { ...@@ -41,7 +41,7 @@ Misc.prototype.eth_hashrate = function (payload, cb) {
} }
Misc.prototype.web3_sha3 = 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)) cb(null, web3.utils.sha3(str))
} }
......
var Net = function () { const Net = function () {
} }
Net.prototype.methods = function () { Net.prototype.methods = function () {
......
var Web3 = require('web3') const Web3 = require('web3')
var ethJSUtil = require('ethereumjs-util') const ethJSUtil = require('ethereumjs-util')
var processTx = require('./txProcess.js') const processTx = require('./txProcess.js')
var BN = ethJSUtil.BN const BN = ethJSUtil.BN
var Transactions = function (executionContext) { const Transactions = function (executionContext) {
this.executionContext = executionContext this.executionContext = executionContext
} }
...@@ -39,9 +39,9 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { ...@@ -39,9 +39,9 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
return cb(error) return cb(error)
} }
var txBlock = this.executionContext.txs[receipt.hash] const txBlock = this.executionContext.txs[receipt.hash]
var r = { const r = {
'transactionHash': receipt.hash, 'transactionHash': receipt.hash,
'transactionIndex': '0x00', 'transactionIndex': '0x00',
'blockHash': '0x' + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
...@@ -111,10 +111,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { ...@@ -111,10 +111,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
return cb(error) return cb(error)
} }
var txBlock = this.executionContext.txs[receipt.transactionHash] const txBlock = this.executionContext.txs[receipt.transactionHash]
// TODO: params to add later // TODO: params to add later
let r = { const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, 'from': receipt.from,
...@@ -151,7 +151,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { ...@@ -151,7 +151,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) {
const txIndex = payload.params[1] 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') const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
...@@ -193,7 +193,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload ...@@ -193,7 +193,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) {
const txIndex = payload.params[1] 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') const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex')
this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { this.executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => {
...@@ -202,7 +202,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo ...@@ -202,7 +202,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
} }
// TODO: params to add later // TODO: params to add later
let r = { const r = {
'blockHash': '0x' + txBlock.hash().toString('hex'), 'blockHash': '0x' + txBlock.hash().toString('hex'),
'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'blockNumber': '0x' + txBlock.header.number.toString('hex'),
'from': receipt.from, 'from': receipt.from,
......
var RemixLib = require('remix-lib') const RemixLib = require('remix-lib')
var TxExecution = RemixLib.execution.txExecution const TxExecution = RemixLib.execution.txExecution
var TxRunner = RemixLib.execution.txRunner const TxRunner = RemixLib.execution.txRunner
function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) { function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) {
let finalCallback = function (err, result) { const finalCallback = function (err, result) {
if (err) { if (err) {
return callback(err) return callback(err)
} }
...@@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks, ...@@ -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) { function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) {
let finalCallback = function (err, result) { const finalCallback = function (err, result) {
if (err) { if (err) {
return callback(err) return callback(err)
} }
...@@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c ...@@ -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) { function createContract (payload, from, data, value, gasLimit, txRunner, callbacks, callback) {
let finalCallback = function (err, result) { const finalCallback = function (err, result) {
if (err) { if (err) {
return callback(err) return callback(err)
} }
...@@ -40,7 +40,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac ...@@ -40,7 +40,7 @@ function createContract (payload, from, data, value, gasLimit, txRunner, callbac
let txRunnerInstance let txRunnerInstance
function processTx (executionContext, accounts, payload, isCall, callback) { function processTx (executionContext, accounts, payload, isCall, callback) {
let api = { const api = {
logMessage: (msg) => { logMessage: (msg) => {
}, },
logHtmlMessage: (msg) => { logHtmlMessage: (msg) => {
......
var RemixLib = require('remix-lib') const RemixLib = require('remix-lib')
var executionContext = RemixLib.execution.executionContext const executionContext = RemixLib.execution.executionContext
const log = require('./utils/logs.js') const log = require('./utils/logs.js')
const merge = require('merge') const merge = require('merge')
...@@ -40,7 +40,7 @@ Provider.prototype.init = async function () { ...@@ -40,7 +40,7 @@ Provider.prototype.init = async function () {
Provider.prototype.sendAsync = function (payload, callback) { Provider.prototype.sendAsync = function (payload, callback) {
log.info('payload method is ', payload.method) log.info('payload method is ', payload.method)
let method = this.methods[payload.method] const method = this.methods[payload.method]
if (this.options.logDetails) { if (this.options.logDetails) {
log.info(payload) log.info(payload)
} }
...@@ -53,7 +53,7 @@ Provider.prototype.sendAsync = function (payload, callback) { ...@@ -53,7 +53,7 @@ Provider.prototype.sendAsync = function (payload, callback) {
if (err) { if (err) {
return callback(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) callback(null, response)
}) })
} }
......
'use strict' 'use strict'
var gray = require('ansi-gray') const gray = require('ansi-gray')
var timestamp = require('time-stamp') const timestamp = require('time-stamp')
var supportsColor = require('color-support') const supportsColor = require('color-support')
function hasFlag (flag) { function hasFlag (flag) {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
...@@ -24,7 +24,7 @@ function addColor (str) { ...@@ -24,7 +24,7 @@ function addColor (str) {
return str return str
} }
let logger = { const logger = {
stdout: function (arg) { stdout: function (arg) {
if (typeof (process) === 'undefined' || !process.stdout) return if (typeof (process) === 'undefined' || !process.stdout) return
process.stdout.write(arg) process.stdout.write(arg)
...@@ -36,40 +36,40 @@ let logger = { ...@@ -36,40 +36,40 @@ let logger = {
} }
function getTimestamp () { function getTimestamp () {
let coloredTimestamp = addColor(timestamp('HH:mm:ss')) const coloredTimestamp = addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']' return '[' + coloredTimestamp + ']'
} }
function log () { function log () {
var time = getTimestamp() const time = getTimestamp()
logger.stdout(time + ' ') logger.stdout(time + ' ')
console.log.apply(console, arguments) console.log.apply(console, arguments)
return this return this
} }
function info () { function info () {
var time = getTimestamp() const time = getTimestamp()
logger.stdout(time + ' ') logger.stdout(time + ' ')
console.info.apply(console, arguments) console.info.apply(console, arguments)
return this return this
} }
function dir () { function dir () {
var time = getTimestamp() const time = getTimestamp()
logger.stdout(time + ' ') logger.stdout(time + ' ')
console.dir.apply(console, arguments) console.dir.apply(console, arguments)
return this return this
} }
function warn () { function warn () {
var time = getTimestamp() const time = getTimestamp()
logger.stderr(time + ' ') logger.stderr(time + ' ')
console.warn.apply(console, arguments) console.warn.apply(console, arguments)
return this return this
} }
function error () { function error () {
var time = getTimestamp() const time = getTimestamp()
logger.stderr(time + ' ') logger.stderr(time + ' ')
console.error.apply(console, arguments) console.error.apply(console, arguments)
return this return this
......
/* global describe, before, it */ /* global describe, before, it */
var Web3 = require('web3') const Web3 = require('web3')
var RemixSim = require('../index.js') const RemixSim = require('../index.js')
let web3 = new Web3() const web3 = new Web3()
var assert = require('assert') const assert = require('assert')
describe('Accounts', function () { describe('Accounts', () => {
before(function () { before(function () {
let provider = new RemixSim.Provider() const provider = new RemixSim.Provider()
web3.setProvider(provider) web3.setProvider(provider)
}) })
describe('eth_getAccounts', () => { describe('eth_getAccounts', () => {
it('should get a list of accounts', async function () { 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) assert.notEqual(accounts.length, 0)
}) })
}) })
describe('eth_getBalance', () => { describe('eth_getBalance', () => {
it('should get a account balance', async function () { it('should get a account balance', async () => {
let accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
let balance0 = await web3.eth.getBalance(accounts[0]) const balance0 = await web3.eth.getBalance(accounts[0])
let balance1 = await web3.eth.getBalance(accounts[1]) const balance1 = await web3.eth.getBalance(accounts[1])
let balance2 = await web3.eth.getBalance(accounts[2]) const balance2 = await web3.eth.getBalance(accounts[2])
assert.deepEqual(balance0, '100000000000000000000') assert.deepEqual(balance0, '100000000000000000000')
assert.deepEqual(balance1, '100000000000000000000') assert.deepEqual(balance1, '100000000000000000000')
...@@ -31,9 +31,9 @@ describe('Accounts', function () { ...@@ -31,9 +31,9 @@ describe('Accounts', function () {
}) })
describe('eth_sign', () => { describe('eth_sign', () => {
it('should sign payloads', async function () { it('should sign payloads', async () => {
let accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
let signature = await web3.eth.sign('Hello world', accounts[0]) const signature = await web3.eth.sign('Hello world', accounts[0])
assert.deepEqual(signature.length, 132) assert.deepEqual(signature.length, 132)
}) })
......
This diff is collapsed.
/* global describe, before, it */ /* global describe, before, it */
var Web3 = require('web3') const Web3 = require('web3')
var RemixSim = require('../index.js') const RemixSim = require('../index.js')
let web3 = new Web3() const web3 = new Web3()
var assert = require('assert') const assert = require('assert')
describe('Misc', function () { describe('Misc', () => {
before(function () { before(() => {
let provider = new RemixSim.Provider() const provider = new RemixSim.Provider()
web3.setProvider(provider) web3.setProvider(provider)
}) })
describe('web3_clientVersion', () => { 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) => { web3._requestManager.send({ method: 'web3_clientVersion', params: [] }, (err, version) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
} }
let remixVersion = require('../package.json').version const remixVersion = require('../package.json').version
assert.equal(version, 'Remix Simulator/' + remixVersion) assert.equal(version, 'Remix Simulator/' + remixVersion)
done() done()
}) })
...@@ -24,7 +24,7 @@ describe('Misc', function () { ...@@ -24,7 +24,7 @@ describe('Misc', function () {
}) })
describe('eth_protocolVersion', () => { 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) => { web3._requestManager.send({ method: 'eth_protocolVersion', params: [] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
...@@ -35,28 +35,28 @@ describe('Misc', function () { ...@@ -35,28 +35,28 @@ describe('Misc', function () {
}) })
describe('eth_syncing', () => { describe('eth_syncing', () => {
it('should get if is syncing', async function () { it('should get if is syncing', async () => {
let isSyncing = await web3.eth.isSyncing() const isSyncing = await web3.eth.isSyncing()
assert.equal(isSyncing, false) assert.equal(isSyncing, false)
}) })
}) })
describe('eth_mining', () => { describe('eth_mining', () => {
it('should get if is mining', async function () { it('should get if is mining', async () => {
let isMining = await web3.eth.isMining() const isMining = await web3.eth.isMining()
assert.equal(isMining, false) assert.equal(isMining, false)
}) })
}) })
describe('eth_hashrate', () => { describe('eth_hashrate', () => {
it('should get hashrate', async function () { it('should get hashrate', async () => {
let hashrate = await web3.eth.getHashrate() const hashrate = await web3.eth.getHashrate()
assert.equal(hashrate, 0) assert.equal(hashrate, 0)
}) })
}) })
describe('web3_sha3', () => { 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) => { web3._requestManager.send({ method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64'] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
...@@ -67,7 +67,7 @@ describe('Misc', function () { ...@@ -67,7 +67,7 @@ describe('Misc', function () {
}) })
describe('eth_getCompilers', () => { 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) => { web3._requestManager.send({ method: 'eth_getCompilers', params: [] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
...@@ -78,7 +78,7 @@ describe('Misc', function () { ...@@ -78,7 +78,7 @@ describe('Misc', function () {
}) })
describe('eth_compileSolidity', () => { 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) => { web3._requestManager.send({ method: 'eth_compileSolidity', params: [] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
...@@ -89,7 +89,7 @@ describe('Misc', function () { ...@@ -89,7 +89,7 @@ describe('Misc', function () {
}) })
describe('eth_compileLLL', () => { 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) => { web3._requestManager.send({ method: 'eth_compileLLL', params: [] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
...@@ -100,7 +100,7 @@ describe('Misc', function () { ...@@ -100,7 +100,7 @@ describe('Misc', function () {
}) })
describe('eth_compileSerpent', () => { 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) => { web3._requestManager.send({ method: 'eth_compileSerpent', params: [] }, (err, result) => {
if (err) { if (err) {
throw new Error(err) throw new Error(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment