Skip to content

Commit

Permalink
add tests for failing when netId is loading
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiebee committed Dec 13, 2018
1 parent 6ad65f9 commit 7e4886b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class TransactionStateManager extends EventEmitter {
*/
generateTxMeta (opts) {
const netId = this.getNetwork()
if ( netId === 'loading' ) throw new Error('MetaMask is having trouble connecting to the network')
if (netId === 'loading') throw new Error('MetaMask is having trouble connecting to the network')
return extend({
id: createId(),
time: (new Date()).getTime(),
Expand Down
13 changes: 11 additions & 2 deletions test/unit/app/controllers/transactions/tx-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const { createTestProviderTools, getTestAccounts } = require('../../../../stub/p

const noop = () => true
const currentNetworkId = 42

const netStore = new ObservableStore(currentNetworkId)

describe('Transaction Controller', function () {
let txController, provider, providerResultStub, fromAccount
Expand All @@ -32,7 +32,7 @@ describe('Transaction Controller', function () {
txController = new TransactionController({
provider,
getGasPrice: function () { return '0xee6b2800' },
networkStore: new ObservableStore(currentNetworkId),
networkStore: netStore,
txHistoryLimit: 10,
blockTracker: blockTrackerStub,
signTransaction: (ethTx) => new Promise((resolve) => {
Expand Down Expand Up @@ -227,6 +227,15 @@ describe('Transaction Controller', function () {
txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
.catch(done)
})

it('should fail if netId is loading', function (done) {
txController.networkStore = new ObservableStore('loading')
txController.addUnapprovedTransaction({ from: selectedAddress, to: '0x0d1d4e623D10F9FBA5Db95830F7d3839406C6AF2' })
.catch((err) => {
if (err.message === 'MetaMask is having trouble connecting to the network') done()
else done(err)
})
})
})

describe('#addTxGasDefaults', function () {
Expand Down

0 comments on commit 7e4886b

Please sign in to comment.