mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
test pending-tx-tracker - update tests to reflect new block tracker behavior and remove tx:confirmed event tests
This commit is contained in:
parent
3084dc47d1
commit
60bc28bf3c
@ -13,7 +13,7 @@ const otherNetworkId = 36
|
|||||||
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
const privKey = new Buffer('8718b9618a37d1fc78c436511fc6df3c8258d3250635bba617f33003270ec03e', 'hex')
|
||||||
|
|
||||||
|
|
||||||
describe('PendingTransactionTracker', function () {
|
describe.only('PendingTransactionTracker', function () {
|
||||||
let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub,
|
let pendingTxTracker, txMeta, txMetaNoHash, txMetaNoRawTx, providerResultStub,
|
||||||
provider, txMeta3, txList, knownErrors
|
provider, txMeta3, txList, knownErrors
|
||||||
this.timeout(10000)
|
this.timeout(10000)
|
||||||
@ -52,7 +52,10 @@ describe('PendingTransactionTracker', function () {
|
|||||||
getPendingTransactions: () => {return []},
|
getPendingTransactions: () => {return []},
|
||||||
getCompletedTransactions: () => {return []},
|
getCompletedTransactions: () => {return []},
|
||||||
publishTransaction: () => {},
|
publishTransaction: () => {},
|
||||||
|
confirmTransaction: () => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
pendingTxTracker._getBlock = (blockNumber) => { return {number: blockNumber, transactions: []} }
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('_checkPendingTx state management', function () {
|
describe('_checkPendingTx state management', function () {
|
||||||
@ -120,40 +123,36 @@ describe('PendingTransactionTracker', function () {
|
|||||||
})
|
})
|
||||||
pendingTxTracker.checkForTxInBlock(block)
|
pendingTxTracker.checkForTxInBlock(block)
|
||||||
})
|
})
|
||||||
it('should emit \'txConfirmed\' if the tx is in the block', function (done) {
|
|
||||||
const block = { transactions: [txMeta]}
|
|
||||||
pendingTxTracker.getPendingTransactions = () => [txMeta]
|
|
||||||
pendingTxTracker.once('tx:confirmed', (txId) => {
|
|
||||||
assert(txId, txMeta.id, 'should pass txId')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
|
|
||||||
pendingTxTracker.checkForTxInBlock(block)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
describe('#queryPendingTxs', function () {
|
describe('#queryPendingTxs', function () {
|
||||||
it('should call #_checkPendingTxs if their is no oldBlock', function (done) {
|
it('should call #_checkPendingTxs if their is no oldBlock', function (done) {
|
||||||
let newBlock, oldBlock
|
let newBlock, oldBlock
|
||||||
newBlock = { number: '0x01' }
|
newBlock = '0x01'
|
||||||
pendingTxTracker._checkPendingTxs = done
|
const originalFunction = pendingTxTracker._checkPendingTxs
|
||||||
|
pendingTxTracker._checkPendingTxs = () => { done() }
|
||||||
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
||||||
|
pendingTxTracker._checkPendingTxs = originalFunction
|
||||||
})
|
})
|
||||||
it('should call #_checkPendingTxs if oldBlock and the newBlock have a diff of greater then 1', function (done) {
|
it('should call #_checkPendingTxs if oldBlock and the newBlock have a diff of greater then 1', function (done) {
|
||||||
let newBlock, oldBlock
|
let newBlock, oldBlock
|
||||||
oldBlock = { number: '0x01' }
|
oldBlock = '0x01'
|
||||||
newBlock = { number: '0x03' }
|
newBlock = '0x03'
|
||||||
pendingTxTracker._checkPendingTxs = done
|
const originalFunction = pendingTxTracker._checkPendingTxs
|
||||||
|
pendingTxTracker._checkPendingTxs = () => { done() }
|
||||||
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
||||||
|
pendingTxTracker._checkPendingTxs = originalFunction
|
||||||
})
|
})
|
||||||
it('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less', function (done) {
|
it('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less', function (done) {
|
||||||
let newBlock, oldBlock
|
let newBlock, oldBlock
|
||||||
oldBlock = { number: '0x1' }
|
oldBlock = '0x1'
|
||||||
newBlock = { number: '0x2' }
|
newBlock = '0x2'
|
||||||
|
const originalFunction = pendingTxTracker._checkPendingTxs
|
||||||
pendingTxTracker._checkPendingTxs = () => {
|
pendingTxTracker._checkPendingTxs = () => {
|
||||||
const err = new Error('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less')
|
const err = new Error('should not call #_checkPendingTxs if oldBlock and the newBlock have a diff of 1 or less')
|
||||||
done(err)
|
done(err)
|
||||||
}
|
}
|
||||||
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
pendingTxTracker.queryPendingTxs({ oldBlock, newBlock })
|
||||||
|
pendingTxTracker._checkPendingTxs = originalFunction
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -171,16 +170,6 @@ describe('PendingTransactionTracker', function () {
|
|||||||
providerResultStub.eth_getTransactionByHash = null
|
providerResultStub.eth_getTransactionByHash = null
|
||||||
pendingTxTracker._checkPendingTx(txMeta)
|
pendingTxTracker._checkPendingTx(txMeta)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should emit \'txConfirmed\'', function (done) {
|
|
||||||
providerResultStub.eth_getTransactionByHash = {blockNumber: '0x01'}
|
|
||||||
pendingTxTracker.once('tx:confirmed', (txId) => {
|
|
||||||
assert(txId, txMeta.id, 'should pass txId')
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
pendingTxTracker.once('tx:failed', (_, err) => { done(err) })
|
|
||||||
pendingTxTracker._checkPendingTx(txMeta)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#_checkPendingTxs', function () {
|
describe('#_checkPendingTxs', function () {
|
||||||
@ -207,7 +196,7 @@ describe('PendingTransactionTracker', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('#resubmitPendingTxs', function () {
|
describe('#resubmitPendingTxs', function () {
|
||||||
const blockStub = { number: '0x0' };
|
const blockNuberStub = '0x0'
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
const txMeta2 = txMeta3 = txMeta
|
const txMeta2 = txMeta3 = txMeta
|
||||||
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
|
txList = [txMeta, txMeta2, txMeta3].map((tx) => {
|
||||||
@ -225,7 +214,7 @@ describe('PendingTransactionTracker', function () {
|
|||||||
Promise.all(txList.map((tx) => tx.processed))
|
Promise.all(txList.map((tx) => tx.processed))
|
||||||
.then((txCompletedList) => done())
|
.then((txCompletedList) => done())
|
||||||
.catch(done)
|
.catch(done)
|
||||||
pendingTxTracker.resubmitPendingTxs(blockStub)
|
pendingTxTracker.resubmitPendingTxs(blockNuberStub)
|
||||||
})
|
})
|
||||||
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
|
it('should not emit \'tx:failed\' if the txMeta throws a known txError', function (done) {
|
||||||
knownErrors =[
|
knownErrors =[
|
||||||
@ -252,7 +241,7 @@ describe('PendingTransactionTracker', function () {
|
|||||||
.then((txCompletedList) => done())
|
.then((txCompletedList) => done())
|
||||||
.catch(done)
|
.catch(done)
|
||||||
|
|
||||||
pendingTxTracker.resubmitPendingTxs(blockStub)
|
pendingTxTracker.resubmitPendingTxs(blockNuberStub)
|
||||||
})
|
})
|
||||||
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
|
it('should emit \'tx:warning\' if it encountered a real error', function (done) {
|
||||||
pendingTxTracker.once('tx:warning', (txMeta, err) => {
|
pendingTxTracker.once('tx:warning', (txMeta, err) => {
|
||||||
@ -270,7 +259,7 @@ describe('PendingTransactionTracker', function () {
|
|||||||
.then((txCompletedList) => done())
|
.then((txCompletedList) => done())
|
||||||
.catch(done)
|
.catch(done)
|
||||||
|
|
||||||
pendingTxTracker.resubmitPendingTxs(blockStub)
|
pendingTxTracker.resubmitPendingTxs(blockNuberStub)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
describe('#_resubmitTx', function () {
|
describe('#_resubmitTx', function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user