Tx controller now uses safe event emitter (#5769)

* transactions - use safe-event-emitter over events

* tests - pass a platform object on init with a noop showTransactionNotification

* test - fix for tx-state-history-helper trying to reduce an empty array

* deps - safe-event-emitter

* lint
feature/default_network_editable
Frankie 6 years ago committed by Dan Finlay
parent af873129bb
commit ce147bf6d8
  1. 2
      app/scripts/controllers/transactions/index.js
  2. 2
      app/scripts/controllers/transactions/pending-tx-tracker.js
  3. 2
      app/scripts/controllers/transactions/tx-state-manager.js
  4. 435
      package-lock.json
  5. 1
      package.json
  6. 1
      test/lib/mock-tx-gen.js
  7. 1
      test/unit/app/controllers/metamask-controller-test.js
  8. 2
      test/unit/app/controllers/transactions/pending-tx-test.js
  9. 48
      test/unit/app/controllers/transactions/tx-controller-test.js

@ -1,4 +1,4 @@
const EventEmitter = require('events')
const EventEmitter = require('safe-event-emitter')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const Transaction = require('ethereumjs-tx')

@ -1,4 +1,4 @@
const EventEmitter = require('events')
const EventEmitter = require('safe-event-emitter')
const log = require('loglevel')
const EthQuery = require('ethjs-query')

@ -1,5 +1,5 @@
const extend = require('xtend')
const EventEmitter = require('events')
const EventEmitter = require('safe-event-emitter')
const ObservableStore = require('obs-store')
const ethUtil = require('ethereumjs-util')
const log = require('loglevel')

435
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -212,6 +212,7 @@
"redux-thunk": "^2.2.0",
"request-promise": "^4.2.1",
"reselect": "^3.0.1",
"safe-event-emitter": "^1.0.1",
"sandwich-expando": "^1.1.3",
"semaphore": "^1.0.5",
"semver": "^5.4.1",

@ -2,6 +2,7 @@ const extend = require('xtend')
const BN = require('ethereumjs-util').BN
const template = {
'status': 'submitted',
'history': [{}],
'txParams': {
'from': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
'gas': '0x30d40',

@ -58,6 +58,7 @@ describe('MetaMaskController', function () {
},
},
initState: clone(firstTimeState),
platform: { showTransactionNotification: () => {} },
})
// disable diagnostics
metamaskController.diagnostics = null

@ -20,10 +20,12 @@ describe('PendingTransactionTracker', function () {
nonce: '0x1',
value: '0xfffff',
},
history: [{}],
rawTx: '0xf86c808504a817c800827b0d940c62bb85faa3311a998d3aba8098c1235c564966880de0b6b3a7640000802aa08ff665feb887a25d4099e40e11f0fef93ee9608f404bd3f853dd9e84ed3317a6a02ec9d3d1d6e176d4d2593dd760e74ccac753e6a0ea0d00cc9789d0d7ff1f471d',
}
txMetaNoHash = {
id: 2,
history: [{}],
status: 'submitted',
txParams: { from: '0x1678a085c290ebd122dc42cba69373b5953b831d'},
}

@ -52,9 +52,9 @@ describe('Transaction Controller', function () {
describe('#getUnapprovedTxCount', function () {
it('should return the number of unapproved txs', function () {
txController.txStateManager._saveTxList([
{ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
])
const unapprovedTxCount = txController.getUnapprovedTxCount()
assert.equal(unapprovedTxCount, 3, 'should be 3')
@ -64,9 +64,9 @@ describe('Transaction Controller', function () {
describe('#getPendingTxCount', function () {
it('should return the number of pending txs', function () {
txController.txStateManager._saveTxList([
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [] },
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 2, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 3, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
])
const pendingTxCount = txController.getPendingTxCount()
assert.equal(pendingTxCount, 3, 'should be 3')
@ -82,15 +82,15 @@ describe('Transaction Controller', function () {
'to': '0xc684832530fcbddae4b4230a47e991ddcec2831d',
}
txController.txStateManager._saveTxList([
{id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{id: 0, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 1, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 2, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 4, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 5, status: 'approved', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 6, status: 'signed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 7, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
{id: 8, status: 'failed', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
])
})
@ -112,7 +112,7 @@ describe('Transaction Controller', function () {
id: 1,
metamaskNetworkId: currentNetworkId,
txParams,
history: [],
history: [{}],
}
txController.txStateManager._saveTxList([txMeta])
stub = sinon.stub(txController, 'addUnapprovedTransaction').callsFake(() => {
@ -232,7 +232,7 @@ describe('Transaction Controller', function () {
from: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
to: '0xc684832530fcbddae4b4230a47e991ddcec2831d',
},
history: [],
history: [{}],
}
providerResultStub.eth_gasPrice = '4a817c800'
providerResultStub.eth_getBlockByNumber = { gasLimit: '47b784' }
@ -423,7 +423,7 @@ describe('Transaction Controller', function () {
data: '0x0',
}
txController.txStateManager._saveTxList([
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [] },
{ id: 1, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams, history: [{}] },
])
txController.retryTransaction(1)
.then((txMeta) => {
@ -462,12 +462,12 @@ describe('Transaction Controller', function () {
beforeEach(function () {
txController.txStateManager._saveTxList([
{ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 2, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {} },
{ id: 2, status: 'rejected', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 3, status: 'approved', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 4, status: 'signed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 5, status: 'submitted', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 6, status: 'confirmed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
{ id: 7, status: 'failed', metamaskNetworkId: currentNetworkId, txParams: {}, history: [{}] },
])
})
it('should show only submitted and approved transactions as pending transasction', function () {

Loading…
Cancel
Save