diff --git a/.travis.yml b/.travis.yml index 626308cf..8c503e72 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,11 +35,12 @@ matrix: - LANG=cpp before_install: - - git submodule update --init - | + set -e + git submodule update --init if [ $LANG = js ]; then ./tools/wabt/scripts/travis-before-install.sh - cd ./tools/wabt/ && make + (cd ./tools/wabt/ && make) npm install npm run validateBuild @@ -47,12 +48,12 @@ before_install: script: - | + set -e if [ $LANG = js ]; then - bin/evm2wasm.js 0x600160020200 trace + ./bin/evm2wasm.js 600160020200 --trace npm run $TEST_SUITE fi - - | if [ $LANG = cpp ]; then mkdir build && cd build cmake .. diff --git a/bin/evm2wasm.js b/bin/evm2wasm.js index 019ab571..80c1a756 100755 --- a/bin/evm2wasm.js +++ b/bin/evm2wasm.js @@ -5,17 +5,15 @@ const argv = require('minimist')(process.argv.slice(2)) const fs = require('fs') // convert evm bytecode to WASM or WAST -function convert (bytecode, wast) { +function convert (bytecode, opts) { return new Promise((resolve, reject) => { - outputFile = argv.o ? argv.o : undefined - if (!bytecode) { - resolve(Buffer.from('')) + return resolve(Buffer.from('')) } - if (wast) { + if (opts.wast) { let output = evm2wasm.evm2wast(bytecode, { - stackTrace: trace, + stackTrace: opts.trace, tempName: 'temp', inlineOps: true, wabt: false @@ -23,7 +21,7 @@ function convert (bytecode, wast) { resolve(output) } else { evm2wasm.evm2wasm(bytecode, { - stackTrace: trace, + stackTrace: opts.trace, tempName: 'temp', inlineOps: true, wabt: false @@ -48,28 +46,29 @@ function storeOrPrintResult (output, outputFile) { } } -let outputFile = argv.o ? argv.o : undefined -let wast = argv.wast !== undefined +const outputFile = argv.o ? argv.o : undefined +const wast = argv.wast !== undefined const trace = argv.trace !== undefined -let file = argv.e ? argv.e : undefined +const inputFile = argv.e ? argv.e : undefined let bytecode try { - if (!file) { + if (!inputFile) { if (argv._.length > 0) { - bytecode = argv._[0] + // ensure it is a string even it was passed as a number + bytecode = argv._[0].toString() } else { throw new Error('must provide evm bytecode file or supply bytecode as a non-named argument') } } else { - bytecode = fs.readFileSync(file).toString() + bytecode = fs.readFileSync(inputFile).toString() } // always consider input EVM as a hex string and translate that into binary for the next stage bytecode = Buffer.from(bytecode, 'hex') - convert(bytecode, wast).then((result) => { + convert(bytecode, { wast: wast, trace: trace }).then((result) => { storeOrPrintResult(result, outputFile) }).catch((err) => { throw err diff --git a/package.json b/package.json index 865daa1d..39ee6bdf 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "transcompiler" ], "dependencies": { + "eslint": "^4.19.1", "ethereumjs-block": "^1.2.2", "ethereumjs-util": "^5.1.5", "ewasm-kernel": "git+https://github.com/ewasm/ewasm-kernel.git#async-pojo",