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

Remove providerConfig from NetworkController #4254

Merged
merged 8 commits into from
Jun 12, 2024
Merged

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented May 3, 2024

Explanation

Historically, the providerConfig property in NetworkController has been used to track the currently selected network as well as provide access to information about that network. The selected network is now tracked via selectedNetworkClientId, and information about that network can be retrieved by looking at the networkConfigurations property or the configuration property on the NetworkClient interface. This means that we no longer need providerConfig and we can remove this redundant state.

References

Fixes #4185.

Changelog

(Updated in PR)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Base automatically changed from refactor-tokens-controller-tests to main May 6, 2024 15:06
@mcmire mcmire force-pushed the remove-provider-config branch 2 times, most recently from 9b3cc0a to 730b264 Compare May 6, 2024 17:04
@mcmire mcmire marked this pull request as ready for review May 6, 2024 17:05
@mcmire mcmire requested a review from a team as a code owner May 6, 2024 17:05
@mcmire
Copy link
Contributor Author

mcmire commented May 22, 2024

I'm going to break this up into multiple PRs as this one is rather large and difficult to review. Placing in draft until that's complete.

After that we can rebase this PR and reopen it for review.

@mcmire mcmire marked this pull request as draft May 22, 2024 17:16
@mcmire mcmire force-pushed the remove-provider-config branch 2 times, most recently from ca0fc05 to 310a6b3 Compare June 7, 2024 23:13
@mcmire mcmire marked this pull request as ready for review June 7, 2024 23:19
Historically, the `providerConfig` property in NetworkController has
been used to track the currently selected network as well as provide
access to information about that network. The selected network is now
tracked via `selectedNetworkClientId`, and information about that
network can be retrieved by looking at the `networkConfigurations`
property or the `configuration` property on the NetworkClient interface.
This means that we no longer need `providerConfig` and we can remove
this redundant state.
mikesposito
mikesposito previously approved these changes Jun 10, 2024
@mcmire
Copy link
Contributor Author

mcmire commented Jun 11, 2024

Conflicts resolved.

@mcmire
Copy link
Contributor Author

mcmire commented Jun 11, 2024

Okay! Tests should pass again.

@mcmire mcmire merged commit 0f2a743 into main Jun 12, 2024
113 checks passed
@mcmire mcmire deleted the remove-provider-config branch June 12, 2024 15:27
Copy link
Contributor

@kanthesha kanthesha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM.

autoManagedNetworkClient =
builtInNetworkClientRegistry[networkClientId as BuiltInNetworkClientId];
if (!autoManagedNetworkClient) {
// This is impossible to reach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about mocking isInfuraNetworkType to return true?

Copy link
Contributor Author

@mcmire mcmire Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test we'd need to write here is not what happens when isInfuraNetworkType returns true or false, but what happens when isInfuraNetworkType returns true and yet possibleAutoManagedNetworkClient is undefined. If that happens, it would mean that there is no network client registered for the networkClientId when it refers to an Infura network.

The reason why this is impossible is that autoManagedNetworkClientRegistry[NetworkClientType.Infura] is automatically populated with all of the Infura networks that we know about, and there is no way to stop that from happening. So if networkClientId refers to an Infura network, we know that it matches a network client in autoManagedNetworkClientRegistry[NetworkClientType.Infura].

However, this will no longer be true in #4286, because that integrates Infura networks into the networkConfigurationsByChainId state property, and so we will now be able to control whether a network client gets created for an Infura network or not, making this scenario testable.

All this to say... this istanbul ignore will go away in #4286.

import {
buildCustomNetworkClientConfiguration,
buildInfuraNetworkClientConfiguration,
} from './helpers';

jest.mock('../src/create-network-client');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious to know, why we have a separate test folder which is uncommon when we compared with other controllers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. This change was made by another team mistakenly and wasn't caught, and has now persisted. I agree that we should move this to src/ however.

const fakeNetworkClient = buildFakeClient(fakeProvider);
createNetworkClientMock.mockReturnValue(fakeNetworkClient);
},
infuraProjectId: 'some-infura-project-id',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to understand, even the custom network client will have a infura project id?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Remove providerConfig from NetworkController
4 participants