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

pull/7/head
Iuri Matias 5 years ago
parent eddc2e3866
commit 3c657daa5a
  1. 2
      remix-simulator/index.js
  2. 10
      remix-simulator/src/genesis.js
  3. 10
      remix-simulator/src/methods/accounts.js
  4. 2
      remix-simulator/src/methods/blocks.js
  5. 2
      remix-simulator/src/methods/filters.js
  6. 8
      remix-simulator/src/methods/misc.js
  7. 2
      remix-simulator/src/methods/net.js
  8. 24
      remix-simulator/src/methods/transactions.js
  9. 14
      remix-simulator/src/methods/txProcess.js
  10. 8
      remix-simulator/src/provider.js
  11. 20
      remix-simulator/src/utils/logs.js
  12. 30
      remix-simulator/test/accounts.js
  13. 74
      remix-simulator/test/blocks.js
  14. 42
      remix-simulator/test/misc.js

@ -1,4 +1,4 @@
var Provider = require('./src/provider') const Provider = require('./src/provider')
module.exports = { module.exports = {
Provider: Provider Provider: Provider

@ -1,9 +1,9 @@
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) {
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)
}) })
} }

@ -1,8 +1,8 @@
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 () {
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()
}) })

@ -1,5 +1,5 @@
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'

@ -1,5 +1,5 @@
var Filters = function (executionContext) { const Filters = function (executionContext) {
this.executionContext = executionContext this.executionContext = executionContext
} }

@ -1,7 +1,7 @@
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) {
} }
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))
} }

@ -1,5 +1,5 @@
var Net = function () { const Net = function () {
} }
Net.prototype.methods = function () { Net.prototype.methods = function () {

@ -1,9 +1,9 @@
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) {
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) {
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) {
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
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
} }
// 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,

@ -1,9 +1,9 @@
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,
} }
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
} }
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
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) => {

@ -1,5 +1,5 @@
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 () {
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) {
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)
}) })
} }

@ -1,8 +1,8 @@
'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) {
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 = {
} }
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

@ -1,28 +1,28 @@
/* 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 () {
}) })
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)
}) })

@ -1,22 +1,22 @@
/* 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('blocks', function () { describe('blocks', () => {
before(function () { before(() => {
let provider = new RemixSim.Provider({ const provider = new RemixSim.Provider({
coinbase: '0x0000000000000000000000000000000000000001' coinbase: '0x0000000000000000000000000000000000000001'
}) })
web3.setProvider(provider) web3.setProvider(provider)
}) })
describe('eth_getBlockByNumber', () => { describe('eth_getBlockByNumber', () => {
it('should get block given its number', async function () { it('should get block given its number', async () => {
let block = await web3.eth.getBlock(0) const block = await web3.eth.getBlock(0)
let expectedBlock = { const expectedBlock = {
difficulty: '69762765929000', difficulty: '69762765929000',
extraData: '0x0', extraData: '0x0',
gasLimit: 8000000, gasLimit: 8000000,
@ -42,56 +42,56 @@ describe('blocks', function () {
}) })
describe('eth_getGasPrice', () => { describe('eth_getGasPrice', () => {
it('should get gas price', async function () { it('should get gas price', async () => {
let gasPrice = await web3.eth.getGasPrice() const gasPrice = await web3.eth.getGasPrice()
assert.equal(gasPrice, 1) assert.equal(gasPrice, 1)
}) })
}) })
describe('eth_coinbase', () => { describe('eth_coinbase', () => {
it('should get coinbase', async function () { it('should get coinbase', async () => {
let coinbase = await web3.eth.getCoinbase() const coinbase = await web3.eth.getCoinbase()
assert.equal(coinbase, '0x0000000000000000000000000000000000000001') assert.equal(coinbase, '0x0000000000000000000000000000000000000001')
}) })
}) })
describe('eth_blockNumber', () => { describe('eth_blockNumber', () => {
it('should get current block number', async function () { it('should get current block number', async () => {
let number = await web3.eth.getBlockNumber() const number = await web3.eth.getBlockNumber()
assert.equal(number, 0) assert.equal(number, 0)
}) })
}) })
describe('eth_getBlockByHash', () => { describe('eth_getBlockByHash', () => {
it('should get block given its hash', async function () { it('should get block given its hash', async () => {
let correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
let block = await web3.eth.getBlock(correctBlock.hash) const block = await web3.eth.getBlock(correctBlock.hash)
assert.deepEqual(block, correctBlock) assert.deepEqual(block, correctBlock)
}) })
}) })
describe('eth_getBlockTransactionCountByHash', () => { describe('eth_getBlockTransactionCountByHash', () => {
it('should get block given its hash', async function () { it('should get block given its hash', async () => {
let correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await web3.eth.getBlockTransactionCount(correctBlock.hash) const numberTransactions = await web3.eth.getBlockTransactionCount(correctBlock.hash)
assert.deepEqual(numberTransactions, 0) assert.deepEqual(numberTransactions, 0)
}) })
}) })
describe('eth_getBlockTransactionCountByNumber', () => { describe('eth_getBlockTransactionCountByNumber', () => {
it('should get block given its hash', async function () { it('should get block given its hash', async () => {
let numberTransactions = await web3.eth.getBlockTransactionCount(0) const numberTransactions = await web3.eth.getBlockTransactionCount(0)
assert.deepEqual(numberTransactions, 0) assert.deepEqual(numberTransactions, 0)
}) })
}) })
describe('eth_getUncleCountByBlockHash', () => { describe('eth_getUncleCountByBlockHash', () => {
it('should get block given its hash', async function () { it('should get block given its hash', async () => {
let correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await (new Promise((resolve, reject) => { const numberTransactions = await (new Promise((resolve, reject) => {
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => { web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => {
if (err) return reject(err) if (err) return reject(err)
resolve(numberTransactions) resolve(numberTransactions)
@ -102,9 +102,9 @@ describe('blocks', function () {
}) })
describe('eth_getUncleCountByBlockNumber', () => { describe('eth_getUncleCountByBlockNumber', () => {
it('should get block given its number', async function () { it('should get block given its number', async () => {
let correctBlock = await web3.eth.getBlock(0) const correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await (new Promise((resolve, reject) => { const numberTransactions = await (new Promise((resolve, reject) => {
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => { web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => {
if (err) return reject(err) if (err) return reject(err)
resolve(numberTransactions) resolve(numberTransactions)
@ -115,8 +115,8 @@ describe('blocks', function () {
}) })
describe('eth_getStorageAt', () => { describe('eth_getStorageAt', () => {
it('should get storage at position at given address', async function () { it('should get storage at position at given address', async () => {
let abi = [ const abi = [
{ {
'constant': false, 'constant': false,
'inputs': [ 'inputs': [
@ -198,7 +198,7 @@ describe('blocks', function () {
} }
] ]
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const contract = new web3.eth.Contract(abi) const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
@ -222,8 +222,8 @@ describe('blocks', function () {
}) })
describe('eth_call', () => { describe('eth_call', () => {
it('should get a value', async function () { it('should get a value', async () => {
let abi = [ const abi = [
{ {
'constant': false, 'constant': false,
'inputs': [ 'inputs': [
@ -305,7 +305,7 @@ describe('blocks', function () {
} }
] ]
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const contract = new web3.eth.Contract(abi) const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts() const accounts = await web3.eth.getAccounts()
@ -314,7 +314,7 @@ describe('blocks', function () {
contractInstance.currentProvider = web3.eth.currentProvider contractInstance.currentProvider = web3.eth.currentProvider
contractInstance.givenProvider = 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) assert.deepEqual(value, 100)
}) })
}) })

@ -1,22 +1,22 @@
/* 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 () {
}) })
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 () {
}) })
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 () {
}) })
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 () {
}) })
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 () {
}) })
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 () {
}) })
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)

Loading…
Cancel
Save