1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

more tests and craete a getPendingTransactions function

This commit is contained in:
frankiebee 2017-09-08 14:24:40 -07:00
parent 50075c6df5
commit 9b9df41724
4 changed files with 34 additions and 12 deletions

View File

@ -49,12 +49,7 @@ module.exports = class TransactionController extends EventEmitter {
this.nonceTracker = new NonceTracker({
provider: this.provider,
getPendingTransactions: (address) => {
return this.txStateManager.getFilteredTxList({
from: address,
status: 'submitted',
})
},
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
getConfirmedTransactions: (address) => {
return this.txStateManager.getFilteredTxList({
from: address,
@ -73,9 +68,7 @@ module.exports = class TransactionController extends EventEmitter {
return account.balance
},
publishTransaction: this.query.sendRawTransaction,
getPendingTransactions: () => {
return this.txStateManager.getFilteredTxList({ status: 'submitted' })
},
getPendingTransactions: this.txStateManager.getPendingTransactions.bind(this.txStateManager),
giveUpOnTransaction: (txId) => {
const msg = `Gave up submitting after 3500 blocks un-mined.`
this.setTxStatusFailed(txId, msg)
@ -122,8 +115,8 @@ module.exports = class TransactionController extends EventEmitter {
return Object.keys(this.txStateManager.getUnapprovedTxList()).length
}
getPendingTxCount () {
return this.txStateManager.getTxsByMetaData('status', 'signed').length
getPendingTxCount (account) {
return this.txStateManager.getPendingTransactions(account).length
}
getChainId () {

View File

@ -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) {
this.once(`${txMeta.id}:signed`, function (txId) {
this.removeAllListeners(`${txMeta.id}:rejected`)

View File

@ -24,7 +24,8 @@ describe('PendingTx', function () {
'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'value': '0xde0b6b3a7640000',
gasPrice,
'gas': '0x7b0c'},
'gas': '0x7b0c',
},
'gasLimitSpecified': false,
'estimatedGas': '0x5208',
}

View File

@ -37,6 +37,28 @@ describe('Transaction Controller', function () {
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 () {
let stub, txMeta, txParams
beforeEach(function () {