@@ -25,7 +25,11 @@ import {
2525 fetchEthGasPriceEstimate ,
2626 calculateTimeEstimate ,
2727} from './gas-util' ;
28- import { GAS_ESTIMATE_TYPES , GasFeeController } from './GasFeeController' ;
28+ import {
29+ GAS_API_BASE_URL ,
30+ GAS_ESTIMATE_TYPES ,
31+ GasFeeController ,
32+ } from './GasFeeController' ;
2933import type {
3034 GasFeeState ,
3135 GasFeeStateChange ,
@@ -218,21 +222,19 @@ describe('GasFeeController', () => {
218222 * GasFeeController.
219223 * @param options.getCurrentNetworkLegacyGasAPICompatibility - Sets
220224 * getCurrentNetworkLegacyGasAPICompatibility on the GasFeeController.
221- * @param options.legacyAPIEndpoint - Sets legacyAPIEndpoint on the GasFeeController.
222- * @param options.EIP1559APIEndpoint - Sets EIP1559APIEndpoint on the GasFeeController.
223225 * @param options.clientId - Sets clientId on the GasFeeController.
224226 * @param options.networkControllerState - State object to initialize
225227 * NetworkController with.
226228 * @param options.interval - The polling interval.
227229 * @param options.state - The initial GasFeeController state
230+ * @param options.infuraAPIKey - The Infura API key.
228231 */
229232 async function setupGasFeeController ( {
230233 getIsEIP1559Compatible = jest . fn ( ) . mockResolvedValue ( true ) ,
231234 getCurrentNetworkLegacyGasAPICompatibility = jest
232235 . fn ( )
233236 . mockReturnValue ( false ) ,
234- legacyAPIEndpoint = 'http://legacy.endpoint/<chain_id>' ,
235- EIP1559APIEndpoint = 'http://eip-1559.endpoint/<chain_id>' ,
237+ infuraAPIKey = 'INFURA_API_KEY' ,
236238 clientId,
237239 getChainId,
238240 networkControllerState = { } ,
@@ -242,12 +244,11 @@ describe('GasFeeController', () => {
242244 getChainId ?: jest . Mock < Hex > ;
243245 getIsEIP1559Compatible ?: jest . Mock < Promise < boolean > > ;
244246 getCurrentNetworkLegacyGasAPICompatibility ?: jest . Mock < boolean > ;
245- legacyAPIEndpoint ?: string ;
246- EIP1559APIEndpoint ?: string ;
247247 clientId ?: string ;
248248 networkControllerState ?: Partial < NetworkState > ;
249249 state ?: GasFeeState ;
250250 interval ?: number ;
251+ infuraAPIKey ?: string ;
251252 } = { } ) {
252253 const controllerMessenger = getControllerMessenger ( ) ;
253254 networkController = await setupNetworkController ( {
@@ -262,11 +263,10 @@ describe('GasFeeController', () => {
262263 messenger,
263264 getCurrentNetworkLegacyGasAPICompatibility,
264265 getCurrentNetworkEIP1559Compatibility : getIsEIP1559Compatible , // change this for networkDetails.state.networkDetails.isEIP1559Compatible ???
265- legacyAPIEndpoint,
266- EIP1559APIEndpoint,
267266 state,
268267 clientId,
269268 interval,
269+ infuraAPIKey,
270270 } ) ;
271271 }
272272
@@ -319,8 +319,6 @@ describe('GasFeeController', () => {
319319 getCurrentNetworkLegacyGasAPICompatibility : jest
320320 . fn ( )
321321 . mockReturnValue ( true ) ,
322- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
323- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
324322 networkControllerState : {
325323 providerConfig : {
326324 type : NetworkType . rpc ,
@@ -338,15 +336,15 @@ describe('GasFeeController', () => {
338336 isEIP1559Compatible : false ,
339337 isLegacyGasAPICompatible : true ,
340338 fetchGasEstimates,
341- fetchGasEstimatesUrl : 'https://some-eip-1559-endpoint/ 1337' ,
339+ fetchGasEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/suggestedGasFees` ,
342340 fetchGasEstimatesViaEthFeeHistory,
343341 fetchLegacyGasPriceEstimates,
344- fetchLegacyGasPriceEstimatesUrl :
345- 'https://some-legacy-endpoint/1337' ,
342+ fetchLegacyGasPriceEstimatesUrl : `${ GAS_API_BASE_URL } /networks/1337/gasPrices` ,
346343 fetchEthGasPriceEstimate,
347344 calculateTimeEstimate,
348345 clientId : '99999' ,
349346 ethQuery : expect . any ( EthQuery ) ,
347+ infuraAPIKey : expect . any ( String ) ,
350348 } ) ;
351349 } ) ;
352350
@@ -375,8 +373,6 @@ describe('GasFeeController', () => {
375373 getCurrentNetworkLegacyGasAPICompatibility : jest
376374 . fn ( )
377375 . mockReturnValue ( true ) ,
378- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
379- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
380376 networkControllerState : {
381377 providerConfig : {
382378 type : NetworkType . rpc ,
@@ -396,15 +392,15 @@ describe('GasFeeController', () => {
396392 isEIP1559Compatible : false ,
397393 isLegacyGasAPICompatible : true ,
398394 fetchGasEstimates,
399- fetchGasEstimatesUrl : 'https://some-eip-1559-endpoint/ 1337' ,
395+ fetchGasEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/suggestedGasFees` ,
400396 fetchGasEstimatesViaEthFeeHistory,
401397 fetchLegacyGasPriceEstimates,
402- fetchLegacyGasPriceEstimatesUrl :
403- 'https://some-legacy-endpoint/1337' ,
398+ fetchLegacyGasPriceEstimatesUrl : `${ GAS_API_BASE_URL } /networks/1337/gasPrices` ,
404399 fetchEthGasPriceEstimate,
405400 calculateTimeEstimate,
406401 clientId : '99999' ,
407402 ethQuery : expect . any ( EthQuery ) ,
403+ infuraAPIKey : expect . any ( String ) ,
408404 } ) ;
409405 } ) ;
410406
@@ -686,8 +682,6 @@ describe('GasFeeController', () => {
686682 it ( 'should call determineGasFeeCalculations correctly' , async ( ) => {
687683 await setupGasFeeController ( {
688684 ...defaultConstructorOptions ,
689- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
690- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
691685 networkControllerState : {
692686 providerConfig : {
693687 type : NetworkType . rpc ,
@@ -705,14 +699,15 @@ describe('GasFeeController', () => {
705699 isEIP1559Compatible : false ,
706700 isLegacyGasAPICompatible : true ,
707701 fetchGasEstimates,
708- fetchGasEstimatesUrl : 'https://some-eip-1559-endpoint/ 1337' ,
702+ fetchGasEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/suggestedGasFees` ,
709703 fetchGasEstimatesViaEthFeeHistory,
710704 fetchLegacyGasPriceEstimates,
711- fetchLegacyGasPriceEstimatesUrl : 'https://some-legacy-endpoint/ 1337' ,
705+ fetchLegacyGasPriceEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/gasPrices` ,
712706 fetchEthGasPriceEstimate,
713707 calculateTimeEstimate,
714708 clientId : '99999' ,
715709 ethQuery : expect . any ( EthQuery ) ,
710+ infuraAPIKey : expect . any ( String ) ,
716711 } ) ;
717712 } ) ;
718713
@@ -737,47 +732,44 @@ describe('GasFeeController', () => {
737732 it ( 'should call determineGasFeeCalculations correctly when getChainId returns a number input' , async ( ) => {
738733 await setupGasFeeController ( {
739734 ...defaultConstructorOptions ,
740- legacyAPIEndpoint : 'http://legacy.endpoint/<chain_id>' ,
741735 getChainId : jest . fn ( ) . mockReturnValue ( 1 ) ,
742736 } ) ;
743737
744738 await gasFeeController . _fetchGasFeeEstimateData ( ) ;
745739
746740 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
747741 expect . objectContaining ( {
748- fetchLegacyGasPriceEstimatesUrl : 'http://legacy.endpoint/1' ,
742+ fetchLegacyGasPriceEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/1/gasPrices` ,
749743 } ) ,
750744 ) ;
751745 } ) ;
752746
753747 it ( 'should call determineGasFeeCalculations correctly when getChainId returns a hexstring input' , async ( ) => {
754748 await setupGasFeeController ( {
755749 ...defaultConstructorOptions ,
756- legacyAPIEndpoint : 'http://legacy.endpoint/<chain_id>' ,
757750 getChainId : jest . fn ( ) . mockReturnValue ( '0x1' ) ,
758751 } ) ;
759752
760753 await gasFeeController . fetchGasFeeEstimates ( ) ;
761754
762755 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
763756 expect . objectContaining ( {
764- fetchLegacyGasPriceEstimatesUrl : 'http://legacy.endpoint/1' ,
757+ fetchLegacyGasPriceEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/1/gasPrices` ,
765758 } ) ,
766759 ) ;
767760 } ) ;
768761
769762 it ( 'should call determineGasFeeCalculations correctly when getChainId returns a numeric string input' , async ( ) => {
770763 await setupGasFeeController ( {
771764 ...defaultConstructorOptions ,
772- legacyAPIEndpoint : 'http://legacy.endpoint/<chain_id>' ,
773765 getChainId : jest . fn ( ) . mockReturnValue ( '1' ) ,
774766 } ) ;
775767
776768 await gasFeeController . fetchGasFeeEstimates ( ) ;
777769
778770 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
779771 expect . objectContaining ( {
780- fetchLegacyGasPriceEstimatesUrl : 'http://legacy.endpoint/1' ,
772+ fetchLegacyGasPriceEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/1/gasPrices` ,
781773 } ) ,
782774 ) ;
783775 } ) ;
@@ -798,8 +790,6 @@ describe('GasFeeController', () => {
798790 it ( 'should call determineGasFeeCalculations correctly' , async ( ) => {
799791 await setupGasFeeController ( {
800792 ...defaultConstructorOptions ,
801- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
802- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
803793 networkControllerState : {
804794 providerConfig : {
805795 type : NetworkType . rpc ,
@@ -817,14 +807,15 @@ describe('GasFeeController', () => {
817807 isEIP1559Compatible : true ,
818808 isLegacyGasAPICompatible : false ,
819809 fetchGasEstimates,
820- fetchGasEstimatesUrl : 'https://some-eip-1559-endpoint/ 1337' ,
810+ fetchGasEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/suggestedGasFees` ,
821811 fetchGasEstimatesViaEthFeeHistory,
822812 fetchLegacyGasPriceEstimates,
823- fetchLegacyGasPriceEstimatesUrl : 'https://some-legacy-endpoint/ 1337' ,
813+ fetchLegacyGasPriceEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/ 1337/gasPrices` ,
824814 fetchEthGasPriceEstimate,
825815 calculateTimeEstimate,
826816 clientId : '99999' ,
827817 ethQuery : expect . any ( EthQuery ) ,
818+ infuraAPIKey : expect . any ( String ) ,
828819 } ) ;
829820 } ) ;
830821
@@ -849,15 +840,14 @@ describe('GasFeeController', () => {
849840 it ( 'should call determineGasFeeCalculations with a URL that contains the chain ID' , async ( ) => {
850841 await setupGasFeeController ( {
851842 ...defaultConstructorOptions ,
852- EIP1559APIEndpoint : 'http://eip-1559.endpoint/<chain_id>' ,
853843 getChainId : jest . fn ( ) . mockReturnValue ( '0x1' ) ,
854844 } ) ;
855845
856846 await gasFeeController . fetchGasFeeEstimates ( ) ;
857847
858848 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
859849 expect . objectContaining ( {
860- fetchGasEstimatesUrl : 'http://eip-1559.endpoint/1' ,
850+ fetchGasEstimatesUrl : ` ${ GAS_API_BASE_URL } /networks/1/suggestedGasFees` ,
861851 } ) ,
862852 ) ;
863853 } ) ;
@@ -899,8 +889,6 @@ describe('GasFeeController', () => {
899889 it ( 'should call determineGasFeeCalculations correctly' , async ( ) => {
900890 await setupGasFeeController ( {
901891 ...defaultConstructorOptions ,
902- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
903- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
904892 clientId : '99999' ,
905893 } ) ;
906894
@@ -912,16 +900,19 @@ describe('GasFeeController', () => {
912900 isEIP1559Compatible : true ,
913901 isLegacyGasAPICompatible : false ,
914902 fetchGasEstimates,
915- fetchGasEstimatesUrl : 'https://some-eip-1559-endpoint/5' ,
903+ fetchGasEstimatesUrl : `${ GAS_API_BASE_URL } /networks/${ convertHexToDecimal (
904+ ChainId . goerli ,
905+ ) } /suggestedGasFees`,
916906 fetchGasEstimatesViaEthFeeHistory,
917907 fetchLegacyGasPriceEstimates,
918- fetchLegacyGasPriceEstimatesUrl : `https://some-legacy-endpoint /${ convertHexToDecimal (
908+ fetchLegacyGasPriceEstimatesUrl : `${ GAS_API_BASE_URL } /networks /${ convertHexToDecimal (
919909 ChainId . goerli ,
920- ) } `,
910+ ) } /gasPrices `,
921911 fetchEthGasPriceEstimate,
922912 calculateTimeEstimate,
923913 clientId : '99999' ,
924914 ethQuery : expect . any ( EthQuery ) ,
915+ infuraAPIKey : expect . any ( String ) ,
925916 } ) ;
926917 } ) ;
927918
@@ -931,10 +922,6 @@ describe('GasFeeController', () => {
931922 await gasFeeController . fetchGasFeeEstimates ( {
932923 networkClientId : 'goerli' ,
933924 } ) ;
934- console . log (
935- 'gasFeeController.state.gasFeeEstimatesByChainId: ' ,
936- gasFeeController . state . gasFeeEstimatesByChainId ,
937- ) ;
938925
939926 expect (
940927 gasFeeController . state . gasFeeEstimatesByChainId ?. [ ChainId . goerli ] ,
@@ -954,7 +941,6 @@ describe('GasFeeController', () => {
954941 it ( 'should call determineGasFeeCalculations with a URL that contains the chain ID' , async ( ) => {
955942 await setupGasFeeController ( {
956943 ...defaultConstructorOptions ,
957- EIP1559APIEndpoint : 'http://eip-1559.endpoint/<chain_id>' ,
958944 } ) ;
959945
960946 await gasFeeController . fetchGasFeeEstimates ( {
@@ -963,9 +949,9 @@ describe('GasFeeController', () => {
963949
964950 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
965951 expect . objectContaining ( {
966- fetchGasEstimatesUrl : `http://eip-1559.endpoint /${ convertHexToDecimal (
952+ fetchGasEstimatesUrl : `${ GAS_API_BASE_URL } /networks /${ convertHexToDecimal (
967953 ChainId . sepolia ,
968- ) } `,
954+ ) } /suggestedGasFees `,
969955 } ) ,
970956 ) ;
971957 } ) ;
@@ -980,8 +966,6 @@ describe('GasFeeController', () => {
980966 getCurrentNetworkLegacyGasAPICompatibility : jest
981967 . fn ( )
982968 . mockReturnValue ( true ) ,
983- legacyAPIEndpoint : 'https://some-legacy-endpoint/<chain_id>' ,
984- EIP1559APIEndpoint : 'https://some-eip-1559-endpoint/<chain_id>' ,
985969 networkControllerState : {
986970 networksMetadata : {
987971 goerli : {
@@ -1007,9 +991,9 @@ describe('GasFeeController', () => {
1007991 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenNthCalledWith (
1008992 1 ,
1009993 expect . objectContaining ( {
1010- fetchGasEstimatesUrl : `https://some-eip-1559-endpoint /${ convertHexToDecimal (
994+ fetchGasEstimatesUrl : `${ GAS_API_BASE_URL } /networks /${ convertHexToDecimal (
1011995 ChainId . goerli ,
1012- ) } `,
996+ ) } /suggestedGasFees `,
1013997 } ) ,
1014998 ) ;
1015999 await clock . tickAsync ( pollingInterval / 2 ) ;
@@ -1018,9 +1002,9 @@ describe('GasFeeController', () => {
10181002 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenNthCalledWith (
10191003 2 ,
10201004 expect . objectContaining ( {
1021- fetchGasEstimatesUrl : `https://some-eip-1559-endpoint /${ convertHexToDecimal (
1005+ fetchGasEstimatesUrl : `${ GAS_API_BASE_URL } /networks /${ convertHexToDecimal (
10221006 ChainId . goerli ,
1023- ) } `,
1007+ ) } /suggestedGasFees `,
10241008 } ) ,
10251009 ) ;
10261010 expect (
@@ -1031,9 +1015,9 @@ describe('GasFeeController', () => {
10311015 await clock . tickAsync ( pollingInterval ) ;
10321016 expect ( mockedDetermineGasFeeCalculations ) . toHaveBeenCalledWith (
10331017 expect . objectContaining ( {
1034- fetchGasEstimatesUrl : `https://some-eip-1559-endpoint /${ convertHexToDecimal (
1018+ fetchGasEstimatesUrl : `${ GAS_API_BASE_URL } /networks /${ convertHexToDecimal (
10351019 ChainId . sepolia ,
1036- ) } `,
1020+ ) } /suggestedGasFees `,
10371021 } ) ,
10381022 ) ;
10391023 } ) ;
0 commit comments