You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.7 KiB
108 lines
3.7 KiB
7 years ago
|
import assert from 'assert'
|
||
|
import proxyquire from 'proxyquire'
|
||
|
import sinon from 'sinon'
|
||
|
|
||
|
import {
|
||
|
REQUIRED_ERROR,
|
||
|
INVALID_RECIPIENT_ADDRESS_ERROR,
|
||
6 years ago
|
KNOWN_RECIPIENT_ADDRESS_ERROR,
|
||
7 years ago
|
} from '../../../send.constants'
|
||
|
|
||
|
const stubs = {
|
||
|
isValidAddress: sinon.stub().callsFake(to => Boolean(to.match(/^[0xabcdef123456798]+$/))),
|
||
|
}
|
||
|
|
||
5 years ago
|
const toRowUtils = proxyquire('../add-recipient.js', {
|
||
6 years ago
|
'../../../../helpers/utils/util': {
|
||
7 years ago
|
isValidAddress: stubs.isValidAddress,
|
||
|
},
|
||
|
})
|
||
|
const {
|
||
|
getToErrorObject,
|
||
6 years ago
|
getToWarningObject,
|
||
7 years ago
|
} = toRowUtils
|
||
|
|
||
5 years ago
|
describe('add-recipient utils', () => {
|
||
7 years ago
|
|
||
|
describe('getToErrorObject()', () => {
|
||
|
it('should return a required error if to is falsy', () => {
|
||
|
assert.deepEqual(getToErrorObject(null), {
|
||
|
to: REQUIRED_ERROR,
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
it('should return null if to is falsy and hexData is truthy', () => {
|
||
|
assert.deepEqual(getToErrorObject(null, undefined, true), {
|
||
|
to: null,
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
it('should return an invalid recipient error if to is truthy but invalid', () => {
|
||
|
assert.deepEqual(getToErrorObject('mockInvalidTo'), {
|
||
|
to: INVALID_RECIPIENT_ADDRESS_ERROR,
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('should return null if to is truthy and valid', () => {
|
||
|
assert.deepEqual(getToErrorObject('0xabc123'), {
|
||
|
to: null,
|
||
|
})
|
||
|
})
|
||
7 years ago
|
|
||
|
it('should return the passed error if to is truthy but invalid if to is truthy and valid', () => {
|
||
|
assert.deepEqual(getToErrorObject('invalid #$ 345878', 'someExplicitError'), {
|
||
|
to: 'someExplicitError',
|
||
|
})
|
||
|
})
|
||
6 years ago
|
|
||
6 years ago
|
it('should return null if to is truthy but part of state tokens', () => {
|
||
6 years ago
|
assert.deepEqual(getToErrorObject('0xabc123', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
|
||
6 years ago
|
to: null,
|
||
6 years ago
|
})
|
||
|
})
|
||
|
|
||
|
it('should null if to is truthy part of tokens but selectedToken falsy', () => {
|
||
|
assert.deepEqual(getToErrorObject('0xabc123', undefined, false, [{'address': '0xabc123'}]), {
|
||
|
to: null,
|
||
|
})
|
||
|
})
|
||
|
|
||
6 years ago
|
it('should return null if to is truthy but part of contract metadata', () => {
|
||
6 years ago
|
assert.deepEqual(getToErrorObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
|
||
6 years ago
|
to: null,
|
||
6 years ago
|
})
|
||
|
})
|
||
|
it('should null if to is truthy part of contract metadata but selectedToken falsy', () => {
|
||
|
assert.deepEqual(getToErrorObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, false, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
|
||
6 years ago
|
to: null,
|
||
6 years ago
|
})
|
||
|
})
|
||
7 years ago
|
})
|
||
|
|
||
6 years ago
|
describe('getToWarningObject()', () => {
|
||
|
it('should return a known address recipient if to is truthy but part of state tokens', () => {
|
||
|
assert.deepEqual(getToWarningObject('0xabc123', undefined, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
|
||
|
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('should null if to is truthy part of tokens but selectedToken falsy', () => {
|
||
|
assert.deepEqual(getToWarningObject('0xabc123', undefined, [{'address': '0xabc123'}]), {
|
||
|
to: null,
|
||
|
})
|
||
|
})
|
||
|
|
||
|
it('should return a known address recipient if to is truthy but part of contract metadata', () => {
|
||
|
assert.deepEqual(getToWarningObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, [{'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(getToWarningObject('0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359', undefined, [{'address': '0xabc123'}], {'address': '0xabc123'}), {
|
||
|
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
|
||
|
})
|
||
|
})
|
||
|
})
|
||
|
|
||
7 years ago
|
})
|