Skip to content

Commit

Permalink
Revert "fix: use hardcoded Infura gas API urls (#4068)"
Browse files Browse the repository at this point in the history
This reverts commit 850461d.

merge conflicts:
- determineGasFeeCalculations.ts
- GasFeeController.ts
- GasFeeController.test.ts
  • Loading branch information
dbrans committed Jun 10, 2024
1 parent 1900a9d commit 3577d9c
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 190 deletions.
1 change: 1 addition & 0 deletions packages/gas-fee-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"jest-when": "^3.4.2",
"nock": "^13.3.1",
"sinon": "^9.2.4",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
Expand Down
91 changes: 52 additions & 39 deletions packages/gas-fee-controller/src/GasFeeController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ import {
fetchEthGasPriceEstimate,
calculateTimeEstimate,
} from './gas-util';
import {
GAS_API_BASE_URL,
GAS_ESTIMATE_TYPES,
GasFeeController,
} from './GasFeeController';
import { GAS_ESTIMATE_TYPES, GasFeeController } from './GasFeeController';
import type {
GasFeeState,
GasFeeStateChange,
Expand Down Expand Up @@ -228,12 +224,13 @@ describe('GasFeeController', () => {
* GasFeeController.
* @param options.getCurrentNetworkLegacyGasAPICompatibility - Sets
* getCurrentNetworkLegacyGasAPICompatibility on the GasFeeController.
* @param options.legacyAPIEndpoint - Sets legacyAPIEndpoint on the GasFeeController.
* @param options.EIP1559APIEndpoint - Sets EIP1559APIEndpoint on the GasFeeController.
* @param options.clientId - Sets clientId on the GasFeeController.
* @param options.networkControllerState - State object to initialize
* NetworkController with.
* @param options.interval - The polling interval.
* @param options.state - The initial GasFeeController state
* @param options.infuraAPIKey - The Infura API key.
* @param options.initializeNetworkProvider - Whether to instruct the
* NetworkController to initialize its provider.
*/
Expand All @@ -242,7 +239,8 @@ describe('GasFeeController', () => {
getCurrentNetworkLegacyGasAPICompatibility = jest
.fn()
.mockReturnValue(false),
infuraAPIKey = 'INFURA_API_KEY',
legacyAPIEndpoint = 'http://legacy.endpoint/<chain_id>',
EIP1559APIEndpoint = 'http://eip-1559.endpoint/<chain_id>',
clientId,
getChainId,
onNetworkDidChange,
Expand All @@ -255,11 +253,13 @@ describe('GasFeeController', () => {
onNetworkDidChange?: jest.Mock<void>;
getIsEIP1559Compatible?: jest.Mock<Promise<boolean>>;
getCurrentNetworkLegacyGasAPICompatibility?: jest.Mock<boolean>;
legacyAPIEndpoint?: string;
// eslint-disable-next-line @typescript-eslint/naming-convention
EIP1559APIEndpoint?: string;
clientId?: string;
networkControllerState?: Partial<NetworkState>;
state?: GasFeeState;
interval?: number;
infuraAPIKey?: string;
initializeNetworkProvider?: boolean;
} = {}) {
const controllerMessenger = getControllerMessenger();
Expand All @@ -277,10 +277,11 @@ describe('GasFeeController', () => {
messenger,
getCurrentNetworkLegacyGasAPICompatibility,
getCurrentNetworkEIP1559Compatibility: getIsEIP1559Compatible, // change this for networkDetails.state.networkDetails.isEIP1559Compatible ???
legacyAPIEndpoint,
EIP1559APIEndpoint,
state,
clientId,
interval,
infuraAPIKey,
});
}

Expand Down Expand Up @@ -335,6 +336,8 @@ describe('GasFeeController', () => {
getCurrentNetworkLegacyGasAPICompatibility: jest
.fn()
.mockReturnValue(true),
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
networkControllerState: {
networkConfigurations: {
'AAAA-BBBB-CCCC-DDDD': {
Expand Down Expand Up @@ -362,14 +365,14 @@ describe('GasFeeController', () => {
isEIP1559Compatible: false,
isLegacyGasAPICompatible: true,
fetchGasEstimates,
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/suggestedGasFees`,
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/1337',
fetchLegacyGasPriceEstimates,
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/gasPrices`,
fetchLegacyGasPriceEstimatesUrl:
'https://some-legacy-endpoint/1337',
fetchEthGasPriceEstimate,
calculateTimeEstimate,
clientId: '99999',
ethQuery: expect.any(EthQuery),
infuraAPIKey: expect.any(String),
nonRPCGasFeeApisDisabled: false,
});
});
Expand Down Expand Up @@ -399,6 +402,8 @@ describe('GasFeeController', () => {
getCurrentNetworkLegacyGasAPICompatibility: jest
.fn()
.mockReturnValue(true),
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
networkControllerState: {
networkConfigurations: {
'AAAA-BBBB-CCCC-DDDD': {
Expand Down Expand Up @@ -428,14 +433,14 @@ describe('GasFeeController', () => {
isEIP1559Compatible: false,
isLegacyGasAPICompatible: true,
fetchGasEstimates,
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/suggestedGasFees`,
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/1337',
fetchLegacyGasPriceEstimates,
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/gasPrices`,
fetchLegacyGasPriceEstimatesUrl:
'https://some-legacy-endpoint/1337',
fetchEthGasPriceEstimate,
calculateTimeEstimate,
clientId: '99999',
ethQuery: expect.any(EthQuery),
infuraAPIKey: expect.any(String),
nonRPCGasFeeApisDisabled: false,
});
});
Expand Down Expand Up @@ -752,6 +757,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
networkControllerState: {
networkConfigurations: {
'AAAA-BBBB-CCCC-DDDD': {
Expand Down Expand Up @@ -779,14 +786,13 @@ describe('GasFeeController', () => {
isEIP1559Compatible: false,
isLegacyGasAPICompatible: true,
fetchGasEstimates,
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/suggestedGasFees`,
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/1337',
fetchLegacyGasPriceEstimates,
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/gasPrices`,
fetchLegacyGasPriceEstimatesUrl: 'https://some-legacy-endpoint/1337',
fetchEthGasPriceEstimate,
calculateTimeEstimate,
clientId: '99999',
ethQuery: expect.any(EthQuery),
infuraAPIKey: expect.any(String),
nonRPCGasFeeApisDisabled: false,
});
});
Expand All @@ -812,29 +818,31 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly when getChainId returns a number input', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'http://legacy.endpoint/<chain_id>',
getChainId: jest.fn().mockReturnValue(1),
});

await gasFeeController._fetchGasFeeEstimateData();

expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
expect.objectContaining({
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1/gasPrices`,
fetchLegacyGasPriceEstimatesUrl: 'http://legacy.endpoint/1',
}),
);
});

it('should call determineGasFeeCalculations correctly when getChainId returns a hexstring input', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'http://legacy.endpoint/<chain_id>',
getChainId: jest.fn().mockReturnValue('0x1'),
});

await gasFeeController.fetchGasFeeEstimates();

expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
expect.objectContaining({
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1/gasPrices`,
fetchLegacyGasPriceEstimatesUrl: 'http://legacy.endpoint/1',
}),
);
});
Expand Down Expand Up @@ -878,14 +886,15 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly when getChainId returns a numeric string input', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'http://legacy.endpoint/<chain_id>',
getChainId: jest.fn().mockReturnValue('1'),
});

await gasFeeController.fetchGasFeeEstimates();

expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
expect.objectContaining({
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1/gasPrices`,
fetchLegacyGasPriceEstimatesUrl: 'http://legacy.endpoint/1',
}),
);
});
Expand All @@ -906,6 +915,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
networkControllerState: {
networkConfigurations: {
'AAAA-BBBB-CCCC-DDDD': {
Expand Down Expand Up @@ -933,14 +944,13 @@ describe('GasFeeController', () => {
isEIP1559Compatible: true,
isLegacyGasAPICompatible: false,
fetchGasEstimates,
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/suggestedGasFees`,
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/1337',
fetchLegacyGasPriceEstimates,
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/1337/gasPrices`,
fetchLegacyGasPriceEstimatesUrl: 'https://some-legacy-endpoint/1337',
fetchEthGasPriceEstimate,
calculateTimeEstimate,
clientId: '99999',
ethQuery: expect.any(EthQuery),
infuraAPIKey: expect.any(String),
nonRPCGasFeeApisDisabled: false,
});
});
Expand All @@ -966,14 +976,15 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
EIP1559APIEndpoint: 'http://eip-1559.endpoint/<chain_id>',
getChainId: jest.fn().mockReturnValue('0x1'),
});

await gasFeeController.fetchGasFeeEstimates();

expect(mockedDetermineGasFeeCalculations).toHaveBeenCalledWith(
expect.objectContaining({
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/1/suggestedGasFees`,
fetchGasEstimatesUrl: 'http://eip-1559.endpoint/1',
}),
);
});
Expand Down Expand Up @@ -1015,6 +1026,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
clientId: '99999',
});

Expand All @@ -1028,20 +1041,17 @@ describe('GasFeeController', () => {
fetchGasEstimates,
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
ChainId.goerli,
)}/suggestedGasFees`,
fetchGasEstimatesUrl: 'https://some-eip-1559-endpoint/5',
fetchLegacyGasPriceEstimates,
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchLegacyGasPriceEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
fetchLegacyGasPriceEstimatesUrl: `https://some-legacy-endpoint/${convertHexToDecimal(
ChainId.goerli,
)}/gasPrices`,
)}`,
fetchEthGasPriceEstimate,
calculateTimeEstimate,
clientId: '99999',
ethQuery: expect.any(EthQuery),
infuraAPIKey: expect.any(String),
nonRPCGasFeeApisDisabled: false,
});
});
Expand Down Expand Up @@ -1129,6 +1139,7 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => {
await setupGasFeeController({
...defaultConstructorOptions,
EIP1559APIEndpoint: 'http://eip-1559.endpoint/<chain_id>',
});

await gasFeeController.fetchGasFeeEstimates({
Expand All @@ -1139,9 +1150,9 @@ describe('GasFeeController', () => {
expect.objectContaining({
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
fetchGasEstimatesUrl: `http://eip-1559.endpoint/${convertHexToDecimal(
ChainId.sepolia,
)}/suggestedGasFees`,
)}`,
}),
);
});
Expand All @@ -1156,6 +1167,8 @@ describe('GasFeeController', () => {
getCurrentNetworkLegacyGasAPICompatibility: jest
.fn()
.mockReturnValue(true),
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
networkControllerState: {
networksMetadata: {
goerli: {
Expand Down Expand Up @@ -1183,9 +1196,9 @@ describe('GasFeeController', () => {
expect.objectContaining({
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
fetchGasEstimatesUrl: `https://some-eip-1559-endpoint/${convertHexToDecimal(
ChainId.goerli,
)}/suggestedGasFees`,
)}`,
}),
);
await clock.tickAsync(pollingInterval / 2);
Expand All @@ -1196,9 +1209,9 @@ describe('GasFeeController', () => {
expect.objectContaining({
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
fetchGasEstimatesUrl: `https://some-eip-1559-endpoint/${convertHexToDecimal(
ChainId.goerli,
)}/suggestedGasFees`,
)}`,
}),
);
expect(
Expand All @@ -1211,9 +1224,9 @@ describe('GasFeeController', () => {
expect.objectContaining({
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
fetchGasEstimatesUrl: `${GAS_API_BASE_URL}/networks/${convertHexToDecimal(
fetchGasEstimatesUrl: `https://some-eip-1559-endpoint/${convertHexToDecimal(
ChainId.sepolia,
)}/suggestedGasFees`,
)}`,
}),
);
});
Expand Down
Loading

0 comments on commit 3577d9c

Please sign in to comment.