core icon indicating copy to clipboard operation
core copied to clipboard

TokenDetectionController: Write comprehensive unit tests

Open mcmire opened this issue 1 year ago • 4 comments

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.

mcmire avatar Aug 18 '23 18:08 mcmire

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 the Preferences: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,

MajorLift avatar Jan 22 '24 00:01 MajorLift

Hey team! Please add your planning poker estimate with Zenhub @Gudahtt @kanthesha @MajorLift @mcmire @mikesposito

desi avatar Jan 22 '24 16:01 desi

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.

MajorLift avatar Feb 20 '24 15:02 MajorLift

  • 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.

MajorLift avatar Feb 27 '24 16:02 MajorLift