2023-02-02 19:56:41 +01:00
|
|
|
import Bowser from 'bowser';
|
2021-05-17 21:00:59 +02:00
|
|
|
import { BN } from 'ethereumjs-util';
|
2023-03-21 17:28:38 +01:00
|
|
|
import { CHAIN_IDS } from '../../../shared/constants/network';
|
2022-09-16 21:05:21 +02:00
|
|
|
import { addHexPrefixToObjectValues } from '../../../shared/lib/swaps-utils';
|
|
|
|
import { toPrecisionWithoutTrailingZeros } from '../../../shared/lib/transactions-controller-utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
import * as util from './util';
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('util', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let ethInWei = '1';
|
2019-12-03 15:52:01 +01:00
|
|
|
for (let i = 0; i < 18; i++) {
|
2021-02-04 19:15:23 +01:00
|
|
|
ethInWei += '0';
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#parseBalance', () => {
|
|
|
|
it('should render 0.01 eth correctly', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x2386F26FC10000';
|
|
|
|
const output = util.parseBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(output).toStrictEqual(['0', '01']);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-11 22:57:47 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render 12.023 eth correctly', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = 'A6DA46CCA6858000';
|
|
|
|
const output = util.parseBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(output).toStrictEqual(['12', '023']);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-11 22:57:47 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render 0.0000000342422 eth correctly', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x7F8FE81C0';
|
|
|
|
const output = util.parseBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(output).toStrictEqual(['0', '0000000342422']);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-11 22:57:47 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should render 0 eth correctly', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x0';
|
|
|
|
const output = util.parseBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(output).toStrictEqual(['0', '0']);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2016-05-26 03:29:03 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#addressSummary', () => {
|
|
|
|
it('should add case-sensitive checksum', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825';
|
|
|
|
const result = util.addressSummary(address);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('0xFDEa65C8...b825');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-07 02:58:46 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should accept arguments for firstseg, lastseg, and keepPrefix', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const address = '0xfdea65c8e26263f6d9a1b5de9555d2931a33b825';
|
|
|
|
const result = util.addressSummary(address, 4, 4, false);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('FDEa...b825');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2016-05-19 21:06:45 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('isValidDomainName', () => {
|
|
|
|
it('should return true when given a valid domain name', () => {
|
|
|
|
expect(util.isValidDomainName('foo.bar')).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when given a valid subdomain', () => {
|
|
|
|
expect(util.isValidDomainName('foo.foo.bar')).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when given a single-character domain', () => {
|
|
|
|
expect(util.isValidDomainName('f.bar')).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when given a unicode TLD', () => {
|
|
|
|
expect(util.isValidDomainName('台灣.中国')).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a domain with unacceptable ASCII characters', () => {
|
|
|
|
expect(util.isValidDomainName('$.bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a TLD that starts with a dash', () => {
|
|
|
|
expect(util.isValidDomainName('foo.-bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a TLD that ends with a dash', () => {
|
|
|
|
expect(util.isValidDomainName('foo.bar-')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a domain name with a chunk that starts with a dash', () => {
|
|
|
|
expect(util.isValidDomainName('-foo.bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a domain name with a chunk that ends with a dash', () => {
|
|
|
|
expect(util.isValidDomainName('foo-.bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a bare TLD', () => {
|
|
|
|
expect(util.isValidDomainName('bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a domain that starts with a period', () => {
|
|
|
|
expect(util.isValidDomainName('.bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a subdomain that starts with a period', () => {
|
|
|
|
expect(util.isValidDomainName('.foo.bar')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a domain that ends with a period', () => {
|
|
|
|
expect(util.isValidDomainName('bar.')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when given a 1-character TLD', () => {
|
|
|
|
expect(util.isValidDomainName('foo.b')).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-02-18 02:20:01 +01:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('isOriginContractAddress', () => {
|
|
|
|
it('should return true when the send address is the same as the selected tokens contract address', () => {
|
|
|
|
expect(
|
2021-03-03 01:28:12 +01:00
|
|
|
util.isOriginContractAddress(
|
|
|
|
'0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
'0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
2021-03-03 01:28:12 +01:00
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when the send address is the same as the selected tokens contract address, capitalized input', () => {
|
|
|
|
expect(
|
2021-03-03 01:28:12 +01:00
|
|
|
util.isOriginContractAddress(
|
|
|
|
'0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
'0X8D6B81208414189A58339873AB429B6C47AB92D3',
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(true);
|
2021-03-03 01:28:12 +01:00
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when the recipient address differs', () => {
|
|
|
|
expect(
|
2021-03-03 01:28:12 +01:00
|
|
|
util.isOriginContractAddress(
|
|
|
|
'0x8d6b81208414189a58339873ab429b6c47ab92d3',
|
|
|
|
'0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B',
|
|
|
|
),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual(false);
|
2021-03-03 01:28:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#numericBalance', () => {
|
|
|
|
it('should return a BN 0 if given nothing', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.numericBalance();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.toString(10)).toStrictEqual('0');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should work with hex prefix', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.numericBalance('0x012');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.toString(10)).toStrictEqual('18');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should work with no hex prefix', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.numericBalance('012');
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.toString(10)).toStrictEqual('18');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#formatBalance', () => {
|
|
|
|
it('should return None when given nothing', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.formatBalance();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('None', 'should return "None"');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-07 20:20:02 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return 1.0000 ETH', () => {
|
2021-04-16 17:05:13 +02:00
|
|
|
const input = new BN(ethInWei, 10).toJSON();
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.formatBalance(input, 4);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('1.0000 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-07-07 20:20:02 +02:00
|
|
|
|
2021-04-16 17:05:13 +02:00
|
|
|
it('should return 0.500 ETH', function () {
|
|
|
|
const input = new BN(ethInWei, 10).div(new BN('2', 10)).toJSON();
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.formatBalance(input, 3);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('0.500 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2016-04-14 22:20:19 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should display specified decimal points', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x128dfa6a90b28000';
|
|
|
|
const result = util.formatBalance(input, 2);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('1.33 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should default to 3 decimal points', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x128dfa6a90b28000';
|
|
|
|
const result = util.formatBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('1.337 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should show 2 significant digits for tiny balances', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const input = '0x1230fa6a90b28';
|
|
|
|
const result = util.formatBalance(input);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('0.00032 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should not parse the balance and return value with 2 decimal points with ETH at the end', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const value = '1.2456789';
|
|
|
|
const needsParse = false;
|
|
|
|
const result = util.formatBalance(value, 2, needsParse);
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result).toStrictEqual('1.24 ETH');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2023-02-02 19:56:41 +01:00
|
|
|
describe('#getIsBrowserDeprecated', () => {
|
|
|
|
it('should call Bowser.getParser when no parameter is passed', () => {
|
|
|
|
const spy = jest.spyOn(Bowser, 'getParser');
|
|
|
|
util.getIsBrowserDeprecated();
|
|
|
|
expect(spy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
it('should return false when given a modern chrome browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.2623.112 Safari/537.36',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
it('should return true when given an outdated chrome browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.2623.112 Safari/537.36',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
it('should return false when given a modern firefox browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/91.0',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
it('should return true when given an outdated firefox browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/90.0',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
it('should return false when given a modern opera browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.3578.98 Safari/537.36 OPR/76.0.3135.47',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
it('should return true when given an outdated opera browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_16_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.3578.98 Safari/537.36 OPR/58.0.3135.47',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
it('should return false when given a modern edge browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.3578.98 Safari/537.36 Edg/90.0.416.68',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
it('should return true when given an outdated edge browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
2023-04-21 16:33:46 +02:00
|
|
|
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.3578.98 Safari/537.36 Edge/89.0.416.68',
|
2023-02-02 19:56:41 +01:00
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
it('should return false when given an unknown browser', () => {
|
|
|
|
const browser = Bowser.getParser(
|
|
|
|
'Mozilla/5.0 (Nintendo Switch; WebApplet) AppleWebKit/609.4 (KHTML, like Gecko) NF/6.0.2.21.3 NintendoBrowser/5.1.0.22474',
|
|
|
|
);
|
|
|
|
const result = util.getIsBrowserDeprecated(browser);
|
|
|
|
expect(result).toStrictEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-04-16 17:05:13 +02:00
|
|
|
describe('normalizing values', function () {
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('#getRandomFileName', () => {
|
|
|
|
it('should only return a string containing alphanumeric characters', () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.getRandomFileName();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result[0]).toStrictEqual(
|
|
|
|
expect.stringMatching(/^[a-zA-Z0-9]*$/gu),
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-22 02:22:55 +01:00
|
|
|
|
|
|
|
// 50 samples
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return a string that is between 6 and 12 characters in length', () => {
|
2020-01-22 02:22:55 +01:00
|
|
|
for (let i = 0; i < 50; i++) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const result = util.getRandomFileName();
|
2021-04-15 20:01:46 +02:00
|
|
|
expect(result.length >= 6 && result.length <= 12).toStrictEqual(true);
|
2020-01-22 02:22:55 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('checkExistingAddresses', () => {
|
2020-07-08 00:18:18 +02:00
|
|
|
const tokenList = [
|
|
|
|
{ address: 'A' },
|
|
|
|
{ address: 'n' },
|
|
|
|
{ address: 'Q' },
|
|
|
|
{ address: 'z' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when a lowercase address matches an uppercase address in the passed list', () => {
|
|
|
|
expect(util.checkExistingAddresses('q', tokenList)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when an uppercase address matches a lowercase address in the passed list', () => {
|
|
|
|
expect(util.checkExistingAddresses('N', tokenList)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when a lowercase address matches a lowercase address in the passed list', () => {
|
|
|
|
expect(util.checkExistingAddresses('z', tokenList)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return true when an uppercase address matches an uppercase address in the passed list', () => {
|
|
|
|
expect(util.checkExistingAddresses('Q', tokenList)).toStrictEqual(true);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-07-08 00:18:18 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should return false when the passed address is not in the passed list', () => {
|
|
|
|
expect(util.checkExistingAddresses('b', tokenList)).toStrictEqual(false);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2020-08-19 16:04:50 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('toPrecisionWithoutTrailingZeros', () => {
|
2020-08-19 16:04:50 +02:00
|
|
|
const testData = [
|
|
|
|
{ args: ['0', 9], result: '0' },
|
|
|
|
{ args: [0, 9], result: '0' },
|
|
|
|
{ args: ['0.0', 9], result: '0' },
|
|
|
|
{ args: ['0.000000000000', 9], result: '0' },
|
|
|
|
{ args: ['1', 9], result: '1' },
|
2020-08-19 18:27:05 +02:00
|
|
|
{ args: [1], result: '1' },
|
2020-08-19 16:04:50 +02:00
|
|
|
{ args: ['1.0', 9], result: '1' },
|
|
|
|
{ args: ['1.000000000', 9], result: '1' },
|
|
|
|
{ args: ['000000001', 9], result: '1' },
|
|
|
|
{ args: ['000000001.0', 9], result: '1' },
|
|
|
|
{ args: ['100000000', 9], result: '100000000' },
|
|
|
|
{ args: ['100000000.00001', 9], result: '100000000' },
|
|
|
|
{ args: ['100.00001', 9], result: '100.00001' },
|
|
|
|
{ args: ['100.00001000', 9], result: '100.00001' },
|
|
|
|
{ args: ['100.000010001', 9], result: '100.00001' },
|
|
|
|
{ args: ['10.010101', 9], result: '10.010101' },
|
|
|
|
{ args: ['0.1', 5], result: '0.1' },
|
|
|
|
{ args: ['0.10', 5], result: '0.1' },
|
|
|
|
{ args: ['0.1010', 5], result: '0.101' },
|
|
|
|
{ args: ['0.01001', 5], result: '0.01001' },
|
|
|
|
{ args: ['0.010010', 5], result: '0.01001' },
|
|
|
|
{ args: ['0.010011', 5], result: '0.010011' },
|
|
|
|
{ args: ['1.01005', 5], result: '1.0101' },
|
|
|
|
{ args: ['1.000049', 5], result: '1' },
|
|
|
|
{ args: ['1.00005', 5], result: '1.0001' },
|
|
|
|
{ args: ['0.0000123456789', 9], result: '0.0000123456789' },
|
|
|
|
{ args: ['1.0000123456789', 10], result: '1.000012346' },
|
|
|
|
{ args: ['10000.0000012345679', 10], result: '10000' },
|
|
|
|
{ args: ['1000000000000', 10], result: '1e+12' },
|
|
|
|
{ args: ['1000050000000', 10], result: '1.00005e+12' },
|
|
|
|
{ args: ['100000000000000000000', 10], result: '1e+20' },
|
|
|
|
{ args: ['100005000000000000000', 10], result: '1.00005e+20' },
|
|
|
|
{ args: ['100005000000000000000.0', 10], result: '1.00005e+20' },
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2020-08-19 16:04:50 +02:00
|
|
|
|
|
|
|
testData.forEach(({ args, result }) => {
|
2021-04-15 20:01:46 +02:00
|
|
|
it(`should return ${result} when passed number ${args[0]} and precision ${args[1]}`, () => {
|
2022-09-16 21:05:21 +02:00
|
|
|
expect(toPrecisionWithoutTrailingZeros(...args)).toStrictEqual(result);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2020-10-06 20:28:38 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('addHexPrefixToObjectValues()', () => {
|
|
|
|
it('should return a new object with the same properties with a 0x prefix', () => {
|
|
|
|
expect(
|
2022-09-16 21:05:21 +02:00
|
|
|
addHexPrefixToObjectValues({
|
2020-10-06 20:28:38 +02:00
|
|
|
prop1: '0x123',
|
|
|
|
prop2: '456',
|
|
|
|
prop3: 'x',
|
|
|
|
}),
|
2021-04-15 20:01:46 +02:00
|
|
|
).toStrictEqual({
|
|
|
|
prop1: '0x123',
|
|
|
|
prop2: '0x456',
|
|
|
|
prop3: '0xx',
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
2021-11-18 18:54:58 +01:00
|
|
|
|
|
|
|
describe('toHumanReadableTime()', () => {
|
|
|
|
const t = (key, number) => {
|
|
|
|
switch (key) {
|
|
|
|
case 'gasTimingSecondsShort':
|
|
|
|
return `${number} sec`;
|
|
|
|
case 'gasTimingMinutesShort':
|
|
|
|
return `${number} min`;
|
|
|
|
case 'gasTimingHoursShort':
|
|
|
|
return `${number} hrs`;
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
it('should return empty string if milliseconds passed is undefined', () => {
|
|
|
|
expect(util.toHumanReadableTime(t)).toStrictEqual('');
|
|
|
|
});
|
|
|
|
it('should return rounded value for time', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 6300)).toStrictEqual('7 sec');
|
|
|
|
});
|
|
|
|
it('should return value in seconds for milliseconds passed is < 9000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 6000)).toStrictEqual('6 sec');
|
|
|
|
});
|
|
|
|
it('should return value in seconds for milliseconds passed is > 6000 and <= 9000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 9000)).toStrictEqual('9 sec');
|
|
|
|
});
|
|
|
|
it('should return value in minutes for milliseconds passed is > 90000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 90001)).toStrictEqual('2 min');
|
|
|
|
});
|
|
|
|
it('should return value in minutes for milliseconds passed is > 90000 and <= 5400000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 5400000)).toStrictEqual('90 min');
|
|
|
|
});
|
|
|
|
it('should return value in hours for milliseconds passed is > 5400000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 5400001)).toStrictEqual('2 hrs');
|
|
|
|
});
|
|
|
|
it('should return value in hours for milliseconds passed very high above 5400000', () => {
|
|
|
|
expect(util.toHumanReadableTime(t, 7200000)).toStrictEqual('2 hrs');
|
|
|
|
});
|
|
|
|
});
|
2021-12-08 21:56:09 +01:00
|
|
|
describe('sanitizeMessage', () => {
|
|
|
|
let message;
|
|
|
|
let primaryType;
|
|
|
|
let types;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
message = {
|
|
|
|
contents: 'Hello, Bob!',
|
|
|
|
from: {
|
|
|
|
name: 'Cow',
|
|
|
|
wallets: [
|
|
|
|
'0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
|
|
|
'0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
to: [
|
|
|
|
{
|
|
|
|
name: 'Bob',
|
|
|
|
wallets: [
|
|
|
|
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
'0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-11-18 17:04:52 +01:00
|
|
|
nestArray: [
|
|
|
|
[12, 34, 56],
|
|
|
|
[56, 78, 89],
|
|
|
|
],
|
2021-12-08 21:56:09 +01:00
|
|
|
};
|
|
|
|
primaryType = 'Mail';
|
|
|
|
types = {
|
|
|
|
EIP712Domain: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'version', type: 'string' },
|
|
|
|
{ name: 'chainId', type: 'uint256' },
|
|
|
|
{ name: 'verifyingContract', type: 'address' },
|
|
|
|
],
|
|
|
|
Mail: [
|
|
|
|
{ name: 'from', type: 'Person' },
|
|
|
|
{ name: 'to', type: 'Person[]' },
|
|
|
|
{ name: 'contents', type: 'string' },
|
2022-11-18 17:04:52 +01:00
|
|
|
{ name: 'nestArray', type: 'uint256[2][2]' },
|
|
|
|
{ name: 'nestedPeople', type: 'Person[][]' },
|
2021-12-08 21:56:09 +01:00
|
|
|
],
|
|
|
|
Person: [
|
|
|
|
{ name: 'name', type: 'string' },
|
|
|
|
{ name: 'wallets', type: 'address[]' },
|
|
|
|
],
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if types is undefined', () => {
|
|
|
|
expect(() =>
|
|
|
|
util.sanitizeMessage(message, primaryType, undefined),
|
|
|
|
).toThrow('Invalid types definition');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if base type is not defined', () => {
|
|
|
|
expect(() => util.sanitizeMessage(message, undefined, types)).toThrow(
|
|
|
|
'Invalid primary type definition',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return parsed message if types is defined', () => {
|
|
|
|
const result = util.sanitizeMessage(message, primaryType, types);
|
2023-02-27 17:32:51 +01:00
|
|
|
expect(result).toStrictEqual({
|
|
|
|
type: 'Mail',
|
|
|
|
value: {
|
|
|
|
contents: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Hello, Bob!',
|
|
|
|
},
|
|
|
|
from: {
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Cow',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nestArray: {
|
|
|
|
type: 'uint256[2][2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 12,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 34,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 78,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 89,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
type: 'Person[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Bob',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-12-08 21:56:09 +01:00
|
|
|
});
|
|
|
|
|
2022-11-18 17:04:52 +01:00
|
|
|
it('should return parsed nested array if defined', () => {
|
|
|
|
const result = util.sanitizeMessage(
|
|
|
|
{
|
|
|
|
nestArray: [
|
|
|
|
[12, 34, 56],
|
|
|
|
[56, 78, 89],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
primaryType,
|
|
|
|
types,
|
|
|
|
);
|
2023-02-27 17:32:51 +01:00
|
|
|
expect(result).toStrictEqual({
|
|
|
|
type: 'Mail',
|
|
|
|
value: {
|
|
|
|
nestArray: {
|
|
|
|
type: 'uint256[2][2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 12,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 34,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 78,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 89,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-11-18 17:04:52 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should return parsed nested array with struct if defined', () => {
|
|
|
|
const msg = {
|
|
|
|
nestedPeople: [
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'Bob',
|
|
|
|
wallets: [
|
|
|
|
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
'0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
name: 'Ben',
|
|
|
|
wallets: [
|
|
|
|
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
'0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Brandon',
|
|
|
|
wallets: [
|
|
|
|
'0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
'0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
'0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
],
|
|
|
|
};
|
|
|
|
const result = util.sanitizeMessage(msg, primaryType, types);
|
2023-02-27 17:32:51 +01:00
|
|
|
expect(result).toStrictEqual({
|
|
|
|
type: 'Mail',
|
|
|
|
value: {
|
|
|
|
nestedPeople: {
|
|
|
|
type: 'Person[][]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'Person[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Bob',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Person[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Ben',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Brandon',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-11-18 17:04:52 +01:00
|
|
|
});
|
|
|
|
|
2021-12-08 21:56:09 +01:00
|
|
|
it('should return ignore message data with unknown types', () => {
|
|
|
|
message.do_not_display = 'one';
|
|
|
|
message.do_not_display_2 = {
|
|
|
|
do_not_display: 'two',
|
|
|
|
};
|
|
|
|
|
|
|
|
// result will NOT contain the do_not_displays because type definition
|
|
|
|
const result = util.sanitizeMessage(message, primaryType, types);
|
2023-02-27 17:32:51 +01:00
|
|
|
expect(result).toStrictEqual({
|
|
|
|
type: 'Mail',
|
|
|
|
value: {
|
|
|
|
contents: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Hello, Bob!',
|
|
|
|
},
|
|
|
|
from: {
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Cow',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nestArray: {
|
|
|
|
type: 'uint256[2][2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 12,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 34,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256[2]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 56,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 78,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'uint256',
|
|
|
|
value: 89,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
to: {
|
|
|
|
type: 'Person[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'Person',
|
|
|
|
value: {
|
|
|
|
name: {
|
|
|
|
type: 'string',
|
|
|
|
value: 'Bob',
|
|
|
|
},
|
|
|
|
wallets: {
|
|
|
|
type: 'address[]',
|
|
|
|
value: [
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'address',
|
|
|
|
value: '0xB0B0b0b0b0b0B000000000000000000000000000',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-12-08 21:56:09 +01:00
|
|
|
});
|
|
|
|
});
|
2023-03-10 14:36:07 +01:00
|
|
|
|
|
|
|
describe('sanitizeString', () => {
|
|
|
|
it('should return the passed value, unchanged, if it is falsy', () => {
|
|
|
|
expect(util.sanitizeString('')).toStrictEqual('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return the passed value, unchanged, if it is not a string', () => {
|
|
|
|
expect(util.sanitizeString(true)).toStrictEqual(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a truthy string that oes not match the sanitizeString regex, unchanged', () => {
|
|
|
|
expect(
|
|
|
|
util.sanitizeString('The Quick Brown Fox Jumps Over The Lazy Dog'),
|
|
|
|
).toStrictEqual('The Quick Brown Fox Jumps Over The Lazy Dog');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a string that matches sanitizeString regex with the matched characters replaced', () => {
|
|
|
|
expect(
|
|
|
|
util.sanitizeString(
|
|
|
|
'The Quick Brown \u202EFox Jumps Over The Lazy Dog',
|
|
|
|
),
|
|
|
|
).toStrictEqual('The Quick Brown \\u202EFox Jumps Over The Lazy Dog');
|
|
|
|
});
|
|
|
|
});
|
2023-03-21 17:28:38 +01:00
|
|
|
|
|
|
|
describe('isDefaultMetaMaskChain()', () => {
|
|
|
|
it('should return true if the provided chainId is a default MetaMask chain', () => {
|
|
|
|
expect(util.isDefaultMetaMaskChain(CHAIN_IDS.GOERLI)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return false if the provided chainId is a not default MetaMask chain', () => {
|
|
|
|
expect(util.isDefaultMetaMaskChain(CHAIN_IDS.CELO)).toBeFalsy();
|
|
|
|
});
|
|
|
|
});
|
2023-05-18 15:53:11 +02:00
|
|
|
|
|
|
|
describe('getNetworkNameFromProviderType()', () => {
|
|
|
|
it('should return providerConfig.type if the type is not rpc', () => {
|
|
|
|
expect(util.getNetworkNameFromProviderType('mainnet')).toStrictEqual(
|
|
|
|
'mainnet',
|
|
|
|
);
|
|
|
|
});
|
|
|
|
it('should return empty string if teh providerConfig.type is rpc', () => {
|
|
|
|
expect(util.getNetworkNameFromProviderType('rpc')).toStrictEqual('');
|
|
|
|
});
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|