From c2cef0f815efb5667bf9aabff125cc1a8822283c Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 30 Jan 2018 13:26:37 -0800 Subject: Set address to default with empty string, add test validation. --- test/unit/ui/add-token.spec.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/unit/ui/add-token.spec.js (limited to 'test/unit') diff --git a/test/unit/ui/add-token.spec.js b/test/unit/ui/add-token.spec.js new file mode 100644 index 000000000..ee52f775f --- /dev/null +++ b/test/unit/ui/add-token.spec.js @@ -0,0 +1,44 @@ +const React = require('react') +const assert = require('assert') +const { createMockStore } = require('redux-test-utils') +const h = require('react-hyperscript') +const { shallowWithStore, mountWithStore } = require('../../lib/shallow-with-store') +const AddTokenScreen = require('../../../ui/app/add-token') + +describe.only('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.') + }) + + }) +}) -- cgit v1.2.3 From 0f10aa372982c0d072bfd8f3466d3a044f0a7e94 Mon Sep 17 00:00:00 2001 From: Thomas Date: Tue, 30 Jan 2018 13:29:05 -0800 Subject: Clean up test, remove react & mountWithStore --- test/unit/ui/add-token.spec.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/ui/add-token.spec.js b/test/unit/ui/add-token.spec.js index ee52f775f..9e74aa37e 100644 --- a/test/unit/ui/add-token.spec.js +++ b/test/unit/ui/add-token.spec.js @@ -1,11 +1,10 @@ -const React = require('react') const assert = require('assert') const { createMockStore } = require('redux-test-utils') const h = require('react-hyperscript') -const { shallowWithStore, mountWithStore } = require('../../lib/shallow-with-store') +const { shallowWithStore } = require('../../lib/shallow-with-store') const AddTokenScreen = require('../../../ui/app/add-token') -describe.only('Add Token Screen', function () { +describe('Add Token Screen', function () { let addTokenComponent, store, component const mockState = { metamask: { -- cgit v1.2.3 From e0caeae06ded5d0e7c74b5e174583fae378e7123 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 30 Jan 2018 15:03:42 -0800 Subject: test for migration 021 --- test/unit/migrations/021-test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/unit/migrations/021-test.js (limited to 'test/unit') diff --git a/test/unit/migrations/021-test.js b/test/unit/migrations/021-test.js new file mode 100644 index 000000000..9d1066c13 --- /dev/null +++ b/test/unit/migrations/021-test.js @@ -0,0 +1,15 @@ +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) + done() + }).catch(done) + }) +}) -- cgit v1.2.3 From a70eda36515ee8dc7f0b58bf561dd14c92e70596 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 13:29:30 -0500 Subject: add test for wipeTransactions --- test/unit/tx-state-manager-test.js | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/unit') diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js index 464e50ee4..3d9641453 100644 --- a/test/unit/tx-state-manager-test.js +++ b/test/unit/tx-state-manager-test.js @@ -238,4 +238,53 @@ describe('TransactionStateManger', function () { assert.equal(txStateManager.getFilteredTxList(filterParams).length, 5, `getFilteredTxList - ${JSON.stringify(filterParams)}`) }) }) + + describe('#wipeTransactions', function () { + + const specificAddress = '0xaa'; + + it('should remove only the transactions from a specific address', function () { + + const txMetas = [ + { id: 0, status: 'unapproved', txParams: { from: specificAddress, to: '0xbb' }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: '0xbb', to: specificAddress }, metamaskNetworkId: currentNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: '0xcc', 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: '0xbb' }, metamaskNetworkId: currentNetworkId }, + { id: 1, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, + { id: 2, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, 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) + + console.log('NETWORK TX LIST: ', txStateManager.getTxList()); + console.log('FULL TX LIST: ', txStateManager.getFullTxList()); + + assert.equal(txsFromCurrentNetworkAndAddress.length, 0); + assert.equal(txFromOtherNetworks.length, 2); + + + }) + }) }) \ No newline at end of file -- cgit v1.2.3 From 94dd77d194de97b59c0a191a7439d96ff255bf41 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Wed, 31 Jan 2018 13:34:14 -0500 Subject: clean up --- test/unit/tx-state-manager-test.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'test/unit') diff --git a/test/unit/tx-state-manager-test.js b/test/unit/tx-state-manager-test.js index 3d9641453..02dc52967 100644 --- a/test/unit/tx-state-manager-test.js +++ b/test/unit/tx-state-manager-test.js @@ -241,14 +241,15 @@ describe('TransactionStateManger', function () { describe('#wipeTransactions', function () { - const specificAddress = '0xaa'; + 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: '0xbb' }, metamaskNetworkId: currentNetworkId }, - { id: 1, status: 'confirmed', txParams: { from: '0xbb', to: specificAddress }, metamaskNetworkId: currentNetworkId }, - { id: 2, status: 'confirmed', txParams: { from: '0xcc', to: specificAddress }, metamaskNetworkId: currentNetworkId }, + { 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)) @@ -257,18 +258,15 @@ describe('TransactionStateManger', function () { 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); - - + 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: '0xbb' }, metamaskNetworkId: currentNetworkId }, - { id: 1, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, - { id: 2, status: 'confirmed', txParams: { from: specificAddress, to: specificAddress }, metamaskNetworkId: otherNetworkId }, + { 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)) @@ -276,14 +274,10 @@ describe('TransactionStateManger', function () { txStateManager.wipeTransactions(specificAddress) const txsFromCurrentNetworkAndAddress = txStateManager.getTxList().filter((txMeta) => txMeta.txParams.from === specificAddress) - const txFromOtherNetworks= txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId) - - console.log('NETWORK TX LIST: ', txStateManager.getTxList()); - console.log('FULL TX LIST: ', txStateManager.getFullTxList()); - - assert.equal(txsFromCurrentNetworkAndAddress.length, 0); - assert.equal(txFromOtherNetworks.length, 2); + const txFromOtherNetworks = txStateManager.getFullTxList().filter((txMeta) => txMeta.metamaskNetworkId === otherNetworkId) + assert.equal(txsFromCurrentNetworkAndAddress.length, 0) + assert.equal(txFromOtherNetworks.length, 2) }) }) -- cgit v1.2.3 From c3adbda5f561c20c011a7b78f1e84513cebba87e Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 31 Jan 2018 10:49:58 -0800 Subject: remove RecentBlocks from disk --- test/unit/migrations/021-test.js | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/migrations/021-test.js b/test/unit/migrations/021-test.js index 9d1066c13..458e9b4b5 100644 --- a/test/unit/migrations/021-test.js +++ b/test/unit/migrations/021-test.js @@ -9,6 +9,7 @@ describe('wallet2 is migrated successfully with out the BlacklistController', () .then((migratedData) => { assert.equal(migratedData.meta.version, 21) assert(!migratedData.data.BlacklistController) + assert(!migratedData.data.RecentBlocks) done() }).catch(done) }) -- cgit v1.2.3