|
|
|
@ -1,22 +1,22 @@ |
|
|
|
|
/* global describe, before, it */ |
|
|
|
|
var Web3 = require('web3') |
|
|
|
|
var RemixSim = require('../index.js') |
|
|
|
|
let web3 = new Web3() |
|
|
|
|
var assert = require('assert') |
|
|
|
|
const Web3 = require('web3') |
|
|
|
|
const RemixSim = require('../index.js') |
|
|
|
|
const web3 = new Web3() |
|
|
|
|
const assert = require('assert') |
|
|
|
|
|
|
|
|
|
describe('blocks', function () { |
|
|
|
|
before(function () { |
|
|
|
|
let provider = new RemixSim.Provider({ |
|
|
|
|
describe('blocks', () => { |
|
|
|
|
before(() => { |
|
|
|
|
const provider = new RemixSim.Provider({ |
|
|
|
|
coinbase: '0x0000000000000000000000000000000000000001' |
|
|
|
|
}) |
|
|
|
|
web3.setProvider(provider) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('eth_getBlockByNumber', () => { |
|
|
|
|
it('should get block given its number', async function () { |
|
|
|
|
let block = await web3.eth.getBlock(0) |
|
|
|
|
it('should get block given its number', async () => { |
|
|
|
|
const block = await web3.eth.getBlock(0) |
|
|
|
|
|
|
|
|
|
let expectedBlock = { |
|
|
|
|
const expectedBlock = { |
|
|
|
|
difficulty: '69762765929000', |
|
|
|
|
extraData: '0x0', |
|
|
|
|
gasLimit: 8000000, |
|
|
|
@ -42,56 +42,56 @@ describe('blocks', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('eth_getGasPrice', () => { |
|
|
|
|
it('should get gas price', async function () { |
|
|
|
|
let gasPrice = await web3.eth.getGasPrice() |
|
|
|
|
it('should get gas price', async () => { |
|
|
|
|
const gasPrice = await web3.eth.getGasPrice() |
|
|
|
|
assert.equal(gasPrice, 1) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('eth_coinbase', () => { |
|
|
|
|
it('should get coinbase', async function () { |
|
|
|
|
let coinbase = await web3.eth.getCoinbase() |
|
|
|
|
it('should get coinbase', async () => { |
|
|
|
|
const 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() |
|
|
|
|
it('should get current block number', async () => { |
|
|
|
|
const 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) |
|
|
|
|
it('should get block given its hash', async () => { |
|
|
|
|
const correctBlock = await web3.eth.getBlock(0) |
|
|
|
|
const 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) |
|
|
|
|
it('should get block given its hash', async () => { |
|
|
|
|
const correctBlock = await web3.eth.getBlock(0) |
|
|
|
|
const 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) |
|
|
|
|
it('should get block given its hash', async () => { |
|
|
|
|
const 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) => { |
|
|
|
|
it('should get block given its hash', async () => { |
|
|
|
|
const correctBlock = await web3.eth.getBlock(0) |
|
|
|
|
const numberTransactions = await (new Promise((resolve, reject) => { |
|
|
|
|
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [correctBlock.hash]}, (err, numberTransactions) => { |
|
|
|
|
if (err) return reject(err) |
|
|
|
|
resolve(numberTransactions) |
|
|
|
@ -102,9 +102,9 @@ describe('blocks', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
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) => { |
|
|
|
|
it('should get block given its number', async () => { |
|
|
|
|
const correctBlock = await web3.eth.getBlock(0) |
|
|
|
|
const numberTransactions = await (new Promise((resolve, reject) => { |
|
|
|
|
web3._requestManager.send({method: 'eth_getUncleCountByBlockHash', params: [0]}, (err, numberTransactions) => { |
|
|
|
|
if (err) return reject(err) |
|
|
|
|
resolve(numberTransactions) |
|
|
|
@ -115,8 +115,8 @@ describe('blocks', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('eth_getStorageAt', () => { |
|
|
|
|
it('should get storage at position at given address', async function () { |
|
|
|
|
let abi = [ |
|
|
|
|
it('should get storage at position at given address', async () => { |
|
|
|
|
const abi = [ |
|
|
|
|
{ |
|
|
|
|
'constant': false, |
|
|
|
|
'inputs': [ |
|
|
|
@ -198,7 +198,7 @@ describe('blocks', function () { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' |
|
|
|
|
const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' |
|
|
|
|
|
|
|
|
|
const contract = new web3.eth.Contract(abi) |
|
|
|
|
const accounts = await web3.eth.getAccounts() |
|
|
|
@ -222,8 +222,8 @@ describe('blocks', function () { |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
describe('eth_call', () => { |
|
|
|
|
it('should get a value', async function () { |
|
|
|
|
let abi = [ |
|
|
|
|
it('should get a value', async () => { |
|
|
|
|
const abi = [ |
|
|
|
|
{ |
|
|
|
|
'constant': false, |
|
|
|
|
'inputs': [ |
|
|
|
@ -305,7 +305,7 @@ describe('blocks', function () { |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
let code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' |
|
|
|
|
const code = '0x608060405234801561001057600080fd5b506040516020806102018339810180604052602081101561003057600080fd5b810190808051906020019092919050505080600081905550506101a9806100586000396000f3fe60806040526004361061005c576000357c0100000000000000000000000000000000000000000000000000000000900480632a1afcd91461006157806360fe47b11461008c5780636d4ce63c146100c7578063ce01e1ec146100f2575b600080fd5b34801561006d57600080fd5b5061007661012d565b6040518082815260200191505060405180910390f35b34801561009857600080fd5b506100c5600480360360208110156100af57600080fd5b8101908080359060200190929190505050610133565b005b3480156100d357600080fd5b506100dc61013d565b6040518082815260200191505060405180910390f35b3480156100fe57600080fd5b5061012b6004803603602081101561011557600080fd5b8101908080359060200190929190505050610146565b005b60005481565b8060008190555050565b60008054905090565b80600081905550807f63a242a632efe33c0e210e04e4173612a17efa4f16aa4890bc7e46caece80de060405160405180910390a25056fea165627a7a7230582063160eb16dc361092a85ced1a773eed0b63738b83bea1e1c51cf066fa90e135d0029' |
|
|
|
|
|
|
|
|
|
const contract = new web3.eth.Contract(abi) |
|
|
|
|
const accounts = await web3.eth.getAccounts() |
|
|
|
@ -314,7 +314,7 @@ describe('blocks', function () { |
|
|
|
|
contractInstance.currentProvider = web3.eth.currentProvider |
|
|
|
|
contractInstance.givenProvider = web3.eth.currentProvider |
|
|
|
|
|
|
|
|
|
let value = await contractInstance.methods.get().call({ from: accounts[0] }) |
|
|
|
|
const value = await contractInstance.methods.get().call({ from: accounts[0] }) |
|
|
|
|
assert.deepEqual(value, 100) |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|