A Metamask fork with Infura removed and default networks editable
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.
 
 
 
 
 
ciphermask/ui/pages/send/send-content/add-recipient/add-recipient.utils.test.js

115 lines
3.6 KiB

import {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
CONFUSING_ENS_ERROR,
CONTRACT_ADDRESS_ERROR,
} from '../../send.constants';
import { getToErrorObject, getToWarningObject } from './add-recipient';
jest.mock('../../../../helpers/utils/util', () => ({
isDefaultMetaMaskChain: jest.fn().mockReturnValue(true),
isEthNetwork: jest.fn().mockReturnValue(true),
checkExistingAddresses: jest.fn().mockReturnValue(true),
isValidDomainName: jest.requireActual('../../../../helpers/utils/util')
.isValidDomainName,
isOriginContractAddress: jest.requireActual('../../../../helpers/utils/util')
.isOriginContractAddress,
}));
jest.mock('../../../../../shared/modules/hexstring-utils', () => ({
isValidHexAddress: jest.fn((to) =>
Boolean(to.match(/^[0xabcdef123456798]+$/u)),
),
isBurnAddress: jest.fn(() => false),
toChecksumHexAddress: jest.fn((input) => input),
}));
describe('add-recipient utils', () => {
describe('getToErrorObject()', () => {
it('should return a required error if "to" is falsy', () => {
expect(getToErrorObject(null)).toStrictEqual({
to: REQUIRED_ERROR,
});
});
it('should return an invalid recipient error if "to" is truthy but invalid', () => {
expect(getToErrorObject('mockInvalidTo')).toStrictEqual({
to: INVALID_RECIPIENT_ADDRESS_ERROR,
});
});
it('should return null if "to" is truthy and valid', () => {
expect(getToErrorObject('0xabc123')).toStrictEqual({
to: null,
});
});
it('should return a contract address error if the recipient is the same as the tokens contract address', () => {
expect(getToErrorObject('0xabc123', '0xabc123')).toStrictEqual({
to: CONTRACT_ADDRESS_ERROR,
});
});
it('should return null if the recipient address is not the token contract address', () => {
expect(getToErrorObject('0xabc123', '0xabc456')).toStrictEqual({
to: null,
});
});
});
describe('getToWarningObject()', () => {
it('should return a known address recipient error if "to" is a token address', () => {
expect(
getToWarningObject('0xabc123', [{ address: '0xabc123' }], {
address: '0xabc123',
}),
).toStrictEqual({
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
});
});
it('should null if "to" is a token address but sendToken is falsy', () => {
expect(
getToWarningObject('0xabc123', [{ address: '0xabc123' }]),
).toStrictEqual({
to: null,
});
});
it('should return a known address recipient error if "to" is part of contract metadata', () => {
expect(
getToWarningObject(
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
[{ address: '0xabc123' }],
{ address: '0xabc123' },
),
).toStrictEqual({
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
});
});
it('should null if "to" is part of contract metadata but sendToken is falsy', () => {
expect(
getToWarningObject(
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
[{ address: '0xabc123' }],
{ address: '0xabc123' },
),
).toStrictEqual({
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
});
});
it('should warn if name is a valid domain and confusable', () => {
expect(getToWarningObject('demo.eth')).toStrictEqual({
to: CONFUSING_ENS_ERROR,
});
});
it('should not warn if name is a valid domain and not confusable', () => {
expect(getToWarningObject('vitalik.eth')).toStrictEqual({
to: null,
});
});
});
});