aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authortmashuang <thomas.b.huang@gmail.com>2018-05-22 05:57:57 +0800
committertmashuang <thomas.b.huang@gmail.com>2018-05-22 05:57:57 +0800
commit58b9afff4f3801d6d74b5311fb95060cc0a79cc1 (patch)
treec8d5a97f85fc7cf3c09a92949fdd615a082915cb /test/unit
parent554a10f17e8e6b4bc79d3e5440295d280458717a (diff)
parent08d95bbafa3f952b960124c36958edbafa57cb3d (diff)
downloadtangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar.gz
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar.bz2
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar.lz
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar.xz
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.tar.zst
tangerine-wallet-browser-58b9afff4f3801d6d74b5311fb95060cc0a79cc1.zip
Merge branch 'develop' into testing
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/actions/save_account_label_test.js35
-rw-r--r--test/unit/actions/set_account_label_test.js34
-rw-r--r--test/unit/app/controllers/address-book-controller.js26
-rw-r--r--test/unit/app/controllers/metamask-controller-test.js19
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js116
-rw-r--r--test/unit/migrations/026-test.js41
6 files changed, 214 insertions, 57 deletions
diff --git a/test/unit/actions/save_account_label_test.js b/test/unit/actions/save_account_label_test.js
deleted file mode 100644
index c5ffd6cbf..000000000
--- a/test/unit/actions/save_account_label_test.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// var jsdom = require('mocha-jsdom')
-var assert = require('assert')
-var freeze = require('deep-freeze-strict')
-var path = require('path')
-
-var actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
-var reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
-
-describe('SAVE_ACCOUNT_LABEL', function () {
- it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () {
- var initialState = {
- metamask: {
- identities: {
- foo: {
- name: 'bar',
- },
- },
- },
- }
- freeze(initialState)
-
- const action = {
- type: actions.SAVE_ACCOUNT_LABEL,
- value: {
- account: 'foo',
- label: 'baz',
- },
- }
- freeze(action)
-
- var resultingState = reducers(initialState, action)
- assert.equal(resultingState.metamask.identities.foo.name, action.value.label)
- })
-})
-
diff --git a/test/unit/actions/set_account_label_test.js b/test/unit/actions/set_account_label_test.js
new file mode 100644
index 000000000..53ea1d130
--- /dev/null
+++ b/test/unit/actions/set_account_label_test.js
@@ -0,0 +1,34 @@
+const assert = require('assert')
+const freeze = require('deep-freeze-strict')
+const path = require('path')
+
+const actions = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'actions.js'))
+const reducers = require(path.join(__dirname, '..', '..', '..', 'ui', 'app', 'reducers.js'))
+
+describe('SET_ACCOUNT_LABEL', function () {
+ it('updates the state.metamask.identities[:i].name property of the state to the action.value.label', function () {
+ const initialState = {
+ metamask: {
+ identities: {
+ foo: {
+ name: 'bar',
+ },
+ },
+ },
+ }
+ freeze(initialState)
+
+ const action = {
+ type: actions.SET_ACCOUNT_LABEL,
+ value: {
+ account: 'foo',
+ label: 'baz',
+ },
+ }
+ freeze(action)
+
+ const resultingState = reducers(initialState, action)
+ assert.equal(resultingState.metamask.identities.foo.name, action.value.label)
+ })
+})
+
diff --git a/test/unit/app/controllers/address-book-controller.js b/test/unit/app/controllers/address-book-controller.js
index 1836dea94..dc4b8e3ff 100644
--- a/test/unit/app/controllers/address-book-controller.js
+++ b/test/unit/app/controllers/address-book-controller.js
@@ -1,26 +1,26 @@
const assert = require('assert')
const AddressBookController = require('../../../../app/scripts/controllers/address-book')
-const mockKeyringController = {
- memStore: {
- getState: function () {
- return {
- identities: {
- '0x0aaa': {
- address: '0x0aaa',
- name: 'owned',
- },
+const stubPreferencesStore = {
+ getState: function () {
+ return {
+ identities: {
+ '0x0aaa': {
+ address: '0x0aaa',
+ name: 'owned',
},
- }
- },
+ },
+ }
},
-}
+};
describe('address-book-controller', function () {
var addressBookController
beforeEach(function () {
- addressBookController = new AddressBookController({}, mockKeyringController)
+ addressBookController = new AddressBookController({
+ preferencesStore: stubPreferencesStore,
+ })
})
describe('addres book management', function () {
diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js
index 65a6fea09..4bc16e65e 100644
--- a/test/unit/app/controllers/metamask-controller-test.js
+++ b/test/unit/app/controllers/metamask-controller-test.js
@@ -4,7 +4,7 @@ const clone = require('clone')
const nock = require('nock')
const createThoughStream = require('through2').obj
const MetaMaskController = require('../../../../app/scripts/metamask-controller')
-const blacklistJSON = require('../../../stub/blacklist')
+const blacklistJSON = require('eth-phishing-detect/src/config')
const firstTimeState = require('../../../../app/scripts/first-time-state')
const currentNetworkId = 42
@@ -118,7 +118,7 @@ describe('MetaMaskController', function () {
[TEST_ADDRESS]: { address: TEST_ADDRESS, name: DEFAULT_LABEL },
})
- await metamaskController.keyringController.saveAccountLabel(TEST_ADDRESS, 'Account Foo')
+ await metamaskController.preferencesController.setAccountLabel(TEST_ADDRESS, 'Account Foo')
assert.deepEqual(metamaskController.getState().identities, {
[TEST_ADDRESS]: { address: TEST_ADDRESS, name: 'Account Foo' },
})
@@ -170,14 +170,17 @@ describe('MetaMaskController', function () {
beforeEach(function () {
address = '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc'
identities = {
- identities: {
- '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
- 'address': '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc',
- 'name': 'Account 1',
- },
+ '0x0dcd5d886577d5081b0c52e242ef29e70be3e7bc': {
+ 'address': address,
+ 'name': 'Account 1',
+ },
+ '0xc42edfcc21ed14dda456aa0756c153f7985d8813': {
+ 'address': '0xc42edfcc21ed14dda456aa0756c153f7985d8813',
+ 'name': 'Account 2',
},
}
- metamaskController.selectFirstIdentity(identities)
+ metamaskController.preferencesController.store.updateState({ identities })
+ metamaskController.selectFirstIdentity()
})
it('changes preferences controller select address', function () {
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index 3d903bd5b..e5e751b57 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -4,16 +4,91 @@ const PreferencesController = require('../../../../app/scripts/controllers/prefe
describe('preferences controller', function () {
let preferencesController
- before(() => {
+ beforeEach(() => {
preferencesController = new PreferencesController()
})
+ describe('setAddresses', function () {
+ it('should keep a map of addresses to names and addresses in the store', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ const {identities} = preferencesController.store.getState()
+ assert.deepEqual(identities, {
+ '0xda22le': {
+ name: 'Account 1',
+ address: '0xda22le',
+ },
+ '0x7e57e2': {
+ name: 'Account 2',
+ address: '0x7e57e2',
+ },
+ })
+ })
+
+ it('should replace its list of addresses', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+ preferencesController.setAddresses([
+ '0xda22le77',
+ '0x7e57e277',
+ ])
+
+ const {identities} = preferencesController.store.getState()
+ assert.deepEqual(identities, {
+ '0xda22le77': {
+ name: 'Account 1',
+ address: '0xda22le77',
+ },
+ '0x7e57e277': {
+ name: 'Account 2',
+ address: '0x7e57e277',
+ },
+ })
+ })
+ })
+
+ describe('setAccountLabel', function () {
+ it('should update a label for the given account', function () {
+ preferencesController.setAddresses([
+ '0xda22le',
+ '0x7e57e2',
+ ])
+
+ assert.deepEqual(preferencesController.store.getState().identities['0xda22le'], {
+ name: 'Account 1',
+ address: '0xda22le',
+ })
+
+
+ preferencesController.setAccountLabel('0xda22le', 'Dazzle')
+ assert.deepEqual(preferencesController.store.getState().identities['0xda22le'], {
+ name: 'Dazzle',
+ address: '0xda22le',
+ })
+ })
+ })
+
+ describe('getTokens', function () {
+ it('should return an empty list initially', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 0, 'empty list of tokens')
+ })
+ })
+
describe('addToken', function () {
it('should add that token to its state', async function () {
const address = '0xabcdef1234567'
const symbol = 'ABBR'
const decimals = 5
+ await preferencesController.setSelectedAddress('0x7e57e2')
await preferencesController.addToken(address, symbol, decimals)
const tokens = preferencesController.getTokens()
@@ -30,6 +105,7 @@ describe('preferences controller', function () {
const symbol = 'ABBR'
const decimals = 5
+ await preferencesController.setSelectedAddress('0x7e57e2')
await preferencesController.addToken(address, symbol, decimals)
const newDecimals = 6
@@ -43,6 +119,44 @@ describe('preferences controller', function () {
assert.equal(added.symbol, symbol, 'set symbol correctly')
assert.equal(added.decimals, newDecimals, 'updated decimals correctly')
})
+
+ it('should allow adding tokens to two separate addresses', async function () {
+ const address = '0xabcdef1234567'
+ const symbol = 'ABBR'
+ const decimals = 5
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken(address, symbol, decimals)
+ assert.equal(preferencesController.getTokens().length, 1, 'one token added for 1st address')
+
+ await preferencesController.setSelectedAddress('0xda22le')
+ await preferencesController.addToken(address, symbol, decimals)
+ assert.equal(preferencesController.getTokens().length, 1, 'one token added for 2nd address')
+ })
+ })
+
+ describe('removeToken', function () {
+ it('should remove the only token from its state', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 5)
+ await preferencesController.removeToken('0xa')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 0, 'one token removed')
+ })
+
+ it('should remove a token from its state', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.removeToken('0xa')
+
+ const tokens = preferencesController.getTokens()
+ assert.equal(tokens.length, 1, 'one token removed')
+
+ const [token1] = tokens
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+ })
})
})
diff --git a/test/unit/migrations/026-test.js b/test/unit/migrations/026-test.js
new file mode 100644
index 000000000..b3f5470cf
--- /dev/null
+++ b/test/unit/migrations/026-test.js
@@ -0,0 +1,41 @@
+const assert = require('assert')
+const migration26 = require('../../../app/scripts/migrations/026')
+const oldStorage = {
+ 'meta': {'version': 25},
+ 'data': {
+ 'PreferencesController': {},
+ 'KeyringController': {
+ 'walletNicknames': {
+ '0x1e77e2': 'Test Account 1',
+ '0x7e57e2': 'Test Account 2',
+ },
+ },
+ },
+}
+
+describe('migration #26', () => {
+ it('should move the identities from KeyringController', (done) => {
+ migration26.migrate(oldStorage)
+ .then((newStorage) => {
+ const identities = newStorage.data.PreferencesController.identities
+ assert.deepEqual(identities, {
+ '0x1e77e2': {name: 'Test Account 1', address: '0x1e77e2'},
+ '0x7e57e2': {name: 'Test Account 2', address: '0x7e57e2'},
+ })
+ assert.strictEqual(newStorage.data.KeyringController.walletNicknames, undefined)
+ done()
+ })
+ .catch(done)
+ })
+
+ it('should successfully migrate first time state', (done) => {
+ migration26.migrate({
+ meta: {},
+ data: require('../../../app/scripts/first-time-state'),
+ })
+ .then((migratedData) => {
+ assert.equal(migratedData.meta.version, migration26.version)
+ done()
+ }).catch(done)
+ })
+})