mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
more tests and craete a getPendingTransactions function
This commit is contained in:
parent
50075c6df5
commit
9b9df41724
@ -49,12 +49,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
this.nonceTracker = new NonceTracker({
|
this.nonceTracker = new NonceTracker({
|
||||||
provider: this.provider,
|
provider: this.provider,
|
||||||
getPendingTransactions: (address) => {
|
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
|
||||||
return this.txStateManager.getFilteredTxList({
|
|
||||||
from: address,
|
|
||||||
status: 'submitted',
|
|
||||||
})
|
|
||||||
},
|
|
||||||
getConfirmedTransactions: (address) => {
|
getConfirmedTransactions: (address) => {
|
||||||
return this.txStateManager.getFilteredTxList({
|
return this.txStateManager.getFilteredTxList({
|
||||||
from: address,
|
from: address,
|
||||||
@ -73,9 +68,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
return account.balance
|
return account.balance
|
||||||
},
|
},
|
||||||
publishTransaction: this.query.sendRawTransaction,
|
publishTransaction: this.query.sendRawTransaction,
|
||||||
getPendingTransactions: () => {
|
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
|
||||||
return this.txStateManager.getFilteredTxList({ status: 'submitted' })
|
|
||||||
},
|
|
||||||
giveUpOnTransaction: (txId) => {
|
giveUpOnTransaction: (txId) => {
|
||||||
const msg = `Gave up submitting after 3500 blocks un-mined.`
|
const msg = `Gave up submitting after 3500 blocks un-mined.`
|
||||||
this.setTxStatusFailed(txId, msg)
|
this.setTxStatusFailed(txId, msg)
|
||||||
@ -122,8 +115,8 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
return Object.keys(this.txStateManager.getUnapprovedTxList()).length
|
return Object.keys(this.txStateManager.getUnapprovedTxList()).length
|
||||||
}
|
}
|
||||||
|
|
||||||
getPendingTxCount () {
|
getPendingTxCount (account) {
|
||||||
return this.txStateManager.getTxsByMetaData('status', 'signed').length
|
return this.txStateManager.getPendingTransactions(account).length
|
||||||
}
|
}
|
||||||
|
|
||||||
getChainId () {
|
getChainId () {
|
||||||
|
@ -33,6 +33,12 @@ module.exports = class TransactionStateManger extends ObservableStore {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPendingTransactions (address) {
|
||||||
|
const opts = { status: 'submitted' }
|
||||||
|
if (address) opts.from = address
|
||||||
|
return this.txStateManager.getFilteredTxList(opts)
|
||||||
|
}
|
||||||
|
|
||||||
addTx (txMeta) {
|
addTx (txMeta) {
|
||||||
this.once(`${txMeta.id}:signed`, function (txId) {
|
this.once(`${txMeta.id}:signed`, function (txId) {
|
||||||
this.removeAllListeners(`${txMeta.id}:rejected`)
|
this.removeAllListeners(`${txMeta.id}:rejected`)
|
||||||
|
@ -24,7 +24,8 @@ describe('PendingTx', function () {
|
|||||||
'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
|
||||||
'value': '0xde0b6b3a7640000',
|
'value': '0xde0b6b3a7640000',
|
||||||
gasPrice,
|
gasPrice,
|
||||||
'gas': '0x7b0c'},
|
'gas': '0x7b0c',
|
||||||
|
},
|
||||||
'gasLimitSpecified': false,
|
'gasLimitSpecified': false,
|
||||||
'estimatedGas': '0x5208',
|
'estimatedGas': '0x5208',
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,28 @@ describe('Transaction Controller', function () {
|
|||||||
txController.txProviderUtils = new TxGasUtils(txController.provider)
|
txController.txProviderUtils = new TxGasUtils(txController.provider)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('#getState', function () {
|
||||||
|
it('should return a state object with the right keys and datat types', function (){
|
||||||
|
const exposedState = txController.getState()
|
||||||
|
assert('unapprovedTxs' in exposedState, 'state should have the key unapprovedTxs')
|
||||||
|
assert('selectedAddressTxList' in exposedState, 'state should have the key selectedAddressTxList')
|
||||||
|
assert(typeof exposedState.unapprovedTxs === 'object', 'should be an object')
|
||||||
|
assert(Array.isArray(exposedState.selectedAddressTxList), 'should be an array')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('#getUnapprovedTxCount', function () {
|
||||||
|
it('should return the number of unapproved txs', function () {
|
||||||
|
txController.txStateManager._saveTxList([
|
||||||
|
{ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
|
||||||
|
{ id: 2, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
|
||||||
|
{ id: 3, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: {} },
|
||||||
|
])
|
||||||
|
const unapprovedTxCount = txController.getUnapprovedTxCount()
|
||||||
|
assert.equal(unapprovedTxCount, 3, 'should be 3')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('#newUnapprovedTransaction', function () {
|
describe('#newUnapprovedTransaction', function () {
|
||||||
let stub, txMeta, txParams
|
let stub, txMeta, txParams
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user