Skip to content

Commit

Permalink
chore(gas-fee-controller): revert recent gas API endpoint (#4446)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrans authored Jun 27, 2024
1 parent 29669b6 commit 036edd3
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 187 deletions.
2 changes: 1 addition & 1 deletion packages/gas-fee-controller/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 81.35,
functions: 81.57,
functions: 80.55,
lines: 86.28,
statements: 86.44,
},
Expand Down
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 @@ -334,6 +335,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 @@ -361,14 +364,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 @@ -398,6 +401,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 @@ -427,14 +432,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 @@ -751,6 +756,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...getDefaultOptions(),
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 @@ -778,14 +785,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 @@ -811,29 +817,31 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly when getChainId returns a number input', async () => {
await setupGasFeeController({
...getDefaultOptions(),
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({
...getDefaultOptions(),
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 @@ -877,14 +885,15 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly when getChainId returns a numeric string input', async () => {
await setupGasFeeController({
...getDefaultOptions(),
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 @@ -905,6 +914,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...getDefaultOptions(),
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 @@ -932,14 +943,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 @@ -965,14 +975,15 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => {
await setupGasFeeController({
...getDefaultOptions(),
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 @@ -1014,6 +1025,8 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations correctly', async () => {
await setupGasFeeController({
...getDefaultOptions(),
legacyAPIEndpoint: 'https://some-legacy-endpoint/<chain_id>',
EIP1559APIEndpoint: 'https://some-eip-1559-endpoint/<chain_id>',
clientId: '99999',
});

Expand All @@ -1027,20 +1040,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 @@ -1128,6 +1138,7 @@ describe('GasFeeController', () => {
it('should call determineGasFeeCalculations with a URL that contains the chain ID', async () => {
await setupGasFeeController({
...getDefaultOptions(),
EIP1559APIEndpoint: 'http://eip-1559.endpoint/<chain_id>',
});

await gasFeeController.fetchGasFeeEstimates({
Expand All @@ -1138,9 +1149,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 @@ -1155,6 +1166,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 @@ -1182,9 +1195,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 @@ -1195,9 +1208,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 @@ -1210,9 +1223,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 036edd3

Please sign in to comment.