Merge pull request #1109 from ethereum/remix_sim_improvs

add bins & command line params for simulator and debugger
pull/5370/head
yann300 6 years ago committed by GitHub
commit 84aa808216
  1. 112
      remix-debug/bin/rdb
  2. 1
      remix-debug/package.json
  3. 1
      remix-debug/test.js
  4. 27
      remix-simulator/bin/ethsim
  5. 1
      remix-simulator/package.json
  6. 68
      remix-simulator/src/server.js

@ -0,0 +1,112 @@
#!/usr/bin/env node
const program = require('commander')
const version = require('../package.json').version
program
.command('version')
.description("outputs version number")
.action(() => {
console.log(version)
process.exit(0)
})
program
.command('help')
.description("outputs usage information")
.action(() => {
program.help()
process.exit(0)
})
program
.option('-f, --file [filename]', 'solidity filename to debug')
.option('--tx [txHash]', 'transaction hash to debug')
.option('--node [url]', 'node to connect to')
.parse(process.argv)
var CmdLine = require('../src/cmdline/index.js')
var solc = require('solc')
var fs = require('fs')
var filename = 'test/sol/simple_storage.sol'
var shortFilename = 'simple_storage.sol'
var inputJson = {
language: 'Solidity',
sources: {
},
settings: {
optimizer: {
enabled: true,
runs: 200
},
outputSelection: {
'*': {
'': [ 'legacyAST' ],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
}
}
inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
console.log('compiling...')
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
var compilation = {}
compilation.data = compilationData
compilation.source = { sources: inputJson.sources }
var cmdLine = new CmdLine()
cmdLine.connect('http', 'http://localhost:8545')
cmdLine.loadCompilationResult(compilation)
cmdLine.initDebugger()
var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
cmdLine.startDebug(tx, shortFilename)
cmdLine.events.on('source', () => {
cmdLine.getSource().forEach(console.dir)
})
const repl = require('repl')
repl.start({
prompt: '> ',
eval: (cmd, context, filename, cb) => {
let command = cmd.trim()
if (command === 'next' || command === 'n') {
cmdLine.stepOverForward(true)
}
if (command === 'previous' || command === 'p' || command === 'prev') {
cmdLine.stepOverBack(true)
}
if (command === 'step' || command === 's') {
cmdLine.stepIntoForward(true)
}
if (command === 'stepback' || command === 'sb') {
cmdLine.stepIntoBack(true)
}
if (command === 'exit' || command === 'quit') {
process.exit(0)
}
if (command === 'var local' || command === 'v l' || command === 'vl') {
cmdLine.displayLocals()
}
if (command === 'var global' || command === 'v g' || command === 'vg') {
cmdLine.displayGlobals()
}
if (command.split(' ')[0] === 'jump') {
let stepIndex = parseInt(command.split(' ')[1], 10)
cmdLine.jumpTo(stepIndex)
}
cb(null, '')
}
})
module.exports = cmdLine

@ -18,6 +18,7 @@
],
"main": "./index.js",
"dependencies": {
"commander": "^2.19.0",
"ethereumjs-util": "^4.5.0",
"ethereumjs-vm": "2.4.0",
"fast-async": "^6.1.2",

@ -1,3 +1,4 @@
// TODO: this file shoudl be removed at some point
var CmdLine = require('./src/cmdline/index.js')
// var compilation = require('./compilation.json')

@ -1,4 +1,29 @@
#!/usr/bin/env node
require('../src/server');
const program = require('commander')
const version = require('../package.json').version
program
.command('version')
.description("outputs version number")
.action(() => {
console.log(version)
process.exit(0)
})
program
.command('help')
.description("outputs usage information")
.action(() => {
program.help()
process.exit(0)
})
program
.option('-p, --port [port]', 'specify port')
.parse(process.argv)
const Server = require('../src/server')
const server = new Server()
server.start(program.port || 8545)

@ -17,6 +17,7 @@
"ansi-gray": "^0.1.1",
"body-parser": "^1.18.2",
"color-support": "^1.1.3",
"commander": "^2.19.0",
"express": "^4.16.3",
"express-ws": "^4.0.0",
"fast-async": "^6.3.7",

@ -5,35 +5,43 @@ const expressWs = require('express-ws')
const Provider = require('./provider')
const log = require('./utils/logs.js')
expressWs(app)
var provider = new Provider()
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.get('/', (req, res) => {
res.send('Welcome to remix-simulator')
})
app.use((req, res) => {
provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) {
return res.send(JSON.stringify({error: err}))
}
res.send(jsonResponse)
})
})
app.ws('/', (ws, req) => {
ws.on('message', function (msg) {
provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
return ws.send(JSON.stringify({error: err}))
}
ws.send(JSON.stringify(jsonResponse))
class Server {
constructor () {
this.provider = new Provider()
}
start (port) {
expressWs(app)
app.use(bodyParser.urlencoded({extended: true}))
app.use(bodyParser.json())
app.get('/', (req, res) => {
res.send('Welcome to remix-simulator')
})
app.use((req, res) => {
this.provider.sendAsync(req.body, (err, jsonResponse) => {
if (err) {
return res.send(JSON.stringify({error: err}))
}
res.send(jsonResponse)
})
})
app.ws('/', (ws, req) => {
ws.on('message', function (msg) {
this.provider.sendAsync(JSON.parse(msg), (err, jsonResponse) => {
if (err) {
return ws.send(JSON.stringify({error: err}))
}
ws.send(JSON.stringify(jsonResponse))
})
})
})
})
})
app.listen(8545, () => log('Remix Simulator listening on port 8545!'))
app.listen(port, () => log('Remix Simulator listening on port ' + port))
}
}
module.exports = Server

Loading…
Cancel
Save