aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-01-18 13:43:34 +0800
committerkumavis <aaron@kumavis.me>2018-01-18 13:43:34 +0800
commit899e839e7c695ff55572d3eb35a9fee98eff8ca1 (patch)
tree4d472d21996a8e858b04184b3288a91a3e28dc2a /test
parentd7c8ec22a45a704036c4969496ef293c524f4542 (diff)
downloadtangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar.gz
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar.bz2
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar.lz
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar.xz
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.tar.zst
tangerine-wallet-browser-899e839e7c695ff55572d3eb35a9fee98eff8ca1.zip
test - createTestProviderTools includes block tracker layer
Diffstat (limited to 'test')
-rw-r--r--test/stub/provider.js14
-rw-r--r--test/unit/pending-tx-test.js4
-rw-r--r--test/unit/tx-controller-test.js24
-rw-r--r--test/unit/tx-gas-util-test.js4
4 files changed, 25 insertions, 21 deletions
diff --git a/test/stub/provider.js b/test/stub/provider.js
index e1e6ffce6..e77db4e28 100644
--- a/test/stub/provider.js
+++ b/test/stub/provider.js
@@ -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 }
}
diff --git a/test/unit/pending-tx-test.js b/test/unit/pending-tx-test.js
index de2da6e36..cb29ddafd 100644
--- a/test/unit/pending-tx-test.js
+++ b/test/unit/pending-tx-test.js
@@ -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,
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index 84094e00a..cc99afee4 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -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({})
diff --git a/test/unit/tx-gas-util-test.js b/test/unit/tx-gas-util-test.js
index 0e4393113..d9a12d1c3 100644
--- a/test/unit/tx-gas-util-test.js
+++ b/test/unit/tx-gas-util-test.js
@@ -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,
})