Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tuul-wq committed Oct 10, 2024
1 parent 7fc0202 commit dc52a4b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/models/network/network-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,36 @@ describe('@/common/network/network-model', () => {
});
});

test('should connect to default_chains and filter out wrong Karura asset on networkStarted event', async () => {
vi.spyOn(chainsApi, 'getChainsData').mockResolvedValue(mockedChains);

// Karura (index 2) and chain (index 19) that's missing in chains.json
const getItem = (_: string, cb: (_: null, result: string) => void) => cb(null, '2_3;19_0,2,3;');

window.Telegram = { WebApp: { CloudStorage: { getItem } } } as any;

const scope = fork({
handlers: [[effectMocks.createProviderFx.fx, effectMocks.createProviderFx.data()]],
});

await allSettled(networkModel.input.networkStarted, { scope, params: 'chains_dev' });

expect(scope.getState(networkModel.$assets)).toEqual({
[mockedChains[0].chainId]: { 0: { assetId: 0 } },
[mockedChains[1].chainId]: { 0: { assetId: 0 } },
[mockedChains[3].chainId]: { 1: { assetId: 1 } },
});

const connection = { provider: expect.any(Object), api: expect.any(Object) };
expect(scope.getState(networkModel.$connections)).toEqual({
[mockedChains[0].chainId]: { ...connection, status: 'connected' }, // Polkadot
[mockedChains[1].chainId]: { ...connection, status: 'connected' }, // Kusama
[mockedChains[2].chainId]: { status: 'disconnected' }, // Karura
[mockedChains[3].chainId]: { ...connection, status: 'connected' }, // Polkadot Asset Hub
[mockedChains[4].chainId]: { status: 'disconnected' }, // Westend
});
});

test('should connect to Karura on assetConnected event', async () => {
const scope = fork({
values: [
Expand Down
2 changes: 2 additions & 0 deletions app/models/network/network-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const $sortedAssets = combine($assets, assets => {
const chainToPresort = DEFAULT_CHAINS_ORDER[typedChainId];

for (const asset of Object.values(assetMap)) {
if (!asset) continue;

if (!chainToPresort || !(asset.assetId in chainToPresort)) {
assetsToSort.push([typedChainId, asset]);
} else {
Expand Down

0 comments on commit dc52a4b

Please sign in to comment.