test - unit - tx-controller-test - add history object to txMeta when using internal calls

feature/default_network_editable
kumavis 7 years ago
parent 630e2300f4
commit afdefc58e9
  1. 60
      test/unit/app/controllers/transactions/tx-controller-test.js

@ -53,9 +53,9 @@ describe('Transaction Controller', function () {
describe('#getUnapprovedTxCount', function () { describe('#getUnapprovedTxCount', function () {
it('should return the number of unapproved txs', function () { it('should return the number of unapproved txs', function () {
txController.txStateManager._saveTxList([ txController.txStateManager._saveTxList([
{ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
]) ])
const unapprovedTxCount = txController.getUnapprovedTxCount() const unapprovedTxCount = txController.getUnapprovedTxCount()
assert.equal(unapprovedTxCount, 3, 'should be 3') assert.equal(unapprovedTxCount, 3, 'should be 3')
@ -65,9 +65,9 @@ describe('Transaction Controller', function () {
describe('#getPendingTxCount', function () { describe('#getPendingTxCount', function () {
it('should return the number of pending txs', function () { it('should return the number of pending txs', function () {
txController.txStateManager._saveTxList([ txController.txStateManager._saveTxList([
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} }, { id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
]) ])
const pendingTxCount = txController.getPendingTxCount() const pendingTxCount = txController.getPendingTxCount()
assert.equal(pendingTxCount, 3, 'should be 3') assert.equal(pendingTxCount, 3, 'should be 3')
@ -83,15 +83,15 @@ describe('Transaction Controller', function () {
'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d', 'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d',
} }
txController.txStateManager._saveTxList([ txController.txStateManager._saveTxList([
{id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams}, {id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams}, {id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams}, {id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams}, {id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams}, {id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams}, {id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams}, {id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams}, {id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams}, {id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
]) ])
}) })
@ -188,24 +188,22 @@ describe('Transaction Controller', function () {
}) })
describe('#addTxGasDefaults', function () { describe('#addTxGasDefaults', function () {
it('should add the tx defaults if their are none', function (done) { it('should add the tx defaults if their are none', async () => {
const txMeta = { const txMeta = {
'txParams': { txParams: {
'from': '0xc684832530fcbddae4b4230a47e991ddcec2831d', from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d', to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
}, },
history: [],
} }
providerResultStub.eth_gasPrice = '4a817c800' providerResultStub.eth_gasPrice = '4a817c800'
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' } providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' }
providerResultStub.eth_estimateGas = '5209' providerResultStub.eth_estimateGas = '5209'
txController.addTxGasDefaults(txMeta)
.then((txMetaWithDefaults) => { const txMetaWithDefaults = await txController.addTxGasDefaults(txMeta)
assert(txMetaWithDefaults.txParams.value, '0x0', 'should have added 0x0 as the value') assert(txMetaWithDefaults.txParams.value, '0x0', 'should have added 0x0 as the value')
assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price') assert(txMetaWithDefaults.txParams.gasPrice, 'should have added the gas price')
assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field') assert(txMetaWithDefaults.txParams.gas, 'should have added the gas field')
done()
})
.catch(done)
}) })
}) })
@ -378,7 +376,7 @@ describe('Transaction Controller', function () {
data: '0x0', data: '0x0',
} }
txController.txStateManager._saveTxList([ txController.txStateManager._saveTxList([
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams }, { id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
]) ])
txController.retryTransaction(1) txController.retryTransaction(1)
.then((txMeta) => { .then((txMeta) => {

Loading…
Cancel
Save