Merge pull request #1272 from ethereum/improve_remix_sim4

Implement filters; add more tests; eth_getStorageAt
pull/5370/head
Iuri Matias 5 years ago committed by GitHub
commit 6f076efdee
  1. 2
      remix-lib/src/execution/execution-context.js
  2. 44
      remix-lib/src/execution/logsManager.js
  3. 2
      remix-lib/src/execution/txExecution.js
  4. 9
      remix-lib/src/web3Provider/web3VmProvider.js
  5. 28
      remix-simulator/README.md
  6. 4
      remix-simulator/bin/ethsim
  7. 2
      remix-simulator/package.json
  8. 15
      remix-simulator/src/methods/accounts.js
  9. 23
      remix-simulator/src/methods/blocks.js
  10. 33
      remix-simulator/src/methods/filters.js
  11. 14
      remix-simulator/src/methods/transactions.js
  12. 4
      remix-simulator/src/methods/txProcess.js
  13. 15
      remix-simulator/src/methods/whisper.js
  14. 13
      remix-simulator/src/provider.js
  15. 7
      remix-simulator/src/server.js
  16. 30
      remix-simulator/test/accounts.js
  17. 340
      remix-simulator/test/blocks.js
  18. 114
      remix-simulator/test/misc.js
  19. 17
      remix-simulator/test/whisper.js

@ -115,6 +115,7 @@ function ExecutionContext () {
this.blockGasLimit = this.blockGasLimitDefault
this.customNetWorks = {}
this.blocks = {}
this.latestBlockNumber = 0
this.txs = {}
this.init = function (config) {
@ -309,6 +310,7 @@ function ExecutionContext () {
self.blocks['0x' + block.hash().toString('hex')] = block
self.blocks[blockNumber] = block
self.latestBlockNumber = blockNumber
this.logsManager.checkBlock(blockNumber, block, this.web3())
}

@ -6,6 +6,8 @@ class LogsManager {
constructor () {
this.notificationCallbacks = []
this.subscriptions = {}
this.filters = {}
this.filterTracking = {}
this.oldLogs = []
}
@ -66,13 +68,20 @@ class LogsManager {
const subscriptionParams = this.subscriptions[subscriptionId]
const [queryType, queryFilter] = subscriptionParams
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter)) {
if (this.eventMatchesFilter(changeEvent, queryType, queryFilter || {topics: []})) {
matchedSubscriptions.push(subscriptionId)
}
}
return matchedSubscriptions
}
getLogsForSubscription (subscriptionId) {
const subscriptionParams = this.subscriptions[subscriptionId]
const [_queryType, queryFilter] = subscriptionParams // eslint-disable-line
return this.getLogsFor(queryFilter)
}
transmit (result) {
this.notificationCallbacks.forEach((callback) => {
if (result.params.result.raw) {
@ -97,6 +106,39 @@ class LogsManager {
delete this.subscriptions[subscriptionId]
}
newFilter (filterType, params) {
const filterId = '0x' + crypto.randomBytes(16).toString('hex')
if (filterType === 'block' || filterType === 'pendingTransactions') {
this.filters[filterId] = { filterType }
}
if (filterType === 'filter') {
this.filters[filterId] = { filterType, params }
}
this.filterTracking[filterId] = {}
return filterId
}
uninstallFilter (filterId) {
delete this.filters[filterId]
}
getLogsForFilter (filterId, logsOnly) {
const {filterType, params} = this.filter[filterId]
const tracking = this.filterTracking[filterId]
if (logsOnly || filterType === 'filter') {
return this.getLogsFor(params || {topics: []})
}
if (filterType === 'block') {
let blocks = this.oldLogs.filter(x => x.type === 'block').filter(x => tracking.block === undefined || x.blockNumber >= tracking.block)
tracking.block = blocks[blocks.length - 1]
return blocks.map(block => ('0x' + block.hash().toString('hex')))
}
if (filterType === 'pendingTransactions') {
return []
}
}
getLogsFor (params) {
let results = []
for (let log of this.oldLogs) {

@ -43,7 +43,7 @@ module.exports = {
* @param {Function} finalCallback - last callback.
*/
callFunction: function (from, to, data, value, gasLimit, funAbi, txRunner, callbacks, finalCallback) {
var tx = { from: from, to: to, data: data, useCall: false, value: value, gasLimit: gasLimit }
var tx = { from: from, to: to, data: data, useCall: funAbi.constant, value: value, gasLimit: gasLimit }
txRunner.rawRun(tx, callbacks.confirmationCb, callbacks.gasEstimationForceSend, callbacks.promptCb, (error, txResult) => {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
finalCallback(error, txResult)

@ -29,6 +29,7 @@ function web3VmProvider () {
this.providers = { 'HttpProvider': function (url) {} }
this.currentProvider = {'host': 'vm provider'}
this.storageCache = {}
this.lastProcessedStorageTxHash = {}
this.sha3Preimages = {}
// util
this.sha3 = function () { return self.web3.sha3.apply(self.web3, arguments) }
@ -92,6 +93,7 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
const account = ethutil.toBuffer(tx.to)
self.vm.stateManager.dumpStorage(account, function (storage) {
self.storageCache[self.processingHash][tx.to] = storage
self.lastProcessedStorageTxHash[tx.to] = self.processingHash
})
}
this.processingIndex = 0
@ -171,12 +173,14 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
if (step.op === 'CREATE') {
this.processingAddress = traceHelper.contractCreationToken(this.processingIndex)
this.storageCache[this.processingHash][this.processingAddress] = {}
this.lastProcessedStorageTxHash[this.processingAddress] = this.processingHash
} else {
this.processingAddress = uiutil.normalizeHexAddress(step.stack[step.stack.length - 2])
if (!self.storageCache[self.processingHash][this.processingAddress]) {
const account = ethutil.toBuffer(this.processingAddress)
self.vm.stateManager.dumpStorage(account, function (storage) {
self.storageCache[self.processingHash][self.processingAddress] = storage
self.lastProcessedStorageTxHash[self.processingAddress] = self.processingHash
})
}
}
@ -217,6 +221,11 @@ web3VmProvider.prototype.traceTransaction = function (txHash, options, cb) {
web3VmProvider.prototype.storageRangeAt = function (blockNumber, txIndex, address, start, maxLength, cb) { // txIndex is the hash in the case of the VM
// we don't use the range params here
if (txIndex === 'latest') {
txIndex = this.lastProcessedStorageTxHash[address]
}
if (this.storageCache[txIndex] && this.storageCache[txIndex][address]) {
var storage = this.storageCache[txIndex][address]
return cb(null, {

@ -16,7 +16,7 @@ Implemented:
* [~] eth_accounts
* [X] eth_blockNumber
* [X] eth_getBalance
* [_] eth_getStorageAt
* [~] eth_getStorageAt
* [X] eth_getTransactionCount
* [X] eth_getBlockTransactionCountByHash
* [X] eth_getBlockTransactionCountByNumber
@ -40,12 +40,12 @@ Implemented:
* [X] eth_compileSolidity (DEPRECATED)
* [X] eth_compileLLL (DEPRECATED)
* [X] eth_compileSerpent (DEPRECATED)
* [_] eth_newFilter
* [_] eth_newBlockFilter
* [_] eth_newPendingTransactionFilter
* [_] eth_uninstallFilter
* [_] eth_getFilterChanges
* [_] eth_getFilterLogs
* [X] eth_newFilter
* [X] eth_newBlockFilter
* [X] eth_newPendingTransactionFilter
* [X] eth_uninstallFilter
* [~] eth_getFilterChanges
* [~] eth_getFilterLogs
* [X] eth_getLogs
* [_] eth_getWork
* [_] eth_submitWork
@ -55,18 +55,6 @@ Implemented:
* [_] db_getString
* [_] db_putHex
* [_] db_getHex
* [X] shh_version
* [_] shh_post
* [_] shh_newIdentity
* [_] shh_hasIdentity
* [_] shh_newGroup
* [_] shh_addToGroup
* [_] shh_newFilter
* [_] shh_uninstallFilter
* [_] shh_getFilterChanges
* [_] shh_getMessages
* [_] bzz_hive (stub)
* [_] bzz_info (stub)
* [_] debug_traceTransaction
* [X] eth_subscribe
* [X] eth_unsubscribe
@ -79,5 +67,3 @@ Implemented:
* [_] personal_unlockAccount
* [_] personal_sendTransaction
* [_] rpc_modules
* [_] web3_clientVersion
* [_] web3_sha3

@ -24,12 +24,14 @@ program
.option('-b, --ip [host]', 'specify host')
.option('-c, --coinbase [coinbase]', 'specify host')
.option('--rpc', 'run rpc server only')
.option('--details', 'display payloads for every requests and their responses')
.parse(process.argv)
const Server = require('../src/server')
const server = new Server({
coinbase: program.coinbase || "0x0000000000000000000000000000000000000000",
rpc: program.rpc
rpc: program.rpc,
logDetails: program.details
})
server.start(program.host || '127.0.0.1', program.port || 8545)

@ -29,7 +29,7 @@
"remix-lib": "0.4.14",
"standard": "^10.0.3",
"time-stamp": "^2.0.0",
"web3": "^1.0.0-beta.37"
"web3": "1.0.0-beta.37"
},
"devDependencies": {
"@babel/core": "^7.4.5",

@ -20,7 +20,7 @@ Accounts.prototype.init = async function () {
this.accountsKeys[ethJSUtil.toChecksumAddress(account.address)] = account.privateKey
this.accounts[ethJSUtil.toChecksumAddress(account.address)] = { privateKey: Buffer.from(account.privateKey.replace('0x', ''), 'hex'), nonce: 0 }
executionContext.vm().stateManager.getAccount(Buffer.from(account.address.toLowerCase().replace('0x', ''), 'hex'), (err, account) => {
executionContext.vm().stateManager.getAccount(Buffer.from(account.address.replace('0x', ''), 'hex'), (err, account) => {
if (err) {
throw new Error(err)
}
@ -61,13 +61,16 @@ Accounts.prototype.eth_getBalance = function (payload, cb) {
}
Accounts.prototype.eth_sign = function (payload, cb) {
let address = payload.params[0]
let message = payload.params[1]
const address = payload.params[0]
const message = payload.params[1]
let privateKey = this.accountsKeys[address]
let account = Web3.eth.accounts.privateKeyToAccount(privateKey)
const privateKey = this.accountsKeys[ethJSUtil.toChecksumAddress(address)]
if (!privateKey) {
return cb(new Error('unknown account'))
}
const account = this.web3.eth.accounts.privateKeyToAccount(privateKey)
let data = account.sign(message)
const data = account.sign(message)
cb(null, data.signature)
}

@ -17,12 +17,18 @@ Blocks.prototype.methods = function () {
eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this),
eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this),
eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this),
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this)
eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this),
eth_getStorageAt: this.eth_getStorageAt.bind(this)
}
}
Blocks.prototype.eth_getBlockByNumber = function (payload, cb) {
var block = executionContext.blocks[payload.params[0]]
let blockIndex = payload.params[0]
if (blockIndex === 'latest') {
blockIndex = executionContext.latestBlockNumber
}
const block = executionContext.blocks[blockIndex]
if (!block) {
return cb(new Error('block not found'))
@ -117,4 +123,17 @@ Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) {
cb(null, 0)
}
Blocks.prototype.eth_getStorageAt = function (payload, cb) {
const [address, position, blockNumber] = payload.params
executionContext.web3().debug.storageRangeAt(blockNumber, 'latest', address.toLowerCase(), position, 1, (err, result) => {
if (err || (result.storage && Object.values(result.storage).length === 0)) {
return cb(err, '')
}
let value = Object.values(result.storage)[0].value
cb(err, value)
})
}
module.exports = Blocks

@ -13,7 +13,6 @@ Filters.prototype.methods = function () {
}
}
// https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs
Filters.prototype.eth_getLogs = function (payload, cb) {
let results = executionContext.logsManager.getLogsFor(payload.params[0])
cb(null, results)
@ -29,4 +28,36 @@ Filters.prototype.eth_unsubscribe = function (payload, cb) {
cb(null, true)
}
Filters.prototype.eth_newFilter = function (payload, cb) {
const filterId = executionContext.logsManager.newFilter('filter', payload.params[0])
cb(null, filterId)
}
Filters.prototype.eth_newBlockFilter = function (payload, cb) {
const filterId = executionContext.logsManager.newFilter('block')
cb(null, filterId)
}
Filters.prototype.eth_newPendingTransactionFilter = function (payload, cb) {
const filterId = executionContext.logsManager.newFilter('pendingTransactions')
cb(null, filterId)
}
Filters.prototype.eth_uninstallfilter = function (payload, cb) {
const result = executionContext.logsManager.uninstallFilter(payload.params[0])
cb(null, result)
}
Filters.prototype.eth_getFilterChanges = function (payload, cb) {
const filterId = payload.params[0]
let results = executionContext.logsManager.getLogsForFilter(filterId)
cb(null, results)
}
Filters.prototype.eth_getFilterLogs = function (payload, cb) {
const filterId = payload.params[0]
let results = executionContext.logsManager.getLogsForFilter(filterId, true)
cb(null, results)
}
module.exports = Filters

@ -53,6 +53,10 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) {
'status': receipt.status
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}
@ -78,6 +82,12 @@ Transactions.prototype.eth_call = function (payload, cb) {
if (payload.params && payload.params.length > 0 && payload.params[0].from) {
payload.params[0].from = ethJSUtil.toChecksumAddress(payload.params[0].from)
}
if (payload.params && payload.params.length > 0 && payload.params[0].to) {
payload.params[0].to = ethJSUtil.toChecksumAddress(payload.params[0].to)
}
payload.params[0].value = undefined
processTx(this.accounts, payload, true, cb)
}
@ -130,6 +140,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) {
r.value = '0x0'
}
if (r.blockNumber === '0x') {
r.blockNumber = '0x0'
}
cb(null, r)
})
}

@ -16,7 +16,7 @@ function runCall (payload, from, to, data, value, gasLimit, txRunner, callbacks,
return callback(null, toReturn)
}
TxExecution.callFunction(from, to, data, value, gasLimit, null, txRunner, callbacks, finalCallback, true)
TxExecution.callFunction(from, to, data, value, gasLimit, {constant: true}, txRunner, callbacks, finalCallback, true)
}
function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, callback) {
@ -27,7 +27,7 @@ function runTx (payload, from, to, data, value, gasLimit, txRunner, callbacks, c
callback(null, result.transactionHash)
}
TxExecution.callFunction(from, to, data, value, gasLimit, null, txRunner, callbacks, finalCallback, false)
TxExecution.callFunction(from, to, data, value, gasLimit, {constant: false}, txRunner, callbacks, finalCallback, false)
}
function createContract (payload, from, data, value, gasLimit, txRunner, callbacks, callback) {

@ -1,15 +0,0 @@
var Whisper = function () {
}
Whisper.prototype.methods = function () {
return {
shh_version: this.shh_version.bind(this)
}
}
Whisper.prototype.shh_version = function (payload, cb) {
cb(null, 5)
}
module.exports = Whisper

@ -10,11 +10,11 @@ const Filters = require('./methods/filters.js')
const Misc = require('./methods/misc.js')
const Net = require('./methods/net.js')
const Transactions = require('./methods/transactions.js')
const Whisper = require('./methods/whisper.js')
const generateBlock = require('./genesis.js')
var Provider = function (options) {
this.options = options || {}
this.Accounts = new Accounts()
this.Transactions = new Transactions()
@ -24,10 +24,10 @@ var Provider = function (options) {
this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, (new Filters()).methods())
this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, (this.Transactions.methods()))
this.methods = merge(this.methods, (new Whisper()).methods())
this.methods = merge(this.methods, this.Transactions.methods())
generateBlock()
this.init()
}
Provider.prototype.init = async function () {
@ -39,8 +39,15 @@ Provider.prototype.sendAsync = function (payload, callback) {
log.info('payload method is ', payload.method)
let method = this.methods[payload.method]
if (this.options.logDetails) {
log.info(payload)
}
if (method) {
return method.call(method, payload, (err, result) => {
if (this.options.logDetails) {
log.info(err)
log.info(result)
}
if (err) {
return callback(err)
}

@ -54,7 +54,12 @@ class Server {
})
}
app.listen(port, host, () => log('Remix Simulator listening on port ' + host + ':' + port))
app.listen(port, host, () => {
log('Remix Simulator listening on ws://' + host + ':' + port)
if (!this.rpcOnly) {
log('http json-rpc is deprecated and disabled by default. To enable it use --rpc')
}
})
}
}

@ -10,8 +10,32 @@ describe('Accounts', function () {
web3.setProvider(provider)
})
it('should get a list of accounts', async function () {
let accounts = await web3.eth.getAccounts()
assert.notEqual(accounts.length, 0)
describe('eth_getAccounts', () => {
it('should get a list of accounts', async function () {
let accounts = await web3.eth.getAccounts()
assert.notEqual(accounts.length, 0)
})
})
describe('eth_getBalance', () => {
it('should get a account balance', async function () {
let accounts = await web3.eth.getAccounts()
let balance0 = await web3.eth.getBalance(accounts[0])
let balance1 = await web3.eth.getBalance(accounts[1])
let balance2 = await web3.eth.getBalance(accounts[2])
assert.deepEqual(balance0, '100000000000000000000')
assert.deepEqual(balance1, '100000000000000000000')
assert.deepEqual(balance2, '100000000000000000000')
})
})
describe('eth_sign', () => {
it('should sign payloads', async function () {
let accounts = await web3.eth.getAccounts()
let signature = await web3.eth.sign('Hello world', accounts[0])
assert.deepEqual(signature.length, 132)
})
})
})

@ -12,40 +12,310 @@ describe('blocks', function () {
web3.setProvider(provider)
})
it('should get block given its number', async function () {
let block = await web3.eth.getBlock(0)
let expectedBlock = {
difficulty: '69762765929000',
extraData: '0x0',
gasLimit: 8000000,
gasUsed: 0,
hash: block.hash.toString('hex'),
logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
miner: '0x0000000000000000000000000000000000000001',
nonce: '0x0000000000000000',
number: 0,
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 163591,
stateRoot: '0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68',
timestamp: block.timestamp,
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)
})
it('should get coinbase', async function () {
let coinbase = await web3.eth.getCoinbase()
assert.equal(coinbase, '0x0000000000000000000000000000000000000001')
describe('eth_getBlockByNumber', () => {
it('should get block given its number', async function () {
let block = await web3.eth.getBlock(0)
let expectedBlock = {
difficulty: '69762765929000',
extraData: '0x0',
gasLimit: 8000000,
gasUsed: 0,
hash: block.hash.toString('hex'),
logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331',
miner: '0x0000000000000000000000000000000000000001',
nonce: '0x0000000000000000',
number: 0,
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000',
sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
size: 163591,
stateRoot: '0x63e1738ea12d4e7d12b71f0f4604706417921eb6a62c407ca5f1d66b9e67f579',
timestamp: block.timestamp,
totalDifficulty: '0',
transactions: [],
transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
uncles: []
}
assert.deepEqual(block, expectedBlock)
})
})
describe('eth_getGasPrice', () => {
it('should get gas price', async function () {
let gasPrice = await web3.eth.getGasPrice()
assert.equal(gasPrice, 1)
})
})
describe('eth_coinbase', () => {
it('should get coinbase', async function () {
let coinbase = await web3.eth.getCoinbase()
assert.equal(coinbase, '0x0000000000000000000000000000000000000001')
})
})
describe('eth_blockNumber', () => {
it('should get current block number', async function () {
let number = await web3.eth.getBlockNumber()
assert.equal(number, 0)
})
})
describe('eth_getBlockByHash', () => {
it('should get block given its hash', async function () {
let correctBlock = await web3.eth.getBlock(0)
let block = await web3.eth.getBlock(correctBlock.hash)
assert.deepEqual(block, correctBlock)
})
})
describe('eth_getBlockTransactionCountByHash', () => {
it('should get block given its hash', async function () {
let correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await web3.eth.getBlockTransactionCount(correctBlock.hash)
assert.deepEqual(numberTransactions, 0)
})
})
describe('eth_getBlockTransactionCountByNumber', () => {
it('should get block given its hash', async function () {
let numberTransactions = await web3.eth.getBlockTransactionCount(0)
assert.deepEqual(numberTransactions, 0)
})
})
describe('eth_getUncleCountByBlockHash', () => {
it('should get block given its hash', async function () {
let correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await (new Promise((resolve, reject) => {
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => {
if (err) return reject(err)
resolve(numberTransactions)
})
}))
assert.deepEqual(numberTransactions, correctBlock.uncles.length)
})
})
describe('eth_getUncleCountByBlockNumber', () => {
it('should get block given its number', async function () {
let correctBlock = await web3.eth.getBlock(0)
let numberTransactions = await (new Promise((resolve, reject) => {
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => {
if (err) return reject(err)
resolve(numberTransactions)
})
}))
assert.deepEqual(numberTransactions, correctBlock.uncles.length)
})
})
describe('eth_getStorageAt', () => {
it('should get storage at position at given address', async function () {
let abi = [
{
'constant': false,
'inputs': [
{
'name': 'x',
'type': 'uint256'
}
],
'name': 'set',
'outputs': [],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'function'
},
{
'constant': false,
'inputs': [
{
'name': 'x',
'type': 'uint256'
}
],
'name': 'set2',
'outputs': [],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'function'
},
{
'inputs': [
{
'name': 'initialValue',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'constructor'
},
{
'anonymous': false,
'inputs': [
{
'indexed': true,
'name': 'value',
'type': 'uint256'
}
],
'name': 'Test',
'type': 'event'
},
{
'constant': true,
'inputs': [],
'name': 'get',
'outputs': [
{
'name': 'retVal',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
},
{
'constant': true,
'inputs': [],
'name': 'storedData',
'outputs': [
{
'name': '',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
}
]
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts()
const contractInstance = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 })
contractInstance.currentProvider = web3.eth.currentProvider
contractInstance.givenProvider = web3.eth.currentProvider
await contractInstance.methods.set(100).send({ from: accounts[0].toLowerCase(), gas: 400000 })
let storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert.deepEqual(storage, '0x64')
await contractInstance.methods.set(200).send({ from: accounts[0], gas: 400000 })
storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert.deepEqual(storage, '0x64')
await contractInstance.methods.set(200).send({ from: accounts[0], gas: 400000 })
storage = await web3.eth.getStorageAt(contractInstance.options.address, 0)
assert.deepEqual(storage, '0xc8')
})
})
describe('eth_call', () => {
it('should get a value', async function () {
let abi = [
{
'constant': false,
'inputs': [
{
'name': 'x',
'type': 'uint256'
}
],
'name': 'set',
'outputs': [],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'function'
},
{
'constant': false,
'inputs': [
{
'name': 'x',
'type': 'uint256'
}
],
'name': 'set2',
'outputs': [],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'function'
},
{
'inputs': [
{
'name': 'initialValue',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'nonpayable',
'type': 'constructor'
},
{
'anonymous': false,
'inputs': [
{
'indexed': true,
'name': 'value',
'type': 'uint256'
}
],
'name': 'Test',
'type': 'event'
},
{
'constant': true,
'inputs': [],
'name': 'get',
'outputs': [
{
'name': 'retVal',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
},
{
'constant': true,
'inputs': [],
'name': 'storedData',
'outputs': [
{
'name': '',
'type': 'uint256'
}
],
'payable': false,
'stateMutability': 'view',
'type': 'function'
}
]
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029'
const contract = new web3.eth.Contract(abi)
const accounts = await web3.eth.getAccounts()
const contractInstance = await contract.deploy({ data: code, arguments: [100] }).send({ from: accounts[0], gas: 400000 })
contractInstance.currentProvider = web3.eth.currentProvider
contractInstance.givenProvider = web3.eth.currentProvider
let value = await contractInstance.methods.get().call({ from: accounts[0] })
assert.deepEqual(value, 100)
})
})
})

@ -10,47 +10,103 @@ describe('Misc', function () {
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()
describe('web3_clientVersion', () => {
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')
describe('eth_protocolVersion', () => {
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)
describe('eth_syncing', () => {
it('should get if is syncing', async function () {
let isSyncing = await web3.eth.isSyncing()
assert.equal(isSyncing, false)
})
})
describe('eth_mining', () => {
it('should get if is mining', async function () {
let isMining = await web3.eth.isMining()
assert.equal(isMining, false)
})
})
it('should get if is mining', async function () {
let isMining = await web3.eth.isMining()
assert.equal(isMining, false)
describe('eth_hashrate', () => {
it('should get hashrate', async function () {
let hashrate = await web3.eth.getHashrate()
assert.equal(hashrate, 0)
})
})
describe('web3_sha3', () => {
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')
})
})
})
it('should get hashrate', async function () {
let hashrate = await web3.eth.getHashrate()
assert.equal(hashrate, 0)
describe('eth_getCompilers', () => {
it('should get list of compilers', async function () {
web3._requestManager.send({ method: 'eth_getCompilers', params: [] }, (err, result) => {
if (err) {
throw new Error(err)
}
assert.equal(result, 0)
})
})
})
describe('eth_compileSolidity', () => {
it('get unsupported result when requesting solidity compiler', async function () {
web3._requestManager.send({ method: 'eth_compileSolidity', params: [] }, (err, result) => {
if (err) {
throw new Error(err)
}
assert.equal(result, 'unsupported')
})
})
})
describe('eth_compileLLL', () => {
it('get unsupported result when requesting LLL compiler', async function () {
web3._requestManager.send({ method: 'eth_compileLLL', params: [] }, (err, result) => {
if (err) {
throw new Error(err)
}
assert.equal(result, 'unsupported')
})
})
})
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')
describe('eth_compileSerpent', () => {
it('get unsupported result when requesting serpent compiler', async function () {
web3._requestManager.send({ method: 'eth_compileSerpent', params: [] }, (err, result) => {
if (err) {
throw new Error(err)
}
assert.equal(result, 'unsupported')
})
})
})
})

@ -1,17 +0,0 @@
/* 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)
})
})
Loading…
Cancel
Save