Skip to content

Conversation

@salimtb
Copy link
Contributor

@salimtb salimtb commented Jan 23, 2026

Explanation

This PR adds comprehensive unit tests for the new @metamask/assets-controller package to ensure code quality and maintainability.

Current state: The assets-controller package was recently introduced with a middleware-based architecture for unified asset management across all blockchain networks. However, test coverage was limited, leaving critical code paths untested.

Changes in this PR:

  • Added unit tests for all data sources:
    • AccountsApiDataSource (18 tests, includes timer cleanup fix using .unref() to prevent Jest worker process hanging)
    • BackendWebsocketDataSource (19 tests)
    • PriceDataSource (29 tests)
    • TokenDataSource (20 tests)
    • SnapDataSource (47 tests)
  • Added unit tests for DetectionMiddleware (13 tests, 100% coverage)
  • Expanded unit tests for AssetsController (42 tests, coverage increased from 33% to 81%)

Test architecture patterns used:

  • setupController / withController helper functions for consistent test setup
  • Proper messenger mocking with MOCK_ANY_NAMESPACE
  • Test cleanup to prevent resource leaks
  • it.each for parameterized tests where applicable
  • Flat test structure avoiding deeply nested describe blocks

References

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 communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Significantly increases test coverage and validates core behaviors across the new middleware-based assets stack.

  • Add extensive unit tests for AssetsController, DetectionMiddleware, and data sources: AbstractDataSource, AccountsApiDataSource, BackendWebsocketDataSource, PriceDataSource, RpcDataSource, and SnapDataSource
  • Cover subscriptions, middleware chaining, lifecycle/events (app/keyring/network), WebSocket handling, pricing polls, and snap-based balances
  • Update RpcDataSource to import BalanceFetcher, MulticallClient, and TokenDetector from evm-rpc-services (was rpc-datasource)
  • Update CHANGELOG.md to note test additions

Written by Cursor Bugbot for commit 9b08b0a. This will update automatically on new commits. Configure here.

@salimtb salimtb changed the title Feat/clean up new controller Feat: clean up new controller Jan 23, 2026
@salimtb salimtb changed the title Feat: clean up new controller feat: clean up new controller Jan 23, 2026
@salimtb salimtb force-pushed the feat/clean-up-new-controller branch from 4f7397d to ba1250b Compare January 23, 2026 16:14
@salimtb salimtb marked this pull request as ready for review January 23, 2026 16:34
@salimtb salimtb requested review from a team as code owners January 23, 2026 16:34
@salimtb salimtb added this pull request to the merge queue Jan 23, 2026
Merged via the queue into main with commit 6e9bb95 Jan 23, 2026
302 checks passed
@salimtb salimtb deleted the feat/clean-up-new-controller branch January 23, 2026 16:39
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.

3 participants