fix(test): gracefully handle BigInt serialization in jest worker - #1161
fix(test): gracefully handle BigInt serialization in jest worker#1161Sigmabrogz wants to merge 1 commit into
Conversation
cab752e to
d4c8855
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| Object.defineProperty(BigInt.prototype, 'toJSON', { | ||
| get() { | ||
| return () => this.toString(); | ||
| }, |
There was a problem hiding this comment.
Getter-only property breaks existing BigInt.prototype.toJSON assignment
High Severity
Object.defineProperty here creates an accessor property on BigInt.prototype.toJSON with a getter but no setter, and with the default configurable: false. The existing code in maverick-v1-pool.ts uses a direct assignment ((BigInt.prototype as any).toJSON = function () { ... }). Since tsconfig.json has "strict": true, all code runs in strict mode — assigning to a setter-less accessor property throws a TypeError. Any test importing MaverickV1EventPool (e.g., maverick-v1-events.test.ts) will crash at module load time.


Fixes #744. This PR gracefully handles the 'Do not know how to serialize a BigInt' error when jest-worker stringifies objects containing BigInt data between worker and parent processes. By monkey-patching BigInt.prototype.toJSON in both the parent execution context and the jest setup env, the tests can be reliably processed without crashing when evaluating dex integration validations.
Note
Low Risk
Test-only configuration change that monkey-patches
BigInt.prototype.toJSON; low blast radius but could affect any tests relying on default BigInt serialization behavior.Overview
Adds a Jest
setupFileshook (jest.setup.ts) that definesBigInt.prototype.toJSONto stringify BigInt values during JSON serialization.This prevents Jest worker/parent message passing from throwing "Do not know how to serialize a BigInt" when test data includes BigInts.
Written by Cursor Bugbot for commit d4c8855. This will update automatically on new commits. Configure here.