Skip to content

Commit

Permalink
test: improve MultichainBalancesController unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
gantunesr committed Dec 2, 2024
1 parent 425d18a commit c8e3065
Showing 1 changed file with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
CaipAssetType,
InternalAccount,
} from '@metamask/keyring-api';
import { BtcAccountType, BtcMethod } from '@metamask/keyring-api';
import { BtcAccountType, BtcMethod, EthAccountType, EthMethod } from '@metamask/keyring-api';

Check failure on line 7 in packages/assets-controllers/src/MultichainBalancesController/MultichainBalancesController.test.ts

View workflow job for this annotation

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

Replace `·BtcAccountType,·BtcMethod,·EthAccountType,·EthMethod·` with `⏎··BtcAccountType,⏎··BtcMethod,⏎··EthAccountType,⏎··EthMethod,⏎`
import { KeyringTypes } from '@metamask/keyring-controller';
import { v4 as uuidv4 } from 'uuid';

Expand Down Expand Up @@ -41,6 +41,27 @@ const mockBtcAccount = {
type: BtcAccountType.P2wpkh,
};

const mockEthAccount = {
address: '0x807dE1cf8f39E83258904b2f7b473E5C506E4aC1',
id: uuidv4(),
metadata: {
name: 'Ethereum Account 1',
importTime: Date.now(),
keyring: {
type: KeyringTypes.snap,
},
snap: {
id: 'mock-eth-snap',
name: 'mock-eth-snap',
enabled: true,
},
lastSelected: 0,
},
options: {},
methods: [EthMethod.SignTypedDataV4, EthMethod.SignTransaction],
type: EthAccountType.Eoa,
};

const mockBalanceResult = {
'bip122:000000000933ea01ad0ee984209779ba/slip44:0': {
amount: '0.00000000',
Expand Down Expand Up @@ -88,7 +109,7 @@ const setupController = ({
controllerMessenger.registerActionHandler(
'AccountsController:listMultichainAccounts',
mockListMultichainAccounts.mockReturnValue(
mocks?.listMultichainAccounts ?? [mockBtcAccount],
mocks?.listMultichainAccounts ?? [mockBtcAccount, mockEthAccount],
),
);

Expand Down Expand Up @@ -178,4 +199,22 @@ describe('BalancesController', () => {
balances: {},
});
});

it('does not track balances for EVM accounts', async () => {
const { controller, messenger, mockListMultichainAccounts } =
setupController({
mocks: {
listMultichainAccounts: [],
},
});

controller.start();
mockListMultichainAccounts.mockReturnValue([mockEthAccount]);
messenger.publish('AccountsController:accountAdded', mockEthAccount);
await controller.updateBalances();

expect(controller.state).toStrictEqual({
balances: {},
});
});
});

0 comments on commit c8e3065

Please sign in to comment.