aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEsteban MIno <efmino@uc.cl>2018-07-28 05:41:47 +0800
committerEsteban MIno <efmino@uc.cl>2018-07-28 05:41:47 +0800
commitdd6a725e6d76b5910d1d23a5e36905b6057e54fd (patch)
treed2421ed30051c7e3de56ed65e2efb20bb0294cca /test
parente687bc5a47e2157193dfa099a0f45a97fa1aaed1 (diff)
downloadtangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar.gz
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar.bz2
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar.lz
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar.xz
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.tar.zst
tangerine-wallet-browser-dd6a725e6d76b5910d1d23a5e36905b6057e54fd.zip
unit tests for tokens per account and network
Diffstat (limited to 'test')
-rw-r--r--test/unit/app/controllers/preferences-controller-test.js128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/unit/app/controllers/preferences-controller-test.js b/test/unit/app/controllers/preferences-controller-test.js
index 0b96fdfa5..dcf56e91f 100644
--- a/test/unit/app/controllers/preferences-controller-test.js
+++ b/test/unit/app/controllers/preferences-controller-test.js
@@ -161,6 +161,42 @@ describe('preferences controller', function () {
await preferencesController.addToken(address, symbol, decimals)
assert.equal(preferencesController.getTokens().length, 1, 'one token added for 2nd address')
})
+
+ it('should add token per account', async function () {
+ const addressFirst = '0xabcdef1234567'
+ const addressSecond = '0xabcdef1234568'
+ const symbolFirst = 'ABBR'
+ const symbolSecond = 'ABBB'
+ const decimals = 5
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken(addressFirst, symbolFirst, decimals)
+ const tokensFirstAddress = preferencesController.getTokens()
+
+ await preferencesController.setSelectedAddress('0xda22le')
+ await preferencesController.addToken(addressSecond, symbolSecond, decimals)
+ const tokensSeconAddress = preferencesController.getTokens()
+
+ assert.notEqual(tokensFirstAddress, tokensSeconAddress, 'add different tokens for two account and tokens are equal')
+ })
+
+ it('should add token per network', async function () {
+ const addressFirst = '0xabcdef1234567'
+ const addressSecond = '0xabcdef1234568'
+ const symbolFirst = 'ABBR'
+ const symbolSecond = 'ABBB'
+ const decimals = 5
+
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken(addressFirst, symbolFirst, decimals)
+ const tokensFirstAddress = preferencesController.getTokens()
+
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken(addressSecond, symbolSecond, decimals)
+ const tokensSeconAddress = preferencesController.getTokens()
+
+ assert.notEqual(tokensFirstAddress, tokensSeconAddress, 'add different tokens for two networks and tokens are equal')
+ })
})
describe('removeToken', function () {
@@ -185,6 +221,98 @@ describe('preferences controller', function () {
const [token1] = tokens
assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
})
+
+ it('should remove a token from its state on corresponding address', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.removeToken('0xa')
+
+ const tokensFirst = preferencesController.getTokens()
+ assert.equal(tokensFirst.length, 1, 'one token removed in account')
+
+ const [token1] = tokensFirst
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'token deleted for account')
+ })
+
+ it('should remove a token from its state on corresponding network', async function () {
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.removeToken('0xa')
+
+ const tokensFirst = preferencesController.getTokens()
+ assert.equal(tokensFirst.length, 1, 'one token removed in network')
+
+ const [token1] = tokensFirst
+ assert.deepEqual(token1, {address: '0xb', symbol: 'B', decimals: 5})
+
+ network.providerStore.updateState({ type: 'rinkeby' })
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'token deleted for network')
+ })
+ })
+
+ describe('on setSelectedAddress', function () {
+ it('should update tokens from its state on corresponding address', async function () {
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ await preferencesController.addToken('0xa', 'C', 4)
+ await preferencesController.addToken('0xb', 'D', 5)
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ const initialTokensFirst = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const initialTokensSecond = preferencesController.getTokens()
+
+ assert.notDeepEqual(initialTokensFirst, initialTokensSecond, 'tokens not equal for different accounts and tokens')
+
+ await preferencesController.setSelectedAddress('0x7e57e2')
+ const tokensFirst = preferencesController.getTokens()
+ await preferencesController.setSelectedAddress('0x7e57e3')
+ const tokensSecond = preferencesController.getTokens()
+
+ assert.deepEqual(tokensFirst, initialTokensFirst, 'tokens equal for same account')
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'tokens equal for same account')
+ })
+ })
+
+ describe('on updateStateNetworkType', function () {
+ it('should remove a token from its state on corresponding network', async function () {
+ network.providerStore.updateState({ type: 'mainnet' })
+ await preferencesController.addToken('0xa', 'A', 4)
+ await preferencesController.addToken('0xb', 'B', 5)
+ const initialTokensFirst = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'rinkeby' })
+ await preferencesController.addToken('0xa', 'C', 4)
+ await preferencesController.addToken('0xb', 'D', 5)
+ const initialTokensSecond = preferencesController.getTokens()
+
+ assert.notDeepEqual(initialTokensFirst, initialTokensSecond, 'tokens not equal for different networks and tokens')
+
+ network.providerStore.updateState({ type: 'mainnet' })
+ const tokensFirst = preferencesController.getTokens()
+ network.providerStore.updateState({ type: 'rinkeby' })
+ const tokensSecond = preferencesController.getTokens()
+ assert.deepEqual(tokensFirst, initialTokensFirst, 'tokens equal for same network')
+ assert.deepEqual(tokensSecond, initialTokensSecond, 'tokens equal for same network')
+ })
})
})