Unverified Commit 7e9dfe1a authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #953 from ethereum/more_calls

add more calls to remix-simulator + add test suite
parents 0c20140d 37fe70ec
...@@ -43,6 +43,16 @@ jobs: ...@@ -43,6 +43,16 @@ jobs:
- checkout - checkout
- run: npm install && npm run bootstrap - run: npm install && npm run bootstrap
- run: cd remix-tests && npm test - run: cd remix-tests && npm test
remix-simulator:
docker:
- image: circleci/node:9.11.2
environment:
working_directory: ~/repo
steps:
- checkout
- run: npm install && npm run bootstrap
- run: cd remix-simulator && npm test
workflows: workflows:
...@@ -53,3 +63,4 @@ workflows: ...@@ -53,3 +63,4 @@ workflows:
- remix-debug - remix-debug
- remix-analyzer - remix-analyzer
- remix-tests - remix-tests
- remix-simulator
...@@ -6,6 +6,7 @@ env: ...@@ -6,6 +6,7 @@ env:
- TEST_DIR=remix-solidity - TEST_DIR=remix-solidity
- TEST_DIR=remix-debug - TEST_DIR=remix-debug
- TEST_DIR=remix-tests - TEST_DIR=remix-tests
- TEST_DIR=remix-simulator
script: script:
- cd $TEST_DIR && npm install && npm test - cd $TEST_DIR && npm install && npm test
deploy: deploy:
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"remix-lib", "remix-lib",
"remix-solidity", "remix-solidity",
"remix-analyzer", "remix-analyzer",
"remix-tests" "remix-tests",
"remix-simulator"
], ],
"version": "independent" "version": "independent"
} }
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
"web3": "1.0.0-beta.27" "web3": "1.0.0-beta.27"
}, },
"scripts": { "scripts": {
"test": "standard" "test": "standard && mocha test/"
}, },
"bin": { "bin": {
"ethsim": "./bin/ethsim", "ethsim": "./bin/ethsim",
...@@ -82,5 +82,8 @@ ...@@ -82,5 +82,8 @@
} }
] ]
] ]
},
"devDependencies": {
"mocha": "^5.2.0"
} }
} }
var version = require('../../package.json').version var version = require('../../package.json').version
var web3 = require('web3')
var Misc = function () { var Misc = function () {
} }
Misc.prototype.methods = function () { Misc.prototype.methods = function () {
return { return {
web3_clientVersion: this.web3_clientVersion.bind(this) web3_clientVersion: this.web3_clientVersion.bind(this),
eth_protocolVersion: this.eth_protocolVersion.bind(this),
eth_syncing: this.eth_syncing.bind(this),
eth_mining: this.eth_mining.bind(this),
eth_hashrate: this.eth_hashrate.bind(this),
web3_sha3: this.web3_sha3.bind(this)
} }
} }
...@@ -13,4 +19,26 @@ Misc.prototype.web3_clientVersion = function (payload, cb) { ...@@ -13,4 +19,26 @@ Misc.prototype.web3_clientVersion = function (payload, cb) {
cb(null, 'Remix Simulator/' + version) cb(null, 'Remix Simulator/' + version)
} }
Misc.prototype.eth_protocolVersion = function (payload, cb) {
cb(null, '0x3f')
}
Misc.prototype.eth_syncing = function (payload, cb) {
cb(null, false)
}
Misc.prototype.eth_mining = function (payload, cb) {
// TODO: should depend on the state
cb(null, false)
}
Misc.prototype.eth_hashrate = function (payload, cb) {
cb(null, '0x0')
}
Misc.prototype.web3_sha3 = function (payload, cb) {
let str = payload.params[0]
cb(null, web3.utils.sha3(str))
}
module.exports = Misc module.exports = Misc
var Net = function () {
}
Net.prototype.methods = function () {
return {
net_version: this.net_version,
net_listening: this.net_listening,
net_peerCount: this.net_peerCount
}
}
Net.prototype.net_version = function (payload, cb) {
// should be configured networkId
cb(null, 1337)
}
Net.prototype.net_listening = function (payload, cb) {
cb(null, true)
}
Net.prototype.net_peerCount = function (payload, cb) {
cb(null, 0)
}
module.exports = Net
...@@ -4,6 +4,7 @@ const merge = require('merge') ...@@ -4,6 +4,7 @@ const merge = require('merge')
const Accounts = require('./methods/accounts.js') const Accounts = require('./methods/accounts.js')
const Blocks = require('./methods/blocks.js') const Blocks = require('./methods/blocks.js')
const Misc = require('./methods/misc.js') const Misc = require('./methods/misc.js')
const Net = require('./methods/net.js')
const Transactions = require('./methods/transactions.js') const Transactions = require('./methods/transactions.js')
const Whisper = require('./methods/whisper.js') const Whisper = require('./methods/whisper.js')
...@@ -14,6 +15,7 @@ var Provider = function () { ...@@ -14,6 +15,7 @@ var Provider = function () {
this.methods = merge(this.methods, this.Accounts.methods()) this.methods = merge(this.methods, this.Accounts.methods())
this.methods = merge(this.methods, (new Blocks()).methods()) this.methods = merge(this.methods, (new Blocks()).methods())
this.methods = merge(this.methods, (new Misc()).methods()) this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods()) this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods())
this.methods = merge(this.methods, (new Whisper()).methods()) this.methods = merge(this.methods, (new Whisper()).methods())
} }
......
'use strict'; 'use strict'
var gray = require('ansi-gray'); var gray = require('ansi-gray')
var timestamp = require('time-stamp'); var timestamp = require('time-stamp')
var supportsColor = require('color-support'); var supportsColor = require('color-support')
function hasFlag(flag) { function hasFlag (flag) {
return ((typeof(process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1)); return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
} }
function addColor(str) { function addColor (str) {
if (hasFlag('no-color')) { if (hasFlag('no-color')) {
return str; return str
} }
if (hasFlag('color')) { if (hasFlag('color')) {
return gray(str); return gray(str)
} }
if (supportsColor()) { if (supportsColor()) {
return gray(str); return gray(str)
} }
return str; return str
} }
let logger = { let logger = {
stdout: function(arg) { stdout: function (arg) {
if (typeof(process) === 'undefined' || !process.stdout) return; if (typeof (process) === 'undefined' || !process.stdout) return
process.stdout.write(arg); process.stdout.write(arg)
}, },
stderr: function(arg) { stderr: function (arg) {
if (typeof(process) === 'undefined' || process.stderr) return; if (typeof (process) === 'undefined' || process.stderr) return
process.stderr.write(arg); process.stderr.write(arg)
}, }
}; }
function getTimestamp(){ function getTimestamp () {
return '['+addColor(timestamp('HH:mm:ss'))+']'; let coloredTimestamp = addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']'
} }
function log(){ function log () {
var time = getTimestamp(); var time = getTimestamp()
logger.stdout(time + ' '); logger.stdout(time + ' ')
console.log.apply(console, arguments); console.log.apply(console, arguments)
return this; return this
} }
function info(){ function info () {
var time = getTimestamp(); var time = getTimestamp()
logger.stdout(time + ' '); logger.stdout(time + ' ')
console.info.apply(console, arguments); console.info.apply(console, arguments)
return this; return this
} }
function dir(){ function dir () {
var time = getTimestamp(); var time = getTimestamp()
logger.stdout(time + ' '); logger.stdout(time + ' ')
console.dir.apply(console, arguments); console.dir.apply(console, arguments)
return this; return this
} }
function warn(){ function warn () {
var time = getTimestamp(); var time = getTimestamp()
logger.stderr(time + ' '); logger.stderr(time + ' ')
console.warn.apply(console, arguments); console.warn.apply(console, arguments)
return this; return this
} }
function error(){ function error () {
var time = getTimestamp(); var time = getTimestamp()
logger.stderr(time + ' '); logger.stderr(time + ' ')
console.error.apply(console, arguments); console.error.apply(console, arguments)
return this; return this
} }
module.exports = log; module.exports = log
module.exports.info = info; module.exports.info = info
module.exports.dir = dir; module.exports.dir = dir
module.exports.warn = warn; module.exports.warn = warn
module.exports.error = error; module.exports.error = error
/* 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 () {
let provider = new RemixSim.Provider()
web3.setProvider(provider)
})
it('should get a list of accounts', async function () {
let accounts = await web3.eth.getAccounts()
assert.notEqual(accounts.length, 0)
})
})
/* global describe, before, it */
var Web3 = require('web3')
var RemixSim = require('../index.js')
let web3 = new Web3()
var assert = require('assert')
describe('blocks', function () {
before(function () {
let provider = new RemixSim.Provider()
web3.setProvider(provider)
})
it('should get block given its number', async function () {
let block = await web3.eth.getBlock(1)
let expectedBlock = {
difficulty: '0',
extraData: '0x',
gasLimit: 8000000,
gasUsed: 0,
hash: '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
miner: '0x3333333333333333333333333333333333333333',
mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
nonce: '0x0000000000000042',
number: 0,
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 504,
stateRoot: '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff',
timestamp: 0,
totalDifficulty: '0',
transactions: [],
transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
uncles: []
}
assert.deepEqual(block, expectedBlock)
})
it('should get gas price', async function () {
let gasPrice = await web3.eth.getGasPrice()
assert.equal(gasPrice, 1)
})
})
/* global describe, before, it */
var Web3 = require('web3')
var RemixSim = require('../index.js')
let web3 = new Web3()
var assert = require('assert')
describe('Misc', function () {
before(function () {
let provider = new RemixSim.Provider()
web3.setProvider(provider)
})
it('should get correct remix simulator version', async function (done) {
web3._requestManager.send({method: 'web3_clientVersion', params: []}, (err, version) => {
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 () {
web3._requestManager.send({method: 'eth_protocolVersion', params: []}, (err, result) => {
if (err) {
throw new Error(err)
}
assert.equal(result, '0x3f')
})
})
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 () {
let isMining = await web3.eth.isMining()
assert.equal(isMining, false)
})
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) => {
if (err) {
throw new Error(err)
}
assert.equal(result, '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad')
})
})
})
/* global describe, before, it */
var Web3 = require('web3')
var RemixSim = require('../index.js')
let web3 = new Web3()
var assert = require('assert')
describe('Whisper', function () {
before(function () {
let provider = new RemixSim.Provider()
web3.setProvider(provider)
})
it('should get correct remix simulator version', async function () {
let version = await web3.shh.getVersion()
assert.equal(version, 5)
})
})
...@@ -41,12 +41,13 @@ ...@@ -41,12 +41,13 @@
"change-case": "^3.0.1", "change-case": "^3.0.1",
"colors": "^1.1.2", "colors": "^1.1.2",
"commander": "^2.13.0", "commander": "^2.13.0",
"remix-lib": "^0.3.7",
"remix-simulator": "0.0.3", "remix-simulator": "0.0.3",
"remix-solidity": "^0.2.7", "remix-solidity": "^0.2.7",
"signale": "^1.2.1", "signale": "^1.2.1",
"solc": "^0.4.24", "solc": "^0.4.24",
"standard": "^10.0.3", "standard": "^10.0.3",
"web3": "1.0.0-beta.27", "web3": "1.0.0-beta.34",
"winston": "^3.0.0" "winston": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment