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

refactor(assets-controllers): Simplify TokenDetectionController tests #3744

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jan 8, 2024

Explanation

The TokenDetectionController tests have been refactored to use mocks instead of real controller instances, and to use the withController pattern to simplify controller setup and ensure that polling has stopped after each test.

A getDefaultTokenListState function has been added to the TokenListController to enable us to use that default state in tests.

One test was added to the TokensController tests to prevent a coverage drop (it was previously being tested indirectly via the TokenDetectionController tests).

References

Relates to #3708

Changelog

@metamask/assets-controllers

Added

  • Add getDefaultTokenListState function to `TokenListController

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

@Gudahtt

This comment was marked as resolved.

@Gudahtt Gudahtt force-pushed the refactor-token-detection-controller-tests branch from 6d24b1a to 07da387 Compare January 8, 2024 16:25
@Gudahtt Gudahtt force-pushed the refactor-token-balances-controller-tests branch from 262b25e to 000b301 Compare January 8, 2024 18:13
Base automatically changed from refactor-token-balances-controller-tests to main January 8, 2024 18:20
@Gudahtt Gudahtt force-pushed the refactor-token-detection-controller-tests branch from 946694b to 665f73c Compare January 8, 2024 18:21
@Gudahtt Gudahtt marked this pull request as ready for review January 8, 2024 18:21
@Gudahtt Gudahtt requested a review from a team as a code owner January 8, 2024 18:21
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.

Just one suggestion, but otherwise looks good.

@@ -157,58 +145,6 @@ function buildTokenDetectionControllerMessenger(
}

describe('TokenDetectionController', () => {
let tokenDetection: TokenDetectionController;
Copy link
Contributor

Choose a reason for hiding this comment

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

Look at all this code go! 👋🏻

[sampleTokenA.address]: new BN(1),
});
await tokenDetection.detectTokens();
describe('enabled', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about using:

Suggested change
describe('enabled', () => {
describe('when the "disabled" option is false', () => {

or something like that?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, done in e80e936

The `TokenDetectionController` tests have been refactored to use mocks
instead of real controller instances, and to use the `withController`
pattern to simplify controller setup and ensure that polling has
stopped after each test.

A `getDefaultTokenListState` function has been added to the
`TokenListController` to enable us to use that default state in
tests.

Relates to #3708
@Gudahtt Gudahtt force-pushed the refactor-token-detection-controller-tests branch from 665f73c to 0b9bede Compare January 8, 2024 19:04
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.

Looks good!

@Gudahtt Gudahtt merged commit a0a381c into main Jan 8, 2024
136 checks passed
@Gudahtt Gudahtt deleted the refactor-token-detection-controller-tests branch January 8, 2024 20:38
@Gudahtt Gudahtt mentioned this pull request Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants