aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-03-28 08:17:04 +0800
committerkumavis <aaron@kumavis.me>2018-03-28 08:17:04 +0800
commit5290570c8fc635856823e8f66b8f810f07b7948a (patch)
treecb98ac01c290f0c9786fc285469bb37e6a851910 /test
parent4ee48acf5672f00d59c49ec68452cd1dd57afa31 (diff)
parentb6b18339e2de92afd2fb5364ec5bc4c29b4d10a3 (diff)
downloadtangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.gz
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.bz2
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.lz
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.xz
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.tar.zst
tangerine-wallet-browser-5290570c8fc635856823e8f66b8f810f07b7948a.zip
Merge branch 'master' of github.com:MetaMask/metamask-extension into i18n-translator-redux
Diffstat (limited to 'test')
-rw-r--r--test/unit/migrations/023-test.js99
-rw-r--r--test/unit/tx-state-manager-test.js6
2 files changed, 102 insertions, 3 deletions
diff --git a/test/unit/migrations/023-test.js b/test/unit/migrations/023-test.js
new file mode 100644
index 000000000..be432d9fa
--- /dev/null
+++ b/test/unit/migrations/023-test.js
@@ -0,0 +1,99 @@
+const assert = require('assert')
+const migration23 = require('../../../app/scripts/migrations/023')
+const properTime = (new Date()).getTime()
+const storage = {
+ "meta": {},
+ "data": {
+ "TransactionController": {
+ "transactions": [
+ ]
+ },
+ },
+}
+
+const transactions = []
+const transactions40 = []
+const transactions20 = []
+
+const txStates = [
+ 'unapproved',
+ 'approved',
+ 'signed',
+ 'submitted',
+ 'confirmed',
+ 'rejected',
+ 'failed',
+ 'dropped',
+]
+
+const deletableTxStates = [
+ 'confirmed',
+ 'rejected',
+ 'failed',
+ 'dropped',
+]
+
+let nonDeletableCount = 0
+
+let status
+while (transactions.length <= 100) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ if (!deletableTxStates.find((s) => s === status)) nonDeletableCount++
+ transactions.push({status})
+}
+
+while (transactions40.length < 40) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ transactions40.push({status})
+}
+
+while (transactions20.length < 20) {
+ status = txStates[Math.floor(Math.random() * Math.floor(txStates.length - 1))]
+ transactions20.push({status})
+}
+
+
+
+storage.data.TransactionController.transactions = transactions
+
+describe('storage is migrated successfully and the proper transactions are remove from state', () => {
+ it('should remove transactions that are unneeded', (done) => {
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ let leftoverNonDeletableTxCount = 0
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+ migratedTransactions.forEach((tx) => {
+ if (!deletableTxStates.find((s) => s === tx.status)) {
+ leftoverNonDeletableTxCount++
+ }
+ })
+ assert.equal(leftoverNonDeletableTxCount, nonDeletableCount, 'migration shouldnt delete transactions we want to keep')
+ assert((migratedTransactions.length >= 40), `should be equal or greater to 40 if they are non deletable states got ${migratedTransactions.length} transactions`)
+ done()
+ }).catch(done)
+ })
+
+ it('should not remove any transactions because 40 is the expectable limit', (done) => {
+ storage.meta.version = 22
+ storage.data.TransactionController.transactions = transactions40
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+
+ assert.equal(migratedTransactions.length, 40, 'migration shouldnt delete when at limit')
+ done()
+ }).catch(done)
+ })
+
+ it('should not remove any transactions because 20 txs is under the expectable limit', (done) => {
+ storage.meta.version = 22
+ storage.data.TransactionController.transactions = transactions20
+ migration23.migrate(storage)
+ .then((migratedData) => {
+ const migratedTransactions = migratedData.data.TransactionController.transactions
+ assert.equal(migratedTransactions.length, 20, 'migration shouldnt delete when under limit')
+ done()
+ }).catch(done)
+ })
+
+})
diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js
index 220bf501f..a5ac13664 100644
--- a/test/unit/tx-state-manager-test.js
+++ b/test/unit/tx-state-manager-test.js
@@ -240,12 +240,12 @@ describe('TransactionStateManager', function () {
})
describe('#wipeTransactions', function () {
-
+
const specificAddress = '0xaa'
const otherAddress = '0xbb'
it('should remove only the transactions from a specific address', function () {
-
+
const txMetas = [
{ id: 0, status: 'unapproved', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: currentNetworkId },
{ id: 1, status: 'confirmed', txParams: { from: otherAddress, to: specificAddress }, metamaskNetworkId: currentNetworkId },
@@ -268,7 +268,7 @@ describe('TransactionStateManager', function () {
{ id: 1, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId },
{ id: 2, status: 'confirmed', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: otherNetworkId },
]
-
+
txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))
txStateManager.wipeTransactions(specificAddress)