1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/hooks/useAddressDetails.test.js
Niranjana Binoy 6e5c2f03bf
Token detection V2 Flag Removal and Re-introducing the use of legacy token list when token detection is OFF (#15138)
* addding the legacy tokenlist, tuning token detection OFF by default, adding new message while importing tokens

updating the controller version and calling detectNewToken on network change

fixing rebase error

Run yarn lavamoat:auto for updating policies

updating lavamoat

Deleted node modules and run again lavamoat auto

fixing rebase issues

updating lavamoat policies

updating lavamoat after rebasing

policies

updating custom token warning and blocking detectedtoken link when tpken detection is off for supported networks

to update the token in fetchTosync

updating the contract map object

Revert build-system lavamoat policy changes

Move token list selection logic from components to getTokenList selector

updating the tokenList

Update lavamoat

Fix error

updating lavamoat

lint fix

fix unit test fail

fix unit test fail

lint fix

fixing rebase locale error

rebase fix

Revert build-system policy changes

temp

addressing review comments

* rebase fix
2022-08-09 22:56:25 -02:30

103 lines
3.0 KiB
JavaScript

import React from 'react';
import { Provider } from 'react-redux';
import { renderHook } from '@testing-library/react-hooks';
import configureStore from '../store/store';
import useAddressDetails from './useAddressDetails';
const renderUseAddressDetails = (toAddress, stateVariables = {}) => {
const mockState = {
metamask: {
provider: {
type: 'test',
chainId: '0x3',
},
tokenList: {},
...stateVariables,
},
};
const wrapper = ({ children }) => (
<Provider store={configureStore(mockState)}>{children}</Provider>
);
return renderHook(() => useAddressDetails(toAddress), { wrapper });
};
describe('useAddressDetails', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return empty object if no address is passed', () => {
const { result } = renderUseAddressDetails();
expect(result.current).toStrictEqual({});
});
it('should return name from addressBook if address is present in addressBook', () => {
const { result } = renderUseAddressDetails(
'0x06195827297c7A80a443b6894d3BDB8824b43896',
{
addressBook: {
'0x3': {
'0x06195827297c7A80a443b6894d3BDB8824b43896': {
address: '0x06195827297c7A80a443b6894d3BDB8824b43896',
name: 'Address Book Account 1',
chainId: '0x3',
},
},
},
},
);
const { toName, isTrusted } = result.current;
expect(toName).toBe('Address Book Account 1');
expect(isTrusted).toBe(true);
});
it('should return name from identities if address is present in identities', () => {
const { result } = renderUseAddressDetails(
'0x06195827297c7A80a443b6894d3BDB8824b43896',
{
identities: {
'0x06195827297c7A80a443b6894d3BDB8824b43896': {
address: '0x06195827297c7A80a443b6894d3BDB8824b43896',
name: 'Account 1',
},
},
},
);
const { toName, isTrusted } = result.current;
expect(toName).toBe('Account 1');
expect(isTrusted).toBe(true);
});
it('should return name from tokenlist if address is present in tokens', () => {
const { result } = renderUseAddressDetails(
'0x06195827297c7A80a443b6894d3BDB8824b43896',
{
useTokenDetection: true,
tokenList: {
'0x06195827297c7a80a443b6894d3bdb8824b43896': {
address: '0x06195827297c7a80a443b6894d3bdb8824b43896',
symbol: 'LINK',
decimals: 18,
name: 'TOKEN-ABC',
},
},
},
);
const { toName, isTrusted } = result.current;
expect(toName).toBe('TOKEN-ABC');
expect(isTrusted).toBe(true);
});
it('should return shortened address if address is not presend in any of above sources', () => {
const { result } = renderUseAddressDetails(
'0x06195827297c7A80a443b6894d3BDB8824b43896',
);
const { toName, isTrusted } = result.current;
expect(toName).toBe('0x061...3896');
expect(isTrusted).toBe(false);
});
});