Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorLift committed Feb 16, 2024
1 parent 161806d commit 6be2657
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 120 deletions.
83 changes: 43 additions & 40 deletions packages/assets-controllers/src/TokenDetectionController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type NetworkState,
type NetworkConfiguration,
type NetworkController,
ProviderConfig,

Check failure on line 16 in packages/assets-controllers/src/TokenDetectionController.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (20.x)

'ProviderConfig' is defined but never used
} from '@metamask/network-controller';
import {
getDefaultPreferencesState,
Expand Down Expand Up @@ -138,8 +139,11 @@ function buildTokenDetectionControllerMessenger(
return controllerMessenger.getRestricted({
name: controllerName,
allowedActions: [
'AccountsController:getSelectedAccount',
'KeyringController:getState',
'NetworkController:getNetworkClientById',
'NetworkController:getNetworkConfigurationByNetworkClientId',
'NetworkController:getProviderConfig',
'TokensController:getState',
'TokensController:addDetectedTokens',
'TokenListController:getState',
Expand Down Expand Up @@ -541,7 +545,7 @@ describe('TokenDetectionController', () => {
clock.restore();
});

describe('when "disabled" is false', () => {
describe('when "disableLegacyInterval" is false', () => {
it('should detect new tokens after switching between accounts', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -553,7 +557,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -609,7 +613,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -664,7 +668,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -710,7 +714,7 @@ describe('TokenDetectionController', () => {
});
});

describe('when "disabled" is true', () => {
describe('when "disableLegacyInterval" is true', () => {
it('should not detect new tokens after switching between accounts', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -722,7 +726,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: true,
disableLegacyInterval: true,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -777,7 +781,7 @@ describe('TokenDetectionController', () => {
clock.restore();
});

describe('when "disabled" is false', () => {
describe('when "disableLegacyInterval" is false', () => {
it('should detect new tokens after switching between accounts', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -789,7 +793,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -847,7 +851,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -904,7 +908,7 @@ describe('TokenDetectionController', () => {
);
});

it('should not detect new tokens after switching between account if token detection is disabled', async () => {
it('should not detect new tokens after switching between account if token detection is disableLegacyInterval', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
});
Expand All @@ -915,7 +919,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -963,7 +967,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1015,7 +1019,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -1064,7 +1068,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1114,7 +1118,7 @@ describe('TokenDetectionController', () => {
});
});

describe('when "disabled" is true', () => {
describe('when "disableLegacyInterval" is true', () => {
it('should not detect new tokens after switching between accounts', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -1126,7 +1130,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: true,
disableLegacyInterval: true,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress: firstSelectedAddress,
Expand Down Expand Up @@ -1174,7 +1178,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: true,
disableLegacyInterval: true,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1233,7 +1237,7 @@ describe('TokenDetectionController', () => {
clock.restore();
});

describe('when "disabled" is false', () => {
describe('when "disableLegacyInterval" is false', () => {
it('should detect new tokens after switching network client id', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -1242,7 +1246,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1299,7 +1303,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1351,7 +1355,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1399,7 +1403,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1441,7 +1445,7 @@ describe('TokenDetectionController', () => {
});
});

describe('when "disabled" is true', () => {
describe('when "disableLegacyInterval" is true', () => {
it('should not detect new tokens after switching network client id', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -1450,7 +1454,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: true,
disableLegacyInterval: true,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1501,7 +1505,7 @@ describe('TokenDetectionController', () => {
clock.restore();
});

describe('when "disabled" is false', () => {
describe('when "disableLegacyInterval" is false', () => {
it('should detect tokens if the token list is non-empty', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -1510,7 +1514,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1567,7 +1571,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1603,7 +1607,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1643,7 +1647,7 @@ describe('TokenDetectionController', () => {
});
});

describe('when "disabled" is true', () => {
describe('when "disableLegacyInterval" is true', () => {
it('should not detect tokens', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
Expand All @@ -1652,7 +1656,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: true,
disableLegacyInterval: true,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1709,7 +1713,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1768,15 +1772,15 @@ describe('TokenDetectionController', () => {
});

describe('detectTokens', () => {
it('should not detect tokens if token detection is disabled and current network is not mainnet', async () => {
it('should not detect tokens if token detection is disableLegacyInterval and current network is not mainnet', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue({
[sampleTokenA.address]: new BN(1),
});
const selectedAddress = '0x0000000000000000000000000000000000000001';
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.goerli,
selectedAddress,
Expand All @@ -1802,7 +1806,7 @@ describe('TokenDetectionController', () => {
);
});

it('should detect and add tokens from the `@metamask/contract-metadata` legacy token list if token detection is disabled and current network is mainnet', async () => {
it('should detect and add tokens from the `@metamask/contract-metadata` legacy token list if token detection is disableLegacyInterval and current network is mainnet', async () => {
const mockGetBalancesInSingleCall = jest.fn().mockResolvedValue(
Object.keys(STATIC_MAINNET_TOKEN_LIST).reduce<Record<string, BN>>(
(acc, address) => {
Expand All @@ -1816,7 +1820,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand All @@ -1840,14 +1844,14 @@ describe('TokenDetectionController', () => {
Object.values(STATIC_MAINNET_TOKEN_LIST).map((token) => {
const newToken = {
...token,
image: token.iconUrl,
isERC721: false,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (newToken as any).erc20;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
delete (newToken as any).erc721;
delete newToken.iconUrl;
delete newToken.aggregators;
delete newToken.name;
return newToken;
}),
{
Expand All @@ -1867,7 +1871,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
networkClientId: NetworkType.mainnet,
selectedAddress,
Expand Down Expand Up @@ -1921,7 +1925,7 @@ describe('TokenDetectionController', () => {
await withController(
{
options: {
disabled: false,
disableLegacyInterval: false,
getBalancesInSingleCall: mockGetBalancesInSingleCall,
trackMetaMetricsEvent: mockTrackMetaMetricsEvent,
networkClientId: NetworkType.mainnet,
Expand Down Expand Up @@ -1986,7 +1990,6 @@ type WithControllerCallback<ReturnValue> = ({
mockKeyringGetState,
mockTokensGetState,
mockTokenListGetState,
mockPreferencesGetState,
callActionSpy,
triggerKeyringUnlock,
triggerKeyringLock,
Expand Down
Loading

0 comments on commit 6be2657

Please sign in to comment.