1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/app/pages/send/send-content/add-recipient/tests/add-recipient-utils.test.js
ty b04120dd0f
Warn users when an ENS name contains 'confusable' characters (#9187)
* Add warning system for 'confusable' ENS names (#9129)

Uses unicode.org's TR39 confusables.txt to display a warning when
'confusable' unicode points are detected.

Currently only the `AddRecipient` component has been updated, but the new
`Confusable` component could be used elsewhere

The new `unicode-confusables` dependency adds close to 100KB to the
bundle size, and around 30KB when gzipped.

Adds 'tag' prop to the tooltop-v2 component

Use $Red-500 for confusable ens warning

Lint Tooltip component

Update copy for confusing ENS domain warning.

* Fix prop type

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-02-27 01:56:04 -03:30

111 lines
3.1 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import assert from 'assert';
import proxyquire from 'proxyquire';
import sinon from 'sinon';
import {
REQUIRED_ERROR,
INVALID_RECIPIENT_ADDRESS_ERROR,
KNOWN_RECIPIENT_ADDRESS_ERROR,
CONFUSING_ENS_ERROR,
} from '../../../send.constants';
const stubs = {
isValidAddress: sinon
.stub()
.callsFake((to) => Boolean(to.match(/^[0xabcdef123456798]+$/u))),
};
const toRowUtils = proxyquire('../add-recipient.js', {
'../../../../helpers/utils/util': {
isValidAddress: stubs.isValidAddress,
},
});
const { getToErrorObject, getToWarningObject } = toRowUtils;
describe('add-recipient utils', function () {
describe('getToErrorObject()', function () {
it('should return a required error if "to" is falsy', function () {
assert.deepStrictEqual(getToErrorObject(null), {
to: REQUIRED_ERROR,
});
});
it('should return null if "to" is falsy and hexData is truthy', function () {
assert.deepStrictEqual(getToErrorObject(null, true), {
to: null,
});
});
it('should return an invalid recipient error if "to" is truthy but invalid', function () {
assert.deepStrictEqual(getToErrorObject('mockInvalidTo'), {
to: INVALID_RECIPIENT_ADDRESS_ERROR,
});
});
it('should return null if "to" is truthy and valid', function () {
assert.deepStrictEqual(getToErrorObject('0xabc123'), {
to: null,
});
});
});
describe('getToWarningObject()', function () {
it('should return a known address recipient error if "to" is a token address', function () {
assert.deepStrictEqual(
getToWarningObject('0xabc123', [{ address: '0xabc123' }], {
address: '0xabc123',
}),
{
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
},
);
});
it('should null if "to" is a token address but sendToken is falsy', function () {
assert.deepStrictEqual(
getToWarningObject('0xabc123', [{ address: '0xabc123' }]),
{
to: null,
},
);
});
it('should return a known address recipient error if "to" is part of contract metadata', function () {
assert.deepStrictEqual(
getToWarningObject(
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
[{ address: '0xabc123' }],
{ address: '0xabc123' },
),
{
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
},
);
});
it('should null if "to" is part of contract metadata but sendToken is falsy', function () {
assert.deepStrictEqual(
getToWarningObject(
'0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
[{ address: '0xabc123' }],
{ address: '0xabc123' },
),
{
to: KNOWN_RECIPIENT_ADDRESS_ERROR,
},
);
});
it('should warn if name is a valid domain and confusable', function () {
assert.deepEqual(getToWarningObject('vitalik.eth'), {
to: CONFUSING_ENS_ERROR,
});
});
it('should not warn if name is a valid domain and not confusable', function () {
assert.deepEqual(getToWarningObject('vitalik.eth'), {
to: null,
});
});
});
});