Skip to content

Commit e936134

Browse files
committed
fix test
1 parent e4abe62 commit e936134

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

packages/gas-fee-controller/src/GasFeeController.test.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ControllerMessenger } from '@metamask/base-controller';
22
import { NetworkType, toHex } from '@metamask/controller-utils';
33
import EthQuery from '@metamask/eth-query';
4-
import { NetworkController } from '@metamask/network-controller';
4+
import { NetworkController, NetworkStatus } from '@metamask/network-controller';
55
import type {
6+
NetworkControllerGetEIP1559CompatibilityAction,
67
NetworkControllerGetNetworkClientByIdAction,
78
NetworkControllerGetStateAction,
89
NetworkControllerNetworkDidChangeEvent,
@@ -43,7 +44,8 @@ const name = 'GasFeeController';
4344
type MainControllerMessenger = ControllerMessenger<
4445
| GetGasFeeState
4546
| NetworkControllerGetStateAction
46-
| NetworkControllerGetNetworkClientByIdAction,
47+
| NetworkControllerGetNetworkClientByIdAction
48+
| NetworkControllerGetEIP1559CompatibilityAction,
4749
| GasFeeStateChange
4850
| NetworkControllerStateChangeEvent
4951
| NetworkControllerNetworkDidChangeEvent
@@ -67,6 +69,7 @@ const setupNetworkController = async ({
6769
allowedActions: [
6870
'NetworkController:getState',
6971
'NetworkController:getNetworkClientById',
72+
'NetworkController:getEIP1559Compatibility',
7073
],
7174
allowedEvents: [
7275
'NetworkController:stateChange',
@@ -98,6 +101,7 @@ const getRestrictedMessenger = (
98101
allowedActions: [
99102
'NetworkController:getState',
100103
'NetworkController:getNetworkClientById',
104+
'NetworkController:getEIP1559Compatibility',
101105
],
102106
allowedEvents: ['NetworkController:stateChange'],
103107
});
@@ -874,51 +878,60 @@ describe('GasFeeController', () => {
874878
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
875879
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
876880
networkControllerState: {
877-
providerConfig: {
878-
type: NetworkType.rpc,
879-
chainId: toHex(1337),
880-
rpcUrl: 'http://some/url',
881-
ticker: 'TEST',
881+
networksMetadata: {
882+
mainnet: {
883+
EIPS: {
884+
1559: true,
885+
},
886+
status: NetworkStatus.Available,
887+
},
882888
},
883889
},
884890
clientId: '99999',
885891
});
886892

887893
await gasFeeController.executePoll('mainnet');
888-
889894
expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
890895
expect.objectContaining({
891-
fetchGasEstimatesUrl: 'http://eip-1559.endpoint/1',
896+
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/1',
892897
}),
893898
);
894899
});
895900
});
901+
896902
describe('polling', () => {
897903
it('should call determineGasFeeCalculations with a URL that contains the chain ID after polling interval', async () => {
898-
jest.useFakeTimers();
899904
await setupGasFeeController({
900905
getIsEIP1559Compatible: jest.fn().mockResolvedValue(false),
901906
getCurrentNetworkLegacyGasAPICompatibility: jest
902907
.fn()
903908
.mockReturnValue(true),
904909
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
905910
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
911+
networkControllerState: {
912+
networksMetadata: {
913+
goerli: {
914+
EIPS: {
915+
1559: true,
916+
},
917+
status: NetworkStatus.Available,
918+
},
919+
},
920+
},
906921
clientId: '99999',
907922
});
908923

909-
gasFeeController.start('mainnet');
910-
jest.advanceTimersByTime(1200);
911-
912-
console.log(JSON.stringify(gasFeeController.state, null, 4));
924+
gasFeeController.start('goerli');
925+
await clock.tickAsync(1500);
913926

914927
expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
915928
expect.objectContaining({
916-
fetchGasEstimatesUrl: 'http://eip-1559.endpoint/1',
929+
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/5',
917930
}),
918931
);
919932
expect(
920-
gasFeeController.state.gasFeeEstimatesByChainId?.['0x1'],
921-
).toBeDefined();
933+
gasFeeController.state.gasFeeEstimatesByChainId?.['0x5'],
934+
).toStrictEqual(buildMockGasFeeStateFeeMarket());
922935
});
923936
});
924937
});

packages/gas-fee-controller/src/GasFeeController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ export class GasFeeController extends GasFeeControllerPolling<
411411
'NetworkController:getEIP1559Compatibility',
412412
networkClientId,
413413
);
414-
415414
isEIP1559Compatible = result || false;
416415
} catch (e) {
417416
console.error(e);

packages/gas-fee-controller/src/GasFeeControllerPolling.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export default abstract class GasFeeControllerPolling<
8484
abstract executePoll(networkClientId: NetworkClientId): Promise<void>;
8585

8686
#poll(networkClientId: NetworkClientId) {
87-
console.log('hit #poll');
8887
if (this.intervalIds[networkClientId]) {
8988
clearInterval(this.intervalIds[networkClientId]);
9089
}

0 commit comments

Comments
 (0)