core
core copied to clipboard
TokenDetectionController: Write comprehensive unit tests
We should review the tests for TokenDetectionController and ensure that the functionality and edge cases are well-covered by tests and that there are no duplicative or unnecessary tests. A new contributor should be able to use the tests as a guideline for what the controller does.
There were API changes made recently to TokenDetectionController, so we should focus on backfilling tests for those especially.
Merging TokenDetectionController
with DetectTokensController
has introduced new behaviors and branches. These are some new tests that will need to be added:
- Correctly responds to
KeyringController:lock
,KeyringController:unlock
,AccountsController:selectedAccountChange
,PreferencesController:stateChange
events.- Resets polling interval to default value (3 minutes) when responding to these events.
- Correctly responds to the
isUnlocked
property of keyring-controller being set to false when the controller is initialized.- Specifically, passive auto token-detection in response to subscribe events is blocked.
- Correctly pulls the
useTokenDetection
property using thePreferences:getState
action when controller is initialized.- Performs token detection on legacy token list if selected network is Mainnet even if token detection is disabled by preferences controller.
- Does not detect tokens that are already in the tokens-controller
detectedTokens
list. -
trackMetaMetricsEvent
is called with the expected options object arguments.
The following are the recommended minimum target coverage thresholds, defined by the threshold values prior to the changes introduced by #3775.
branches: 88.36,
functions: 97.08,
lines: 97.23,
statements: 97.28,
Hey team! Please add your planning poker estimate with Zenhub @Gudahtt @kanthesha @MajorLift @mcmire @mikesposito
The scope of this ticket no longer includes the API changes caused by the consolidation with DetectTokensController
.
However, it needs to update the tests in the extension detect-tokens.test.js
file to align with the current controller API, and integrate these test cases into the core TokenDetectionController.test.ts
file. This effort will include removing redundant or obsolete tests.
- https://github.com/MetaMask/core/issues/3661 is fixed by https://github.com/MetaMask/core/pull/3938 (https://github.com/MetaMask/core/pull/3938/commits/f060ced256d24ce5069873e44686cd5d152960d0), but no unit tests were written for this behavior change.
- We should write these tests in this ticket.