aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/send-content/send-to-row/tests
diff options
context:
space:
mode:
authorEsteban MiƱo <efmino@uc.cl>2019-01-23 03:05:59 +0800
committerDan Finlay <542863+danfinlay@users.noreply.github.com>2019-01-23 03:05:59 +0800
commit1d93d9a3852daf3842ef71c3775f41cbb79a3f00 (patch)
treed4643fb30d6b1ad39eb06f7af68c111f5a42ba7a /ui/app/components/send/send-content/send-to-row/tests
parent2cfea0b788e4c3f9420358ef62cff46850fc8146 (diff)
downloadtangerine-wallet-browser-1d93d9a3852daf3842ef71c3775f41cbb79a3f00.tar.gz
tangerine-wallet-browser-1d93d9a3852daf3842ef71c3775f41cbb79a3f00.tar.zst
tangerine-wallet-browser-1d93d9a3852daf3842ef71c3775f41cbb79a3f00.zip
Prevent send to token (#6051)
* check contact metadata * check for tokens in state * tests * update tests * validation only if sending tokens * container test
Diffstat (limited to 'ui/app/components/send/send-content/send-to-row/tests')
-rw-r--r--ui/app/components/send/send-content/send-to-row/tests/send-to-row-container.test.js4
-rw-r--r--ui/app/components/send/send-content/send-to-row/tests/send-to-row-selectors.test.js12
-rw-r--r--ui/app/components/send/send-content/send-to-row/tests/send-to-row-utils.test.js24
3 files changed, 40 insertions, 0 deletions
diff --git a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-container.test.js b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-container.test.js
index dfce7652f..95efdd7cc 100644
--- a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-container.test.js
+++ b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-container.test.js
@@ -24,6 +24,7 @@ proxyquire('../send-to-row.container.js', {
},
'../../send.selectors.js': {
getCurrentNetwork: (s) => `mockNetwork:${s}`,
+ getSelectedToken: (s) => `mockSelectedToken:${s}`,
getSendHexData: (s) => s,
getSendTo: (s) => `mockTo:${s}`,
getSendToAccounts: (s) => `mockToAccounts:${s}`,
@@ -31,6 +32,7 @@ proxyquire('../send-to-row.container.js', {
'./send-to-row.selectors.js': {
getToDropdownOpen: (s) => `mockToDropdownOpen:${s}`,
sendToIsInError: (s) => `mockInError:${s}`,
+ getTokens: (s) => `mockTokens:${s}`,
},
'../../../../actions': actionSpies,
'../../../../ducks/send.duck': duckActionSpies,
@@ -45,9 +47,11 @@ describe('send-to-row container', () => {
hasHexData: true,
inError: 'mockInError:mockState',
network: 'mockNetwork:mockState',
+ selectedToken: 'mockSelectedToken:mockState',
to: 'mockTo:mockState',
toAccounts: 'mockToAccounts:mockState',
toDropdownOpen: 'mockToDropdownOpen:mockState',
+ tokens: 'mockTokens:mockState',
})
})
diff --git a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-selectors.test.js b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-selectors.test.js
index 122ad3265..0fa342d1e 100644
--- a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-selectors.test.js
+++ b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-selectors.test.js
@@ -1,6 +1,7 @@
import assert from 'assert'
import {
getToDropdownOpen,
+ getTokens,
sendToIsInError,
} from '../send-to-row.selectors.js'
@@ -44,4 +45,15 @@ describe('send-to-row selectors', () => {
})
})
+ describe('getTokens()', () => {
+ it('should return empty array if no tokens in state', () => {
+ const state = {
+ metamask: {
+ tokens: [],
+ },
+ }
+
+ assert.deepStrictEqual(getTokens(state), [])
+ })
+ })
})
diff --git a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-utils.test.js b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-utils.test.js
index c779aeb76..8d4f26e15 100644
--- a/ui/app/components/send/send-content/send-to-row/tests/send-to-row-utils.test.js
+++ b/ui/app/components/send/send-content/send-to-row/tests/send-to-row-utils.test.js
@@ -5,6 +5,7 @@ import sinon from 'sinon'
import {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
+ KNOWN_RECIPIENT_ADDRESS_ERROR,
} from '../../../send.constants'
const stubs = {
@@ -52,6 +53,29 @@ describe('send-to-row utils', () => {
to: 'someExplicitError',
})
})
+
+ it('should return a known address recipient if to is truthy but part of state tokens', () => {
+ assert.deepEqual(getToErrorObject('0xabc123', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
+ to: KNOWN_RECIPIENT_ADDRESS_ERROR,
+ })
+ })
+
+ it('should null if to is truthy part of tokens but selectedToken falsy', () => {
+ assert.deepEqual(getToErrorObject('0xabc123', undefined, false, [{'address': '0xabc123'}]), {
+ to: null,
+ })
+ })
+
+ it('should return a known address recipient if to is truthy but part of contract metadata', () => {
+ assert.deepEqual(getToErrorObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
+ to: KNOWN_RECIPIENT_ADDRESS_ERROR,
+ })
+ })
+ it('should null if to is truthy part of contract metadata but selectedToken falsy', () => {
+ assert.deepEqual(getToErrorObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
+ to: KNOWN_RECIPIENT_ADDRESS_ERROR,
+ })
+ })
})
})