From 7a30950e4dd31a2e4b1807bf3d1e2a09a25da323 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Sun, 14 Jan 2018 14:01:37 -0800 Subject: test - fix to match expected behavior --- test/unit/tx-controller-test.js | 42 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index aeefd5ec6..36f3e1c68 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -5,7 +5,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 { createStubedProvider } = require('../stub/provider') +const { createStubedProvider, createEthJsQueryStub } = require('../stub/provider') const noop = () => true const currentNetworkId = 42 @@ -30,6 +30,8 @@ describe('Transaction Controller', function () { resolve() }), }) + txController.query = createEthJsQueryStub(provider) + txController.txGasUtil.query = createEthJsQueryStub(provider) txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop }) txController.txProviderUtils = new TxGasUtils(txController.provider) }) @@ -110,23 +112,16 @@ describe('Transaction Controller', function () { history: [], } txController.txStateManager._saveTxList([txMeta]) - stub = sinon.stub(txController, 'addUnapprovedTransaction').returns(Promise.resolve(txController.txStateManager.addTx(txMeta))) + stub = sinon.stub(txController, 'addUnapprovedTransaction').callsFake(() => { + txController.emit('newUnapprovedTx', txMeta) + return Promise.resolve(txController.txStateManager.addTx(txMeta)) }) afterEach(function () { txController.txStateManager._saveTxList([]) stub.restore() }) - - it('should emit newUnapprovedTx event and pass txMeta as the first argument', function (done) { - txController.once('newUnapprovedTx', (txMetaFromEmit) => { - assert(txMetaFromEmit, 'txMeta is falsey') - assert.equal(txMetaFromEmit.id, 1, 'the right txMeta was passed') - done() - }) - txController.newUnapprovedTransaction(txParams) - .catch(done) - }) + }) it('should resolve when finished and status is submitted and resolve with the hash', function (done) { txController.once('newUnapprovedTx', (txMetaFromEmit) => { @@ -160,8 +155,17 @@ 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) { - const addTxDefaultsStub = sinon.stub(txController, 'addTxDefaults').callsFake(() => Promise.resolve()) txController.addUnapprovedTransaction({}) .then((txMeta) => { assert(('id' in txMeta), 'should have a id') @@ -172,10 +176,20 @@ describe('Transaction Controller', function () { const memTxMeta = txController.txStateManager.getTx(txMeta.id) assert.deepEqual(txMeta, memTxMeta, `txMeta should be stored in txController after adding it\n expected: ${txMeta} \n got: ${memTxMeta}`) - addTxDefaultsStub.restore() done() }).catch(done) }) + + it('should emit newUnapprovedTx event and pass txMeta as the first argument', function (done) { + providerResultStub.eth_gasPrice = '4a817c800' + txController.once('newUnapprovedTx', (txMetaFromEmit) => { + assert(txMetaFromEmit, 'txMeta is falsey') + done() + }) + txController.addUnapprovedTransaction({}) + .catch(done) + }) + }) describe('#addTxDefaults', function () { -- cgit v1.2.3