1 |
|
2 | var CmdLine = require('./src/cmdline/index.js')
|
3 |
|
4 |
|
5 | var solc = require('solc')
|
6 | var fs = require('fs')
|
7 |
|
8 | var filename = 'test/sol/simple_storage.sol'
|
9 | var shortFilename = 'simple_storage.sol'
|
10 |
|
11 | var inputJson = {
|
12 | language: 'Solidity',
|
13 | sources: {
|
14 | },
|
15 | settings: {
|
16 | optimizer: {
|
17 | enabled: true,
|
18 | runs: 200
|
19 | },
|
20 | outputSelection: {
|
21 | '*': {
|
22 | '': [ 'legacyAST' ],
|
23 | '*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
|
24 | }
|
25 | }
|
26 | }
|
27 | }
|
28 |
|
29 | inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
|
30 |
|
31 | console.dir(inputJson)
|
32 |
|
33 | console.log('compiling...')
|
34 |
|
35 | let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
|
36 | console.dir(Object.keys(compilationData))
|
37 | var compilation = {}
|
38 | compilation.data = compilationData
|
39 | compilation.source = { sources: inputJson.sources }
|
40 | console.dir(compilation)
|
41 | console.dir(compilation.data.errors)
|
42 |
|
43 | var cmdLine = new CmdLine()
|
44 | cmdLine.connect('http', 'http://localhost:8545')
|
45 | cmdLine.loadCompilationResult(compilation)
|
46 | cmdLine.initDebugger()
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
|
63 |
|
64 |
|
65 | cmdLine.startDebug(tx, shortFilename)
|
66 |
|
67 | cmdLine.events.on('source', () => {
|
68 | cmdLine.getSource().forEach(console.dir)
|
69 | })
|
70 |
|
71 |
|
72 |
|
73 | const repl = require('repl')
|
74 |
|
75 | repl.start({
|
76 | prompt: '> ',
|
77 | eval: (cmd, context, filename, cb) => {
|
78 | let command = cmd.trim()
|
79 | if (command === 'next' || command === 'n') {
|
80 | cmdLine.stepOverForward(true)
|
81 | }
|
82 | if (command === 'previous' || command === 'p' || command === 'prev') {
|
83 | cmdLine.stepOverBack(true)
|
84 | }
|
85 | if (command === 'step' || command === 's') {
|
86 | cmdLine.stepIntoForward(true)
|
87 | }
|
88 | if (command === 'stepback' || command === 'sb') {
|
89 | cmdLine.stepIntoBack(true)
|
90 | }
|
91 | if (command === 'exit' || command === 'quit') {
|
92 | process.exit(0)
|
93 | }
|
94 | if (command === 'var local' || command === 'v l' || command === 'vl') {
|
95 | cmdLine.displayLocals()
|
96 | }
|
97 | if (command === 'var global' || command === 'v g' || command === 'vg') {
|
98 | cmdLine.displayGlobals()
|
99 | }
|
100 | if (command.split(' ')[0] === 'jump') {
|
101 | let stepIndex = parseInt(command.split(' ')[1], 10)
|
102 | cmdLine.jumpTo(stepIndex)
|
103 | }
|
104 | cb(null, '')
|
105 | }
|
106 | })
|
107 |
|
108 | module.exports = cmdLine
|
109 |
|