diff options
Adds createSpeedUpTransaction to txController
Diffstat (limited to 'test/unit/app/controllers/transactions/tx-controller-test.js')
-rw-r--r-- | test/unit/app/controllers/transactions/tx-controller-test.js | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js index 2fe4c47d1..6889f9bb2 100644 --- a/test/unit/app/controllers/transactions/tx-controller-test.js +++ b/test/unit/app/controllers/transactions/tx-controller-test.js @@ -5,6 +5,9 @@ const EthTx = require('ethereumjs-tx') const ObservableStore = require('obs-store') const sinon = require('sinon') const TransactionController = require('../../../../../app/scripts/controllers/transactions') +const { + TRANSACTION_TYPE_RETRY, +} = require('../../../../../app/scripts/controllers/transactions/enums') const { createTestProviderTools, getTestAccounts } = require('../../../../stub/provider') const noop = () => true @@ -392,6 +395,70 @@ describe('Transaction Controller', function () { }) + describe('#createSpeedUpTransaction', () => { + let addTxSpy + let approveTransactionSpy + let txParams + let expectedTxParams + + beforeEach(() => { + addTxSpy = sinon.spy(txController, 'addTx') + approveTransactionSpy = sinon.spy(txController, 'approveTransaction') + + txParams = { + nonce: '0x00', + from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4', + to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4', + gas: '0x5209', + gasPrice: '0xa', + } + txController.txStateManager._saveTxList([ + { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] }, + ]) + + expectedTxParams = Object.assign({}, txParams, { gasPrice: '0xb'}) + }) + + afterEach(() => { + addTxSpy.restore() + approveTransactionSpy.restore() + }) + + it('should call this.addTx and this.approveTransaction with the expected args', async () => { + await txController.createSpeedUpTransaction(1) + assert.equal(addTxSpy.callCount, 1) + + const addTxArgs = addTxSpy.getCall(0).args[0] + assert.deepEqual(addTxArgs.txParams, expectedTxParams) + + const { lastGasPrice, type } = addTxArgs + assert.deepEqual({ lastGasPrice, type }, { + lastGasPrice: '0xa', + type: TRANSACTION_TYPE_RETRY, + }) + }) + + it('should call this.approveTransaction with the id of the returned tx', async () => { + const result = await txController.createSpeedUpTransaction(1) + assert.equal(approveTransactionSpy.callCount, 1) + + const approveTransactionArg = approveTransactionSpy.getCall(0).args[0] + assert.equal(result.id, approveTransactionArg) + }) + + it('should return the expected txMeta', async () => { + const result = await txController.createSpeedUpTransaction(1) + + assert.deepEqual(result.txParams, expectedTxParams) + + const { lastGasPrice, type } = result + assert.deepEqual({ lastGasPrice, type }, { + lastGasPrice: '0xa', + type: TRANSACTION_TYPE_RETRY, + }) + }) + }) + describe('#publishTransaction', function () { let hash, txMeta beforeEach(function () { |