Skip to content

test(perps): migrate controller unit tests to core - #8840

Merged
abretonc7s merged 6 commits into
mainfrom
feat/perps/controller-in-core
May 20, 2026
Merged

test(perps): migrate controller unit tests to core#8840
abretonc7s merged 6 commits into
mainfrom
feat/perps/controller-in-core

Conversation

@abretonc7s

@abretonc7sabretonc7s commented May 18, 2026

Copy link
Copy Markdown
Contributor

Explanation

This PR migrates the mobile perps controller unit tests into @metamask/perps-controller so Core owns the controller test suite. It ports the mobile coverage into Core-native tests/src files, splits the largest controller/provider/subscription suites into focused shards, adds shared test helpers, and switches package coverage collection from the placeholder test to real src/**/*.ts coverage.

The package now enforces at least 80% statement/line coverage for the perps controller package. This is test-only and does not change the published runtime API.

Validation performed:

  • yarn workspace @metamask/perps-controller run test --runInBand
    • 82.89% statements
    • 82.89% lines
    • 78.61% functions
    • 70.06% branches
  • yarn eslint 'packages/perps-controller/{src,tests}/**/*.ts'
  • yarn lint:misc --check
  • yarn workspace @metamask/perps-controller run changelog:validate

Known limitation: yarn tsc --build packages/perps-controller/tsconfig.build.json --verbose is blocked by existing workspace dependency type errors outside this PR, first in accounts-controller / snap-account-service keyring exports, so the perps package is skipped by project references.

References

No related Core GitHub issue found for perps controller tests core.

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 (not applicable; test-only migration)
  • I've communicated my changes to consumers by updating changelogs for packages I've changed (not applicable; test-only, no consumer-facing change)
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Low Risk
Low risk since changes are test-only, but they significantly expand and restructure the @metamask/perps-controller Jest suite and relax coverage thresholds, which could affect CI behavior and coverage enforcement.

Overview
Migrates the Perps controller unit test suite into @metamask/perps-controller, adding shared mock helpers (tests/helpers/*) and a large set of new controller tests split across focused shards (PerpsController.*.test.ts).

Updates the package Jest config to collect coverage from real src/**/*.ts (excluding barrel index.ts files) and adjusts enforced global coverage thresholds from 100% to 70% branches / 78% functions / 80% lines+statements.

Reviewed by Cursor Bugbot for commit 3ff0529. Bugbot is set up for automated code reviews on this repo. Configure here.

@abretonc7s
abretonc7s marked this pull request as ready for review May 19, 2026 07:19
@abretonc7s
abretonc7s requested a review from a team as a code ownerMay 19, 2026 07:19
Comment threadpackages/perps-controller/tests/helpers/providerMocks.ts
michalconsensys
michalconsensys previously approved these changes May 19, 2026
@abretonc7s
abretonc7s added this pull request to the merge queueMay 19, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks May 19, 2026
@abretonc7s
abretonc7s added this pull request to the merge queueMay 20, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks May 20, 2026
@abretonc7s
abretonc7s enabled auto-merge May 20, 2026 09:28
Comment threadpackages/perps-controller/tests/helpers/providerMocks.ts
Constructor-initiated refreshEligibility chain (RFFC:getState ->
GeolocationController:getGeolocation) was leaking into depositMockCall
recordings before assertions ran, causing CI failures on Node 18 while
local Node 22 passed due to microtask ordering differences.
submitTransaction now spreads isInternal:true into addTransaction
options (added via main merge). Update both perpsDeposit and
perpsDepositAndOrder assertions to match.

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 24ce9a1. Configure here.

jest.fn() is typeof 'function', not 'object', so the provider-mock
clearing loop never executed. Cleanup still worked via clearAllMocks
in beforeEach, but the selective clear was dead code.
@abretonc7s
abretonc7s added this pull request to the merge queueMay 20, 2026
Merged via the queue into main with commit 5f811f9May 20, 2026
370 checks passed
@abretonc7s
abretonc7s deleted the feat/perps/controller-in-core branch May 20, 2026 14:57
@abretonc7sabretonc7s mentioned this pull request May 22, 2026
4 tasks
pullBot pushed a commit to dmrazzy/core that referenced this pull request May 22, 2026
## Explanation
Minor release of `@metamask/perps-controller` (6.2.0 → 6.3.0).
**Added**
- Per-order slippage controls for market trades
- `vip_tier` / `vip_discount` properties on perps trading events for fee
analytics
- In-app banner during HyperLiquid outages
- Subpath `exports` for `./constants`, `./constants/*`, `./types`,
`./utils/*` so consumers using legacy `node` resolution can deep-import
without losing tree-shaking
**Fixed**
- Resolve trading account against currently selected EVM account so
account switching is honored across providers
- Suppress `User or API Wallet does not exist` Sentry noise from
unfunded wallets
- Auto-approve HyperLiquid builder fee when missing so order submission
succeeds after fresh wallet setup
See `packages/perps-controller/CHANGELOG.md` for full details.
## References
- MetaMask#8871 (perps sync May 21 2026)
- MetaMask#8883 (subpath exports)
- MetaMask#8840 (test migration — internal, omitted from changelog)
## Checklist
- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [ ] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@abretonc7s@michalconsensys