add test command & fixing linting

pull/5370/head
Iuri Matias 6 years ago
parent 6ecacea7ea
commit cee49f03f9
  1. 1
      .travis.yml
  2. 2
      remix-simulator/package.json
  3. 83
      remix-simulator/src/utils/logs.js
  4. 10
      remix-simulator/test/accounts.js
  5. 14
      remix-simulator/test/blocks.js
  6. 44
      remix-simulator/test/misc.js
  7. 12
      remix-simulator/test/whisper.js

@ -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:

@ -29,7 +29,7 @@
"web3": "1.0.0-beta.27"
},
"scripts": {
"test": "standard"
"test": "standard && mocha test/"
},
"bin": {
"ethsim": "./bin/ethsim",

@ -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));
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
}
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);
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);
},
};
if (typeof (process) === 'undefined' || process.stderr) return
process.stderr.write(arg)
}
}
function getTimestamp () {
return '['+addColor(timestamp('HH:mm:ss'))+']';
let coloredTimestamp = addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']'
}
function log () {
var time = getTimestamp();
logger.stdout(time + ' ');
console.log.apply(console, arguments);
return this;
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;
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;
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;
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;
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

@ -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() {
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)
})
});
})

@ -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() {
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)
})
});
})

@ -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() {
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')
})
})
})
});

@ -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() {
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)
})
});
})

Loading…
Cancel
Save