aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/migrations/021-test.js16
-rw-r--r--test/unit/tx-state-manager-test.js43
-rw-r--r--test/unit/ui/add-token.spec.js43
3 files changed, 102 insertions, 0 deletions
diff --git a/test/unit/migrations/021-test.js b/test/unit/migrations/021-test.js
new file mode 100644
index 000000000..458e9b4b5
--- /dev/null
+++ b/test/unit/migrations/021-test.js
@@ -0,0 +1,16 @@
+const assert = require('assert')
+
+const wallet2 = require('../../lib/migrations/002.json')
+const migration21 = require('../../../app/scripts/migrations/021')
+
+describe('wallet2 is migrated successfully with out the BlacklistController', () => {
+ it('should delete BlacklistController key', (done) => {
+ migration21.migrate(wallet2)
+ .then((migratedData) => {
+ assert.equal(migratedData.meta.version, 21)
+ assert(!migratedData.data.BlacklistController)
+ assert(!migratedData.data.RecentBlocks)
+ done()
+ }).catch(done)
+ })
+})
diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js
index 464e50ee4..02dc52967 100644
--- a/test/unit/tx-state-manager-test.js
+++ b/test/unit/tx-state-manager-test.js
@@ -238,4 +238,47 @@ describe('TransactionStateManger', function () {
assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`)
})
})
+
+ 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 },
+ { id: 2, status: 'confirmed', txParams: { from: otherAddress, to: specificAddress }, metamaskNetworkId: currentNetworkId },
+ ]
+ txMetas.forEach((txMeta) => txStateManager.addTx(txMeta, noop))
+
+ txStateManager.wipeTransactions(specificAddress)
+
+ const transactionsFromCurrentAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress)
+ const transactionsFromOtherAddresses = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from !== specificAddress)
+
+ assert.equal(transactionsFromCurrentAddress.length, 0)
+ assert.equal(transactionsFromOtherAddresses.length, 2)
+ })
+
+ it('should not remove the transactions from other networks', function () {
+ const txMetas = [
+ { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: otherAddress }, metamaskNetworkId: currentNetworkId },
+ { 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)
+
+ const txsFromCurrentNetworkAndAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress)
+ const txFromOtherNetworks = txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId)
+
+ assert.equal(txsFromCurrentNetworkAndAddress.length, 0)
+ assert.equal(txFromOtherNetworks.length, 2)
+
+ })
+ })
}) \ No newline at end of file
diff --git a/test/unit/ui/add-token.spec.js b/test/unit/ui/add-token.spec.js
new file mode 100644
index 000000000..69b7fb620
--- /dev/null
+++ b/test/unit/ui/add-token.spec.js
@@ -0,0 +1,43 @@
+const assert = require('assert')
+const { createMockStore } = require('redux-test-utils')
+const h = require('react-hyperscript')
+const { shallowWithStore } = require('../../lib/shallow-with-store')
+const AddTokenScreen = require('../../../old-ui/app/add-token')
+
+describe('Add Token Screen', function () {
+ let addTokenComponent, store, component
+ const mockState = {
+ metamask: {
+ identities: {
+ '0x7d3517b0d011698406d6e0aed8453f0be2697926': {
+ 'address': '0x7d3517b0d011698406d6e0aed8453f0be2697926',
+ 'name': 'Add Token Name',
+ },
+ },
+ },
+ }
+ beforeEach(function () {
+ store = createMockStore(mockState)
+ component = shallowWithStore(h(AddTokenScreen), store)
+ addTokenComponent = component.dive()
+ })
+
+ describe('#ValidateInputs', function () {
+
+ it('Default State', function () {
+ addTokenComponent.instance().validateInputs()
+ const state = addTokenComponent.state()
+ assert.equal(state.warning, 'Address is invalid.')
+ })
+
+ it('Address is a Metamask Identity', function () {
+ addTokenComponent.setState({
+ address: '0x7d3517b0d011698406d6e0aed8453f0be2697926',
+ })
+ addTokenComponent.instance().validateInputs()
+ const state = addTokenComponent.state()
+ assert.equal(state.warning, 'Personal address detected. Input the token contract address.')
+ })
+
+ })
+})