11import { ControllerMessenger } from '@metamask/base-controller' ;
22import { NetworkType , toHex } from '@metamask/controller-utils' ;
33import EthQuery from '@metamask/eth-query' ;
4- import { NetworkController } from '@metamask/network-controller' ;
4+ import { NetworkController , NetworkStatus } from '@metamask/network-controller' ;
55import type {
6+ NetworkControllerGetEIP1559CompatibilityAction ,
67 NetworkControllerGetNetworkClientByIdAction ,
78 NetworkControllerGetStateAction ,
89 NetworkControllerNetworkDidChangeEvent ,
@@ -43,7 +44,8 @@ const name = 'GasFeeController';
4344type 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} ) ;
0 commit comments