1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 02:10:12 +01:00
metamask-extension/ui/hooks/useAddressDetails.test.js
ryanml 0bc1eeaf37
Deprecating the Rinkeby, Ropsten, and Kovan test networks (#15989)
* Deprecating Rinkeby, setting default debug network to Goerli

* Deprecating Ropsten and Kovan

* Conflict fix

* Remove unused localization, test fixes

* Add migration for moving used deprecated testnets to custom networks

* Fix migrator test

* Add more unit tests

* Migration updates provider type to rpc if deprecated network is selected

* Migration fully and correctly updates the provider if selected network is a deprecated testnet

* Continue to show deprecation warning on each of rinkeby, ropsten and kovan

* Add rpcUrl deprecation message to loading screen

* Removing mayBeFauceting prop

Co-authored-by: Dan Miller <danjm.com@gmail.com>
2022-09-28 20:26:01 -07:00

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: '0x5',
},
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: {
'0x5': {
'0x06195827297c7A80a443b6894d3BDB8824b43896': {
address: '0x06195827297c7A80a443b6894d3BDB8824b43896',
name: 'Address Book Account 1',
chainId: '0x5',
},
},
},
},
);
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);
});
});