Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update gas fee controller to 15.1.2 #9693

Merged
merged 27 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
99012a0
Update base controller v5, logging controller v3, permission controll…
tommasini May 15, 2024
3b93d7b
deduplicate
tommasini May 15, 2024
6d7ba31
Merge branch 'main' into update/1781-base-controller-v5
MarioAslau May 16, 2024
2601780
fix type issue on signature controller initialisation
tommasini May 16, 2024
a63b06b
merge main and solve conflicts
tommasini May 16, 2024
c06937c
update Network Controller to v^18
tommasini May 17, 2024
456816b
merge main and solve conflicts
tommasini May 17, 2024
36f0d83
Upgrade gas fee controller to 15.1.2
kylanhurt May 20, 2024
1dba3c1
Deduplicate
kylanhurt May 22, 2024
0e50159
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt May 22, 2024
8dcd077
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt May 22, 2024
cfa3ffc
Remove some ts-expect-errors now that base controller is updated
kylanhurt May 22, 2024
c69c0e8
Fix tests by adding new nonRPCGasFeeApisDisabled prop to tests
kylanhurt May 22, 2024
51c2306
Fix typo with infuraApiKey
kylanhurt May 23, 2024
fcb1114
Set 'nonRPCGasFeeApisDisabled' to true by default
kylanhurt May 23, 2024
7d8d1bf
Revert "Set 'nonRPCGasFeeApisDisabled' to true by default"
kylanhurt May 24, 2024
2cf79c1
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt May 29, 2024
7e275d0
Adjustments to GasFeeController constructor
kylanhurt May 29, 2024
446d903
Merge branch 'kylan/gas-fee-controller' of https://github.com/MetaMas…
kylanhurt May 29, 2024
289abb7
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt May 31, 2024
f0c61df
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt May 31, 2024
2702224
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt Jun 4, 2024
4b4d38b
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt Jun 4, 2024
9eed4b9
Update e2e test for gas fees to use Sepolia
kylanhurt Jun 5, 2024
5158bf7
Merge branch 'main' into kylan/gas-fee-controller
kylanhurt Jun 5, 2024
97902b0
Add small delay to advanced gas fees e2e test
kylanhurt Jun 5, 2024
9592677
Add migration for updated GasFeeController
kylanhurt Jun 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,26 +618,20 @@ class Engine {
networkController.state.selectedNetworkClientId,
);
const gasFeeController = new GasFeeController({
//@ts-expect-error Misalign types because of Base Controller version
messenger: this.controllerMessenger.getRestricted({
name: 'GasFeeController',
allowedActions: [
`${networkController.name}:getNetworkClientById`,
`${networkController.name}:getEIP1559Compatibility`,
`${networkController.name}:getState`,
],
allowedEvents: [AppConstants.NETWORK_DID_CHANGE_EVENT],
}),
getProvider: () =>
// @ts-expect-error at this point in time the provider will be defined by the `networkController.initializeProvider`
networkController.getProviderAndBlockTracker().provider,
onNetworkDidChange: (listener) =>
this.controllerMessenger.subscribe(
AppConstants.NETWORK_DID_CHANGE_EVENT,
listener,
),
getCurrentNetworkEIP1559Compatibility: async () =>
(await networkController.getEIP1559Compatibility()) ?? false,
getChainId: () => networkController.state.providerConfig.chainId,
getCurrentNetworkLegacyGasAPICompatibility: () => {
const chainId = networkController.state.providerConfig.chainId;
return (
Expand All @@ -647,10 +641,7 @@ class Engine {
);
},
clientId: AppConstants.SWAPS.CLIENT_ID,
legacyAPIEndpoint:
'https://gas.api.cx.metamask.io/networks/<chain_id>/gasPrices',
EIP1559APIEndpoint:
'https://gas.api.cx.metamask.io/networks/<chain_id>/suggestedGasFees',
infuraAPIKey: process.env.MM_INFURA_PROJECT_ID || NON_EMPTY,
});

const phishingController = new PhishingController({
Expand Down
98 changes: 98 additions & 0 deletions app/store/migrations/042.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import migration from './042';
import { merge } from 'lodash';
import initialRootState from '../../util/test/initial-root-state';
import { captureException } from '@sentry/react-native';

const oldState = {
engine: {
backgroundState: {
GasFeeController: {
gasFeeEstimates: {},
estimatedGasFeeTimeBounds: {},
gasEstimateType: 'none',
gasFeeEstimatesByChainId: {},
},
},
},
};

const expectedNewState = {
engine: {
backgroundState: {
GasFeeController: {
gasFeeEstimates: {},
estimatedGasFeeTimeBounds: {},
gasEstimateType: 'none',
gasFeeEstimatesByChainId: {},
nonRPCGasFeeApisDisabled: false,
},
},
},
};

jest.mock('@sentry/react-native', () => ({
captureException: jest.fn(),
}));
const mockedCaptureException = jest.mocked(captureException);

describe('Migration #42', () => {
beforeEach(() => {
jest.restoreAllMocks();
jest.resetAllMocks();
});

const invalidStates = [
{
state: merge({}, initialRootState, {
engine: null,
}),
errorMessage:
"FATAL ERROR: Migration 42: Invalid engine state error: 'object'",
scenario: 'engine state is invalid',
},
{
state: merge({}, initialRootState, {
engine: {
backgroundState: null,
},
}),
errorMessage:
"FATAL ERROR: Migration 42: Invalid engine backgroundState error: 'object'",
scenario: 'backgroundState is invalid',
},
{
state: merge({}, initialRootState, {
engine: {
backgroundState: {
GasFeeController: null,
},
},
}),
errorMessage:
"FATAL ERROR: Migration 42: Invalid GasFeeController state error: 'null'",
scenario: 'GasFeeController state is invalid',
},
];

for (const { errorMessage, scenario, state } of invalidStates) {
it(`should capture exception if ${scenario}`, async () => {
const newState = await migration(state);

expect(newState).toStrictEqual(state);
expect(mockedCaptureException).toHaveBeenCalledWith(expect.any(Error));
expect(mockedCaptureException.mock.calls[0][0].message).toBe(
errorMessage,
);
});
}

it('should contain new property nonRPCGasFeeApisDisabled = false in GasFeeController state ', async () => {
const newState = await migration(oldState);
expect(newState).toStrictEqual(expectedNewState);

expect(
// @ts-expect-error: ignore for testing purposes: new state is type unknown
newState.engine.backgroundState.GasFeeController.nonRPCGasFeeApisDisabled,
).toEqual(false);
});
});
32 changes: 32 additions & 0 deletions app/store/migrations/042.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { captureException } from '@sentry/react-native';
import { isObject } from '@metamask/utils';
import { ensureValidState } from './util';

/**
* Migration to update state of GasFeeController
*
* @param state Persisted Redux state
* @returns
*/
export default function migrate(state: unknown) {
if (!ensureValidState(state, 42)) {
return state;
}

const gasFeeControllerState = state.engine.backgroundState.GasFeeController;

if (!isObject(gasFeeControllerState)) {
captureException(
new Error(
`FATAL ERROR: Migration 42: Invalid GasFeeController state error: '${JSON.stringify(
gasFeeControllerState,
)}'`,
),
);
return state;
}

gasFeeControllerState.nonRPCGasFeeApisDisabled = false;

return state;
}
2 changes: 2 additions & 0 deletions app/store/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import migration38 from './038';
import migration39 from './039';
import migration40 from './040';
import migration41 from './041';
import migration42 from './042';

type MigrationFunction = (state: unknown) => unknown;
type AsyncMigrationFunction = (state: unknown) => Promise<unknown>;
Expand Down Expand Up @@ -96,6 +97,7 @@ export const migrationList: MigrationsList = {
39: migration39,
40: migration40,
41: migration41,
42: migration42,
};

// Enable both synchronous and asynchronous migrations
Expand Down
3 changes: 2 additions & 1 deletion app/util/test/initial-background-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
"gasFeeEstimates": {},
"estimatedGasFeeTimeBounds": {},
"gasEstimateType": "none",
"gasFeeEstimatesByChainId": {}
"gasFeeEstimatesByChainId": {},
"nonRPCGasFeeApisDisabled": false
kylanhurt marked this conversation as resolved.
Show resolved Hide resolved
},
"ApprovalController": {
"pendingApprovals": {},
Expand Down
1 change: 1 addition & 0 deletions e2e/fixtures/fixture-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class FixtureBuilder {
estimatedGasFeeTimeBounds: {},
gasEstimateType: 'none',
gasFeeEstimatesByChainId: {},
nonRPCGasFeeApisDisabled: false,
},
TokenDetectionController: {},
NftDetectionController: {},
Expand Down
15 changes: 15 additions & 0 deletions e2e/specs/confirmations/advanced-gas-fees.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import WalletActionsModal from '../../pages/modals/WalletActionsModal';
import TestHelpers from '../../helpers';
import Assertions from '../../utils/Assertions';
import { AmountViewSelectorsText } from '../../selectors/SendFlow/AmountView.selectors';
import NetworkListModal from '../../pages/modals/NetworkListModal';
import NetworkEducationModal from '../../pages/modals/NetworkEducationModal';
import { CustomNetworks } from '../../resources/networks.e2e';

const VALID_ADDRESS = '0xebe6CcB6B55e1d094d9c58980Bc10Fed69932cAb';

Expand All @@ -36,8 +39,20 @@ describe(SmokeConfirmations('Advanced Gas Fees and Priority Tests'), () => {

// Check that we are on the wallet screen
await WalletView.isVisible();

await WalletView.tapNetworksButtonOnNavBar();
await TestHelpers.delay(2000);
await NetworkListModal.changeNetworkTo(
CustomNetworks.Sepolia.providerConfig.nickname,
);
await Assertions.checkIfVisible(NetworkEducationModal.container);
await NetworkEducationModal.tapGotItButton();
await Assertions.checkIfNotVisible(NetworkEducationModal.container);

//Tap send Icon
await TestHelpers.delay(2000);
await TabBarComponent.tapActions();
await TestHelpers.delay(2000);
await WalletActionsModal.tapSendButton();

await SendView.inputAddress(VALID_ADDRESS);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"@metamask/design-tokens": "^2.0.0",
"@metamask/eth-sig-util": "^7.0.2",
"@metamask/etherscan-link": "^2.0.0",
"@metamask/gas-fee-controller": "^13.0.0",
"@metamask/gas-fee-controller": "^15.1.2",
"@metamask/key-tree": "^9.0.0",
"@metamask/keyring-api": "^4.0.0",
"@metamask/keyring-controller": "^16.0.0",
Expand Down
17 changes: 0 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4136,23 +4136,6 @@
is-hex-prefixed "1.0.0"
strip-hex-prefix "1.0.0"

"@metamask/gas-fee-controller@^13.0.0":
version "13.0.2"
resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-13.0.2.tgz#d8c0efeab91492f9ce96f7eca834bb9bd17fbb62"
integrity sha512-uhjxUToLbON0kUSZUvkDbavM/oGbNHhMV3U76Qf2GCevENiYgZhKNBnUn+KOL1Us8YD2yho2D7G28L+KZa00Wg==
dependencies:
"@metamask/base-controller" "^4.1.1"
"@metamask/controller-utils" "^8.0.4"
"@metamask/eth-query" "^4.0.0"
"@metamask/ethjs-unit" "^0.3.0"
"@metamask/network-controller" "^17.2.1"
"@metamask/polling-controller" "^5.0.1"
"@metamask/utils" "^8.3.0"
"@types/bn.js" "^5.1.5"
"@types/uuid" "^8.3.0"
bn.js "^5.2.1"
uuid "^8.3.2"

"@metamask/gas-fee-controller@^15.1.2":
version "15.1.2"
resolved "https://registry.yarnpkg.com/@metamask/gas-fee-controller/-/gas-fee-controller-15.1.2.tgz#cb8d85906efa1ff42a159ec023287ff31a63e45b"
Expand Down
Loading