test - createTestProviderTools includes block tracker layer

feature/default_network_editable
kumavis 7 years ago
parent d7c8ec22a4
commit 899e839e7c
  1. 1
      package.json
  2. 14
      test/stub/provider.js
  3. 4
      test/unit/pending-tx-test.js
  4. 24
      test/unit/tx-controller-test.js
  5. 4
      test/unit/tx-gas-util-test.js

@ -70,7 +70,6 @@
"ensnare": "^1.0.0",
"eslint-plugin-react": "^7.4.0",
"eth-bin-to-ops": "^1.0.1",
"eth-block-tracker": "^2.2.0",
"eth-contract-metadata": "^1.1.4",
"eth-json-rpc-filters": "^1.2.5",
"eth-json-rpc-infura": "^2.0.5",

@ -1,11 +1,12 @@
const JsonRpcEngine = require('json-rpc-engine')
const scaffoldMiddleware = require('eth-json-rpc-middleware/scaffold')
const TestBlockchain = require('eth-block-tracker/test/util/testBlockMiddleware')
module.exports = {
createEngineForTestData,
providerFromEngine,
scaffoldMiddleware,
createStubbedProvider,
createTestProviderTools,
}
@ -18,8 +19,13 @@ function providerFromEngine (engine) {
return provider
}
function createStubbedProvider (resultStub) {
function createTestProviderTools (opts = {}) {
const engine = createEngineForTestData()
engine.push(scaffoldMiddleware(resultStub))
return providerFromEngine(engine)
const testBlockchain = new TestBlockchain()
// handle provided hooks
engine.push(scaffoldMiddleware(opts.scaffold || {}))
// handle block tracker methods
engine.push(testBlockchain.createMiddleware())
const provider = providerFromEngine(engine)
return { provider, engine, testBlockchain }
}

@ -3,7 +3,7 @@ const ethUtil = require('ethereumjs-util')
const EthTx = require('ethereumjs-tx')
const ObservableStore = require('obs-store')
const clone = require('clone')
const { createStubbedProvider } = require('../stub/provider')
const { createTestProviderTools } = require('../stub/provider')
const PendingTransactionTracker = require('../../app/scripts/lib/pending-tx-tracker')
const MockTxGen = require('../lib/mock-tx-gen')
const sinon = require('sinon')
@ -39,7 +39,7 @@ describe('PendingTransactionTracker', function () {
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
}
providerResultStub = {}
provider = createStubbedProvider(providerResultStub)
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
pendingTxTracker = new PendingTransactionTracker({
provider,

@ -6,7 +6,7 @@ const ObservableStore = require('obs-store')
const sinon = require('sinon')
const TransactionController = require('../../app/scripts/controllers/transactions')
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
const { createStubbedProvider } = require('../stub/provider')
const { createTestProviderTools } = require('../stub/provider')
const noop = () => true
const currentNetworkId = 42
@ -15,11 +15,18 @@ const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f3
describe('Transaction Controller', function () {
let txController, provider, providerResultStub
let txController, provider, providerResultStub, testBlockchain
beforeEach(function () {
providerResultStub = {}
provider = createStubbedProvider(providerResultStub)
providerResultStub = {
// 1 gwei
eth_gasPrice: '0x0de0b6b3a7640000',
// by default, all accounts are external accounts (not contracts)
eth_getCode: '0x',
}
const providerTools = createTestProviderTools({ scaffold: providerResultStub })
provider = providerTools.provider
testBlockchain = providerTools.testBlockchain
txController = new TransactionController({
provider,
@ -153,15 +160,6 @@ describe('Transaction Controller', function () {
})
describe('#addUnapprovedTransaction', function () {
let addTxDefaults
beforeEach(() => {
addTxDefaults = txController.addTxDefaults
txController.addTxDefaults = function addTxDefaultsStub () { return Promise.resolve() }
})
afterEach(() => {
txController.addTxDefaults = addTxDefaults
})
it('should add an unapproved transaction and return a valid txMeta', function (done) {
txController.addUnapprovedTransaction({})

@ -1,12 +1,12 @@
const assert = require('assert')
const TxGasUtils = require('../../app/scripts/lib/tx-gas-utils')
const { createStubbedProvider } = require('../stub/provider')
const { createTestProviderTools } = require('../stub/provider')
describe('Tx Gas Util', function () {
let txGasUtil, provider, providerResultStub
beforeEach(function () {
providerResultStub = {}
provider = createStubbedProvider(providerResultStub)
provider = createTestProviderTools({ scaffold: providerResultStub }).provider
txGasUtil = new TxGasUtils({
provider,
})

Loading…
Cancel
Save