mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Enforce tx history limit
This commit is contained in:
parent
90d6bec3ed
commit
7389f9d0a0
@ -5,6 +5,7 @@ const rp = require('request-promise')
|
||||
|
||||
const TESTNET_RPC = MetamaskConfig.network.testnet
|
||||
const MAINNET_RPC = MetamaskConfig.network.mainnet
|
||||
const txLimit = 40
|
||||
|
||||
/* The config-manager is a convenience object
|
||||
* wrapping a pojo-migrator.
|
||||
@ -15,6 +16,8 @@ const MAINNET_RPC = MetamaskConfig.network.mainnet
|
||||
*/
|
||||
module.exports = ConfigManager
|
||||
function ConfigManager (opts) {
|
||||
this.txLimit = txLimit
|
||||
|
||||
// ConfigManager is observable and will emit updates
|
||||
this._subs = []
|
||||
|
||||
@ -181,6 +184,9 @@ ConfigManager.prototype._saveTxList = function (txList) {
|
||||
|
||||
ConfigManager.prototype.addTx = function (tx) {
|
||||
var transactions = this.getTxList()
|
||||
while (transactions.length > this.txLimit - 1) {
|
||||
transactions.shift()
|
||||
}
|
||||
transactions.push(tx)
|
||||
this._saveTxList(transactions)
|
||||
}
|
||||
|
@ -233,6 +233,17 @@ describe('config-manager', function() {
|
||||
assert.equal(result.length, 1)
|
||||
assert.equal(result[0].id, 1)
|
||||
})
|
||||
|
||||
it('cuts off early txs beyond a limit', function() {
|
||||
const limit = configManager.txLimit
|
||||
for (let i = 0; i < limit + 1; i++) {
|
||||
let tx = { id: i }
|
||||
configManager.addTx(tx)
|
||||
}
|
||||
var result = configManager.getTxList()
|
||||
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
|
||||
assert.equal(result[0].id, 1, 'early txs truncted')
|
||||
})
|
||||
})
|
||||
|
||||
describe('#confirmTx', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user