Skip to content

fix(test): gracefully handle BigInt serialization in jest worker - #1161

Open
Sigmabrogz wants to merge 1 commit into
VeloraDEX:masterfrom
Sigmabrogz:fix/bigint-serialization
Open

fix(test): gracefully handle BigInt serialization in jest worker#1161
Sigmabrogz wants to merge 1 commit into
VeloraDEX:masterfrom
Sigmabrogz:fix/bigint-serialization

Conversation

@Sigmabrogz

@Sigmabrogz Sigmabrogz commented Mar 21, 2026

Copy link
Copy Markdown

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 setupFiles hook (jest.setup.ts) that defines BigInt.prototype.toJSON to 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.

@Sigmabrogz
Sigmabrogz force-pushed the fix/bigint-serialization branch from cab752e to d4c8855 Compare March 21, 2026 16:04

@cursor cursor Bot 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, enable autofix in the Cursor dashboard.

Comment thread jest.setup.ts
Object.defineProperty(BigInt.prototype, 'toJSON', {
get() {
return () => this.toString();
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

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.

TypeError: Do not know how to serialize a BigInt Error

1 participant