lint, build & test working for remix-simulator

pull/5/head
aniket-engg 4 years ago
parent 6c1c567790
commit a1f50eb141
  1. 15
      libs/remix-simulator/.eslintrc
  2. 4
      libs/remix-simulator/package.json
  3. 72
      libs/remix-simulator/src/methods/blocks.js
  4. 24
      libs/remix-simulator/src/methods/filters.js
  5. 27
      libs/remix-simulator/src/methods/transactions.js
  6. 2
      libs/remix-simulator/src/methods/txProcess.js
  7. 16
      libs/remix-simulator/src/provider.js
  8. 18
      libs/remix-simulator/tsconfig.lib.json
  9. 1024
      package-lock.json
  10. 6
      package.json
  11. 25
      workspace.json

@ -0,0 +1,15 @@
{
"extends": "../../.eslintrc",
"rules": {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": "off"
},
"env": {
"browser": true,
"amd": true,
"node": true,
"es6": true
},
"ignorePatterns": ["!**/*"]
}

@ -25,7 +25,7 @@
"express": "^4.16.3",
"express-ws": "^4.0.0",
"merge": "^1.2.0",
"remix-lib": "0.4.29",
"@remix-project/remix-lib": "0.4.29",
"standard": "^10.0.3",
"time-stamp": "^2.0.0",
"web3": "^1.2.4"
@ -44,7 +44,7 @@
},
"scripts": {
"lint": "standard",
"test": "standard && mocha test/"
"test": "./../../node_modules/.bin/mocha --require tsconfig-paths/register test/"
},
"bin": {
"ethsim": "./bin/ethsim",

@ -1,12 +1,13 @@
const Blocks = function (executionContext, _options) {
class Blocks {
constructor (executionContext, _options) {
this.executionContext = executionContext
const options = _options || {}
this.coinbase = options.coinbase || '0x0000000000000000000000000000000000000000'
this.blockNumber = 0
}
Blocks.prototype.methods = function () {
methods () {
return {
eth_getBlockByNumber: this.eth_getBlockByNumber.bind(this),
eth_gasPrice: this.eth_gasPrice.bind(this),
@ -21,7 +22,7 @@ Blocks.prototype.methods = function () {
}
}
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
eth_getBlockByNumber (payload, cb) {
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = this.executionContext.latestBlockNumber
@ -34,22 +35,22 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
}
let b = {
'number': toHex(block.header.number),
'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce),
'number': this.toHex(block.header.number),
'hash': this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot),
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
@ -57,32 +58,32 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
cb(null, b)
}
function toHex (value) {
toHex (value) {
if (!value) return '0x0'
let v = value.toString('hex')
return ((v === '0x' || v === '') ? '0x0' : ('0x' + v))
}
Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
eth_getBlockByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
let b = {
'number': toHex(block.header.number),
'hash': toHex(block.hash()),
'parentHash': toHex(block.header.parentHash),
'nonce': toHex(block.header.nonce),
'number': this.toHex(block.header.number),
'hash': this.toHex(block.hash()),
'parentHash': this.toHex(block.header.parentHash),
'nonce': this.toHex(block.header.nonce),
'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
'stateRoot': toHex(block.header.stateRoot),
'stateRoot': this.toHex(block.header.stateRoot),
'miner': this.coinbase,
'difficulty': toHex(block.header.difficulty),
'totalDifficulty': toHex(block.header.totalDifficulty),
'extraData': toHex(block.header.extraData),
'difficulty': this.toHex(block.header.difficulty),
'totalDifficulty': this.toHex(block.header.totalDifficulty),
'extraData': this.toHex(block.header.extraData),
'size': '0x027f07', // 163591
'gasLimit': toHex(block.header.gasLimit),
'gasUsed': toHex(block.header.gasUsed),
'timestamp': toHex(block.header.timestamp),
'gasLimit': this.toHex(block.header.gasLimit),
'gasUsed': this.toHex(block.header.gasUsed),
'timestamp': this.toHex(block.header.timestamp),
'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')),
'uncles': []
}
@ -90,39 +91,39 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) {
cb(null, b)
}
Blocks.prototype.eth_gasPrice = function (payload, cb) {
eth_gasPrice (payload, cb) {
cb(null, 1)
}
Blocks.prototype.eth_coinbase = function (payload, cb) {
eth_coinbase (payload, cb) {
cb(null, this.coinbase)
}
Blocks.prototype.eth_blockNumber = function (payload, cb) {
eth_blockNumber (payload, cb) {
cb(null, this.blockNumber)
}
Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) {
eth_getBlockTransactionCountByHash (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length)
}
Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) {
eth_getBlockTransactionCountByNumber (payload, cb) {
var block = this.executionContext.blocks[payload.params[0]]
cb(null, block.transactions.length)
}
Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) {
eth_getUncleCountByBlockHash (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
eth_getUncleCountByBlockNumber (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getStorageAt = function (payload, cb) {
eth_getStorageAt (payload, cb) {
const [address, position, blockNumber] = payload.params
this.executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
@ -134,5 +135,6 @@ Blocks.prototype.eth_getStorageAt = function (payload, cb) {
cb(err, value)
})
}
}
module.exports = Blocks

@ -1,9 +1,10 @@
const Filters = function (executionContext) {
class Filters {
constructor(executionContext) {
this.executionContext = executionContext
}
Filters.prototype.methods = function () {
methods () {
return {
eth_getLogs: this.eth_getLogs.bind(this),
eth_subscribe: this.eth_subscribe.bind(this),
@ -11,51 +12,52 @@ Filters.prototype.methods = function () {
}
}
Filters.prototype.eth_getLogs = function (payload, cb) {
eth_getLogs (payload, cb) {
let results = this.executionContext.logsManager.getLogsFor(payload.params[0])
cb(null, results)
}
Filters.prototype.eth_subscribe = function (payload, cb) {
eth_subscribe (payload, cb) {
let subscriptionId = this.executionContext.logsManager.subscribe(payload.params)
cb(null, subscriptionId)
}
Filters.prototype.eth_unsubscribe = function (payload, cb) {
eth_unsubscribe (payload, cb) {
this.executionContext.logsManager.unsubscribe(payload.params[0])
cb(null, true)
}
Filters.prototype.eth_newFilter = function (payload, cb) {
eth_newFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('filter', payload.params[0])
cb(null, filterId)
}
Filters.prototype.eth_newBlockFilter = function (payload, cb) {
eth_newBlockFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('block')
cb(null, filterId)
}
Filters.prototype.eth_newPendingTransactionFilter = function (payload, cb) {
eth_newPendingTransactionFilter (payload, cb) {
const filterId = this.executionContext.logsManager.newFilter('pendingTransactions')
cb(null, filterId)
}
Filters.prototype.eth_uninstallfilter = function (payload, cb) {
eth_uninstallfilter (payload, cb) {
const result = this.executionContext.logsManager.uninstallFilter(payload.params[0])
cb(null, result)
}
Filters.prototype.eth_getFilterChanges = function (payload, cb) {
eth_getFilterChanges (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results)
}
Filters.prototype.eth_getFilterLogs = function (payload, cb) {
eth_getFilterLogs (payload, cb) {
const filterId = payload.params[0]
let results = this.executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results)
}
}
module.exports = Filters

@ -3,15 +3,17 @@ const ethJSUtil = require('ethereumjs-util')
const processTx = require('./txProcess.js')
const BN = ethJSUtil.BN
const Transactions = function (executionContext) {
class Transactions{
constructor(executionContext) {
this.executionContext = executionContext
}
Transactions.prototype.init = function (accounts) {
init (accounts) {
this.accounts = accounts
}
Transactions.prototype.methods = function () {
methods () {
return {
eth_sendTransaction: this.eth_sendTransaction.bind(this),
eth_getTransactionReceipt: this.eth_getTransactionReceipt.bind(this),
@ -25,7 +27,7 @@ Transactions.prototype.methods = function () {
}
}
Transactions.prototype.eth_sendTransaction = function (payload, cb) {
eth_sendTransaction (payload, cb) {
// from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
@ -33,7 +35,7 @@ Transactions.prototype.eth_sendTransaction = function (payload, cb) {
processTx(this.executionContext, this.accounts, payload, false, cb)
}
Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
eth_getTransactionReceipt (payload, cb) {
this.executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => {
if (error) {
return cb(error)
@ -61,11 +63,11 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
})
}
Transactions.prototype.eth_estimateGas = function (payload, cb) {
eth_estimateGas (payload, cb) {
cb(null, 3000000)
}
Transactions.prototype.eth_getCode = function (payload, cb) {
eth_getCode (payload, cb) {
let address = payload.params[0]
this.executionContext.web3().eth.getCode(address, (error, result) => {
@ -77,7 +79,7 @@ Transactions.prototype.eth_getCode = function (payload, cb) {
})
}
Transactions.prototype.eth_call = function (payload, cb) {
eth_call (payload, cb) {
// from might be lowercased address (web3)
if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
@ -91,7 +93,7 @@ Transactions.prototype.eth_call = function (payload, cb) {
processTx(this.executionContext, this.accounts, payload, true, cb)
}
Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
eth_getTransactionCount (payload, cb) {
let address = payload.params[0]
this.executionContext.vm().stateManager.getAccount(address, (err, account) => {
@ -103,7 +105,7 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) {
})
}
Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
eth_getTransactionByHash (payload, cb) {
const address = payload.params[0]
this.executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => {
@ -148,7 +150,7 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
})
}
Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) {
eth_getTransactionByBlockHashAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
@ -190,7 +192,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload
})
}
Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) {
eth_getTransactionByBlockNumberAndIndex (payload, cb) {
const txIndex = payload.params[1]
const txBlock = this.executionContext.blocks[payload.params[0]]
@ -231,5 +233,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo
cb(null, r)
})
}
}
module.exports = Transactions

@ -1,4 +1,4 @@
const RemixLib = require('remix-lib')
const RemixLib = require('@remix-project/remix-lib')
const TxExecution = RemixLib.execution.txExecution
const TxRunner = RemixLib.execution.txRunner

@ -1,4 +1,4 @@
const RemixLib = require('remix-lib')
const RemixLib = require('@remix-project/remix-lib')
const executionContext = RemixLib.execution.executionContext
const log = require('./utils/logs.js')
@ -13,7 +13,8 @@ const Transactions = require('./methods/transactions.js')
const generateBlock = require('./genesis.js')
var Provider = function (options) {
class Provider {
constructor(options) {
this.options = options || {}
// TODO: init executionContext here
this.executionContext = executionContext
@ -32,12 +33,12 @@ var Provider = function (options) {
this.init()
}
Provider.prototype.init = async function () {
async init () {
await this.Accounts.init()
this.Transactions.init(this.Accounts.accounts)
}
Provider.prototype.sendAsync = function (payload, callback) {
sendAsync (payload, callback) {
log.info('payload method is ', payload.method)
const method = this.methods[payload.method]
@ -60,16 +61,17 @@ Provider.prototype.sendAsync = function (payload, callback) {
callback(new Error('unknown method ' + payload.method))
}
Provider.prototype.send = function (payload, callback) {
send (payload, callback) {
this.sendAsync(payload, callback || function () {})
}
Provider.prototype.isConnected = function () {
isConnected () {
return true
}
Provider.prototype.on = function (type, cb) {
on (type, cb) {
this.executionContext.logsManager.addListener(type, cb)
}
}
module.exports = Provider

@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../dist/out-tsc",
"allowJs": true,
"declaration": true,
"rootDir": "./",
"types": ["node"]
},
"exclude": ["**/*.spec.js"],
"include": [
"src/**/*.js",
"./index.js",
"bin/"
]
}

1024
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -132,11 +132,14 @@
"dependencies": {
"@remixproject/engine": "^0.2.3",
"@types/tape": "^4.2.33",
"ansi-gray": "^0.1.1",
"color-support": "^1.1.3",
"ethereumjs-block": "^2.2.2",
"ethereumjs-tx": "^2.1.2",
"ethereumjs-vm": "4.1.3",
"http-server": "^0.11.1",
"npm-install-version": "^6.0.2"
"npm-install-version": "^6.0.2",
"time-stamp": "^2.2.0"
},
"devDependencies": {
"@babel/core": "^7.4.5",
@ -200,6 +203,7 @@
"js-beautify": "1.6.14",
"minixhr": "^3.2.2",
"mkdirp": "^0.5.1",
"mocha": "^8.0.1",
"nanohtml": "^1.6.3",
"nightwatch": "^1.3.5",
"notify-error": "^1.2.0",

@ -234,29 +234,36 @@
"schematics": {},
"architect": {
"lint": {
"builder": "@nrwl/workspace:run-commands",
"builder": "@nrwl/linter:lint",
"options": {
"commands": [
{
"command": "./../../node_modules/.bin/npm-run-all lint"
}
"linter": "eslint",
"config": "libs/remix-simulator/.eslintrc",
"files": [
"libs/remix-simulator/**/*.js"
],
"cwd": "libs/remix-simulator"
"exclude": ["**/node_modules/**", "libs/remix-simulator/test/**/*"]
}
},
"test": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "rm -rf ../../dist"
},
{
"command": "./../../node_modules/.bin/npm-run-all test"
}
],
"cwd": "libs/remix-simulator"
}
},
"build": {
"builder": "@nrwl/node:package",
"options": {
"outputPath": "dist/libs/remix-simulator",
"tsConfig": "libs/remix-simulator/tsconfig.lib.json",
"packageJson": "libs/remix-simulator/package.json",
"main": "libs/remix-simulator/index.js",
"assets": ["libs/remix-simulator/*.md"]
}
}
}
},

Loading…
Cancel
Save