Skip to content

Commit

Permalink
Add beginning of test
Browse files Browse the repository at this point in the history
  • Loading branch information
danfinlay committed Nov 14, 2018
1 parent d943345 commit f2514ad
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/unit/app/controllers/transactions/tx-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,50 @@ describe('Transaction Controller', function () {
assert.equal(params.gas, originalValue, 'gas unmodified')
assert.equal(params.gasPrice, originalValue, 'gas price unmodified')
assert.equal(result.hash, originalValue, `hash was set \n got: ${result.hash} \n expected: ${originalValue}`)
assert.equal(result.status, 'submitted' ,'Should have reached the submitted status.')
signStub.restore()
pubStub.restore()
done()
}).catch(done)
})

it('continues operating after a listener throws', async function () {
this.timeout(15000)
const wrongValue = '0x05'

txController.addTx(txMeta)
providerResultStub.eth_gasPrice = wrongValue
providerResultStub.eth_estimateGas = '0x5209'

const signStub = sinon.stub(txController, 'signTransaction').callsFake(() => Promise.resolve())
const setStatusStub = sinon.stub(txController.txStateManager, 'setTxStatusSubmitted').throws()
const setStatusStub2 = sinon.stub(txController.txStateManager, 'setTxStatusFailed').throws()

const pubStub = sinon.stub(txController, 'publishTransaction').callsFake(() => {
txController.setTxHash('1', originalValue)
txController.txStateManager.setTxStatusSubmitted('1')
})

try {
await txController.approveTransaction(txMeta.id)
} catch (e) {
assert.ok(e, 'stub throws deliberately')
}
const result = txController.txStateManager.getTx(txMeta.id)
const params = result.txParams

assert.equal(params.gas, originalValue, 'gas unmodified')
assert.equal(params.gasPrice, originalValue, 'gas price unmodified')
assert.equal(result.hash, originalValue, `hash was set \n got: ${result.hash} \n expected: ${originalValue}`)
assert.equal(result.status, 'approved' ,'Should have only reached the approved status.')

// TODO: Add a way of detecting whether the Controller will continue trying to submit this transaction.

signStub.restore()
pubStub.restore()
setStatusStub.restore()
setStatusStub2.restore()
})
})

describe('#sign replay-protected tx', function () {
Expand Down

0 comments on commit f2514ad

Please sign in to comment.