From cee49f03f9eaf421b578d7d509859fafae59a48b Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 29 Aug 2018 13:04:07 -0400 Subject: [PATCH] add test command & fixing linting --- .travis.yml | 1 + remix-simulator/package.json | 2 +- remix-simulator/src/methods/net.js | 10 +-- remix-simulator/src/utils/logs.js | 103 +++++++++++++++-------------- remix-simulator/test/accounts.js | 12 ++-- remix-simulator/test/blocks.js | 16 ++--- remix-simulator/test/misc.js | 46 +++++++------ remix-simulator/test/whisper.js | 14 ++-- 8 files changed, 103 insertions(+), 101 deletions(-) diff --git a/.travis.yml b/.travis.yml index 16fb9517ac..8db3013e25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ env: - TEST_DIR=remix-solidity - TEST_DIR=remix-debug - TEST_DIR=remix-tests + - TEST_DIR=remix-simulator script: - cd $TEST_DIR && npm install && npm test deploy: diff --git a/remix-simulator/package.json b/remix-simulator/package.json index 26d4c15c13..b5cacc280a 100644 --- a/remix-simulator/package.json +++ b/remix-simulator/package.json @@ -29,7 +29,7 @@ "web3": "1.0.0-beta.27" }, "scripts": { - "test": "standard" + "test": "standard && mocha test/" }, "bin": { "ethsim": "./bin/ethsim", diff --git a/remix-simulator/src/methods/net.js b/remix-simulator/src/methods/net.js index 70db0d73cb..83104d772b 100644 --- a/remix-simulator/src/methods/net.js +++ b/remix-simulator/src/methods/net.js @@ -1,8 +1,8 @@ -var Net = function() { +var Net = function () { } -Net.prototype.methods = function() { +Net.prototype.methods = function () { return { net_version: this.net_version, net_listening: this.net_listening, @@ -10,16 +10,16 @@ Net.prototype.methods = function() { } } -Net.prototype.net_version = function(payload, cb) { +Net.prototype.net_version = function (payload, cb) { // should be configured networkId cb(null, 1337) } -Net.prototype.net_listening = function(payload, cb) { +Net.prototype.net_listening = function (payload, cb) { cb(null, true) } -Net.prototype.net_peerCount = function(payload, cb) { +Net.prototype.net_peerCount = function (payload, cb) { cb(null, 0) } diff --git a/remix-simulator/src/utils/logs.js b/remix-simulator/src/utils/logs.js index d117ea9fcb..7139140b97 100644 --- a/remix-simulator/src/utils/logs.js +++ b/remix-simulator/src/utils/logs.js @@ -1,81 +1,82 @@ -'use strict'; +'use strict' -var gray = require('ansi-gray'); -var timestamp = require('time-stamp'); -var supportsColor = require('color-support'); +var gray = require('ansi-gray') +var timestamp = require('time-stamp') +var supportsColor = require('color-support') -function hasFlag(flag) { - return ((typeof(process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)); +function hasFlag (flag) { + return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)) } -function addColor(str) { +function addColor (str) { if (hasFlag('no-color')) { - return str; + return str } if (hasFlag('color')) { - return gray(str); + return gray(str) } if (supportsColor()) { - return gray(str); + return gray(str) } - return str; + return str } let logger = { - stdout: function(arg) { - if (typeof(process) === 'undefined' || !process.stdout) return; - process.stdout.write(arg); + stdout: function (arg) { + if (typeof (process) === 'undefined' || !process.stdout) return + process.stdout.write(arg) }, - stderr: function(arg) { - if (typeof(process) === 'undefined' || process.stderr) return; - process.stderr.write(arg); - }, -}; + stderr: function (arg) { + if (typeof (process) === 'undefined' || process.stderr) return + process.stderr.write(arg) + } +} -function getTimestamp(){ - return '['+addColor(timestamp('HH:mm:ss'))+']'; +function getTimestamp () { + let coloredTimestamp = addColor(timestamp('HH:mm:ss')) + return '[' + coloredTimestamp + ']' } -function log(){ - var time = getTimestamp(); - logger.stdout(time + ' '); - console.log.apply(console, arguments); - return this; +function log () { + var time = getTimestamp() + logger.stdout(time + ' ') + console.log.apply(console, arguments) + return this } -function info(){ - var time = getTimestamp(); - logger.stdout(time + ' '); - console.info.apply(console, arguments); - return this; +function info () { + var time = getTimestamp() + logger.stdout(time + ' ') + console.info.apply(console, arguments) + return this } -function dir(){ - var time = getTimestamp(); - logger.stdout(time + ' '); - console.dir.apply(console, arguments); - return this; +function dir () { + var time = getTimestamp() + logger.stdout(time + ' ') + console.dir.apply(console, arguments) + return this } -function warn(){ - var time = getTimestamp(); - logger.stderr(time + ' '); - console.warn.apply(console, arguments); - return this; +function warn () { + var time = getTimestamp() + logger.stderr(time + ' ') + console.warn.apply(console, arguments) + return this } -function error(){ - var time = getTimestamp(); - logger.stderr(time + ' '); - console.error.apply(console, arguments); - return this; +function error () { + var time = getTimestamp() + logger.stderr(time + ' ') + console.error.apply(console, arguments) + return this } -module.exports = log; -module.exports.info = info; -module.exports.dir = dir; -module.exports.warn = warn; -module.exports.error = error; +module.exports = log +module.exports.info = info +module.exports.dir = dir +module.exports.warn = warn +module.exports.error = error diff --git a/remix-simulator/test/accounts.js b/remix-simulator/test/accounts.js index 689baed8d7..e9d6e2f652 100644 --- a/remix-simulator/test/accounts.js +++ b/remix-simulator/test/accounts.js @@ -1,19 +1,17 @@ +/* global describe, before, it */ var Web3 = require('web3') var RemixSim = require('../index.js') let web3 = new Web3() var assert = require('assert') -describe("Accounts", function() { - - before(function() { +describe('Accounts', function () { + before(function () { let provider = new RemixSim.Provider() web3.setProvider(provider) }) - it("should get a list of accounts", async function() { + it('should get a list of accounts', async function () { let accounts = await web3.eth.getAccounts() assert.notEqual(accounts.length, 0) }) - -}); - +}) diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js index 80ba0bd635..8cc275c20c 100644 --- a/remix-simulator/test/blocks.js +++ b/remix-simulator/test/blocks.js @@ -1,16 +1,16 @@ +/* global describe, before, it */ var Web3 = require('web3') var RemixSim = require('../index.js') -let web3 = new Web3(); +let web3 = new Web3() var assert = require('assert') -describe("blocks", function() { - - before(function() { +describe('blocks', function () { + before(function () { let provider = new RemixSim.Provider() web3.setProvider(provider) }) - it("should get block given its number", async function() { + it('should get block given its number', async function () { let block = await web3.eth.getBlock(1) let expectedBlock = { @@ -39,10 +39,8 @@ describe("blocks", function() { assert.deepEqual(block, expectedBlock) }) - it("should get gas price", async function() { + it('should get gas price', async function () { let gasPrice = await web3.eth.getGasPrice() assert.equal(gasPrice, 1) }) - -}); - +}) diff --git a/remix-simulator/test/misc.js b/remix-simulator/test/misc.js index 0f8e8b8467..27cc95c5cb 100644 --- a/remix-simulator/test/misc.js +++ b/remix-simulator/test/misc.js @@ -1,50 +1,56 @@ +/* global describe, before, it */ var Web3 = require('web3') var RemixSim = require('../index.js') -let web3 = new Web3(); +let web3 = new Web3() var assert = require('assert') -describe("Misc", function() { - - before(function() { +describe('Misc', function () { + before(function () { let provider = new RemixSim.Provider() web3.setProvider(provider) }) - it("should get correct remix simulator version", async function(done) { + it('should get correct remix simulator version', async function (done) { web3._requestManager.send({method: 'web3_clientVersion', params: []}, (err, version) => { - let remix_version = require('../package.json').version - assert.equal(version, "Remix Simulator/" + remix_version) - done(); + if (err) { + throw new Error(err) + } + let remixVersion = require('../package.json').version + assert.equal(version, 'Remix Simulator/' + remixVersion) + done() }) }) - it("should get protocol version", async function() { + it('should get protocol version', async function () { web3._requestManager.send({method: 'eth_protocolVersion', params: []}, (err, result) => { - assert.equal(result, "0x3f") + if (err) { + throw new Error(err) + } + assert.equal(result, '0x3f') }) }) - it("should get if is syncing", async function() { + it('should get if is syncing', async function () { let isSyncing = await web3.eth.isSyncing() assert.equal(isSyncing, false) }) - it("should get if is mining", async function() { + it('should get if is mining', async function () { let isMining = await web3.eth.isMining() assert.equal(isMining, false) }) - it("should get hashrate", async function() { + it('should get hashrate', async function () { let hashrate = await web3.eth.getHashrate() assert.equal(hashrate, 0) }) - it("should get result of a sha3", async function() { - web3._requestManager.send({method: 'web3_sha3', params: ["0x68656c6c6f20776f726c64"]}, (err, result) => { - assert.equal(result, "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad") + it('should get result of a sha3', async function () { + web3._requestManager.send({method: 'web3_sha3', params: ['0x68656c6c6f20776f726c64']}, (err, result) => { + if (err) { + throw new Error(err) + } + assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad') }) }) - -}); - - +}) diff --git a/remix-simulator/test/whisper.js b/remix-simulator/test/whisper.js index 54565acbd2..e288f0730b 100644 --- a/remix-simulator/test/whisper.js +++ b/remix-simulator/test/whisper.js @@ -1,19 +1,17 @@ +/* global describe, before, it */ var Web3 = require('web3') var RemixSim = require('../index.js') -let web3 = new Web3(); +let web3 = new Web3() var assert = require('assert') -describe("Whisper", function() { - - before(function() { +describe('Whisper', function () { + before(function () { let provider = new RemixSim.Provider() web3.setProvider(provider) }) - it("should get correct remix simulator version", async function() { + it('should get correct remix simulator version', async function () { let version = await web3.shh.getVersion() assert.equal(version, 5) }) - -}); - +})