Skip to content

Commit

Permalink
fix: add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
salimtb committed Dec 3, 2024
1 parent c71e977 commit 3681c95
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,57 @@ describe('TokensController', () => {
);
});

it('should add tokens to allIgnoredTokens state only if we are not using current network', async () => {
const selectedAddress = '0x0001';
const selectedAccount = createMockInternalAccount({
address: selectedAddress,
});

await withController(
{
mocks: {
getSelectedAccount: selectedAccount,
getAccount: selectedAccount,
},
},
async ({ controller, triggerSelectedAccountChange, changeNetwork }) => {
// Select the first account
triggerSelectedAccountChange(selectedAccount);

// Add tokens to sepolia
changeNetwork({ selectedNetworkClientId: InfuraNetworkType.sepolia });
await controller.addToken({
address: '0x01',
symbol: 'Token1',
decimals: 18,
});
expect(controller.state.tokens).toHaveLength(1);
expect(controller.state.ignoredTokens).toHaveLength(0);

// switch to goerli
changeNetwork({ selectedNetworkClientId: InfuraNetworkType.goerli });

// Add tokens to goerli
await controller.addToken({
address: '0x02',
symbol: 'Token2',
decimals: 8,
});

expect(controller.state.tokens).toHaveLength(1);
expect(controller.state.ignoredTokens).toHaveLength(0);

// ignore token on sepolia
controller.ignoreTokens(['0x01'], InfuraNetworkType.sepolia);

// as we are not on sepolia, tokens, ignoredTokens, and detectedTokens should not be affected
expect(controller.state.tokens).toHaveLength(1);
expect(controller.state.ignoredTokens).toHaveLength(0);
expect(controller.state.detectedTokens).toHaveLength(0);
},
);
});

it('should not retain ignored tokens from a different network', async () => {
const selectedAddress = '0x0001';
const selectedAccount = createMockInternalAccount({
Expand Down

0 comments on commit 3681c95

Please sign in to comment.