aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-09-09 05:24:40 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-09-09 05:24:40 +0800
commit9b9df417246dbf332f0a7d8afadb664544ceb484 (patch)
tree4459d9272defce22c54e301d518bc1d4efab7f2f
parent50075c6df5af4441db78b47f3bc2036a65228224 (diff)
downloadtangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar.gz
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar.bz2
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar.lz
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar.xz
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.tar.zst
tangerine-wallet-browser-9b9df417246dbf332f0a7d8afadb664544ceb484.zip
more tests and craete a getPendingTransactions function
-rw-r--r--app/scripts/controllers/transactions.js15
-rw-r--r--app/scripts/lib/tx-state-manager.js6
-rw-r--r--test/unit/components/pending-tx-test.js3
-rw-r--r--test/unit/tx-controller-test.js22
4 files changed, 34 insertions, 12 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index d71be37d8..636424c64 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -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 () {
diff --git a/app/scripts/lib/tx-state-manager.js b/app/scripts/lib/tx-state-manager.js
index eb2a187db..05fbba612 100644
--- a/app/scripts/lib/tx-state-manager.js
+++ b/app/scripts/lib/tx-state-manager.js
@@ -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`)
diff --git a/test/unit/components/pending-tx-test.js b/test/unit/components/pending-tx-test.js
index 22a98bc93..906564558 100644
--- a/test/unit/components/pending-tx-test.js
+++ b/test/unit/components/pending-tx-test.js
@@ -24,7 +24,8 @@ describe('PendingTx', function () {
'to': '0xc5b8dbac4c1d3f152cdeb400e2313f309c410acb',
'value': '0xde0b6b3a7640000',
gasPrice,
- 'gas': '0x7b0c'},
+ 'gas': '0x7b0c',
+ },
'gasLimitSpecified': false,
'estimatedGas': '0x5208',
}
diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js
index f969752ec..937ac55de 100644
--- a/test/unit/tx-controller-test.js
+++ b/test/unit/tx-controller-test.js
@@ -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 () {