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

testfix(transaction-controller): Refactor provider setup to provide correct providers and tracker #4391

Merged

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented Jun 7, 2024

Explanation

Refactors tests so that providers are injected appropriately in the MockMultichainTransaction.

The error is interacting with a separate bug in @metamask/eth-block-tracker < v9.0.3 (@metamask/nonce-tracker < 6.0.0), which is why we don't see them failing until #4329 / #4327

References

Changelog

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

@legobeat legobeat force-pushed the test-fix-transaction-controller-test-providers branch 2 times, most recently from 97da9a5 to a0e3f37 Compare June 8, 2024 00:47
@legobeat legobeat marked this pull request as ready for review June 8, 2024 00:52
@legobeat legobeat requested a review from a team as a code owner June 8, 2024 00:52
@legobeat legobeat force-pushed the test-fix-transaction-controller-test-providers branch from a0e3f37 to 5f25d4e Compare June 10, 2024 00:23
provider: MAINNET_PROVIDER,
blockTracker: buildMockBlockTracker('0x102833C', MAINNET_PROVIDER),
provider: HTTP_PROVIDERS.goerli,
blockTracker: buildMockBlockTracker('0x102833C', HTTP_PROVIDERS.goerli),
Copy link
Contributor Author

@legobeat legobeat Jun 10, 2024

Choose a reason for hiding this comment

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

Note: Mismatching provider here (e.g. supplying HTTPS_PROVIDERS.mainnet) did not cause tests to fail. This suggests that some further coverage could be desired, to catch situations were blockTracker and provider inadvertently are on different chains/networks?

dbrans
dbrans previously approved these changes Jun 10, 2024
@legobeat legobeat requested review from dbrans, adonesky1 and a team June 10, 2024 17:52
@legobeat legobeat force-pushed the test-fix-transaction-controller-test-providers branch from ac84c1c to a8b210c Compare June 10, 2024 17:57
@legobeat
Copy link
Contributor Author

legobeat commented Jun 10, 2024

(lint fix due to rebase on top of #4382)

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Ideally we shouldn't need to create specific providers for specific use cases. We shouldn't be hitting the network at all, so if we do need a provider we should be able to make a fake version using FakeProvider. But, as a fix this PR makes sense.

'sepolia',
'customNetworkClientId-1',
] as const) {
MOCK_BLOCK_TRACKERS[network] = buildMockBlockTracker(network);
Copy link
Contributor

@mcmire mcmire Jun 10, 2024

Choose a reason for hiding this comment

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

The problem this solves is a good example of why sharing variables among tests by initializing them outside of all tests can lead to misleading and difficult to debug behavior (since a variable may have state that's changed in one test and then bleeds over into another test). This fix makes sense, but if we really need specific block trackers and providers it would be better to create them on the fly in tests, using a helper function to assist. See here for more: https://github.com/MetaMask/contributor-docs/blob/main/docs/unit-testing.md#reset-shared-variables (expand the triangle for an example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully agreed! The end state here is still not as I'd like it either but had to draw the line somewhere ;^^

@legobeat legobeat merged commit e1a71e5 into MetaMask:main Jun 10, 2024
113 checks passed
@MetaMask MetaMask deleted a comment Jun 11, 2024
legobeat added a commit that referenced this pull request Jun 11, 2024
legobeat added a commit that referenced this pull request Jun 11, 2024
legobeat added a commit that referenced this pull request Jun 11, 2024
legobeat added a commit that referenced this pull request Jun 11, 2024
legobeat added a commit that referenced this pull request Jun 12, 2024
legobeat added a commit to legobeat/metamask-controllers that referenced this pull request Jun 12, 2024
legobeat added a commit that referenced this pull request Jun 12, 2024
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.

3 participants