Skip to content

Commit

Permalink
Ensure network client mock corresponds with initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
Gudahtt committed May 8, 2023
1 parent afb95de commit e8fed4e
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/network-controller/tests/NetworkController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3737,7 +3737,24 @@ function refreshNetworkTests({
buildFakeClient(fakeProviders[0]),
buildFakeClient(fakeProviders[1]),
];
const networkClientOptions: Parameters<typeof createNetworkClient>[0] =
const initializationNetworkClientOptions: Parameters<
typeof createNetworkClient
>[0] =
controller.state.providerConfig.type === NetworkType.rpc
? {
chainId: toHex(controller.state.providerConfig.chainId),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
rpcUrl: controller.state.providerConfig.rpcUrl!,
type: NetworkClientType.Custom,
}
: {
network: controller.state.providerConfig.type,
infuraProjectId: 'infura-project-id',
type: NetworkClientType.Infura,
};
const operationNetworkClientOptions: Parameters<
typeof createNetworkClient
>[0] =
expectedProviderConfig.type === NetworkType.rpc
? {
chainId: toHex(expectedProviderConfig.chainId),
Expand All @@ -3751,13 +3768,9 @@ function refreshNetworkTests({
type: NetworkClientType.Infura,
};
mockCreateNetworkClient()
.calledWith({
network: NetworkType.mainnet,
infuraProjectId: 'infura-project-id',
type: NetworkClientType.Infura,
})
.calledWith(initializationNetworkClientOptions)
.mockReturnValue(fakeNetworkClients[0])
.calledWith(networkClientOptions)
.calledWith(operationNetworkClientOptions)
.mockReturnValue(fakeNetworkClients[1]);
await controller.initializeProvider();
const { provider: providerBefore } =
Expand Down

0 comments on commit e8fed4e

Please sign in to comment.