Skip to content

Commit

Permalink
Fixed brittle TokenListController test (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
BelfordZ authored Sep 7, 2022
1 parent 8a6ceb2 commit bea14f9
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions src/assets/TokenListController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,10 @@ function getRestrictedMessenger() {
const messenger = controllerMessenger.getRestricted<
'TokenListController',
never,
never
TokenListStateChange['type']
>({
name,
allowedEvents: ['TokenListController:stateChange'],
});
return messenger;
}
Expand Down Expand Up @@ -1060,21 +1061,33 @@ describe('TokenListController', () => {
preventPollingOnNetworkRestart: false,
});

network.update({
provider: {
type: 'rpc',
chainId: '56',
},
await new Promise((resolve: any) => {
messenger.subscribe('TokenListController:stateChange', (_, patch) => {
const tokenListChanged = patch.find(
(p) => Object.keys(p.value.tokenList).length !== 0,
);
if (!tokenListChanged) {
return;
}

expect(controller.state.tokenList).toStrictEqual(
sampleTwoChainState.tokenList,
);

expect(controller.state.tokensChainsCache['56'].data).toStrictEqual(
sampleTwoChainState.tokensChainsCache['56'].data,
);
messenger.clearEventSubscriptions('TokenListController:stateChange');
controller.destroy();
resolve();
});

network.update({
provider: {
type: 'rpc',
chainId: '56',
},
});
});
await new Promise<void>((resolve) => setTimeout(() => resolve(), 10));
expect(controller.state.tokenList).toStrictEqual(
sampleTwoChainState.tokenList,
);

expect(controller.state.tokensChainsCache['56'].data).toStrictEqual(
sampleTwoChainState.tokensChainsCache['56'].data,
);

controller.destroy();
});
});

0 comments on commit bea14f9

Please sign in to comment.