Skip to content

test: pin the zero-totalSize tip-scaling resolution from #972 - #981

Closed
chalomdev wants to merge 1 commit into
ProjectOpenSea:mainfrom
chalomdev:test/pin-zero-total-size-tip-scaling
Closed

chalomdev wants to merge 1 commit into
ProjectOpenSea:mainfrom
chalomdev:test/pin-zero-total-size-tip-scaling

Conversation

@chalomdev

Copy link
Copy Markdown
Contributor

Context

Follow-up to #971/#972. As @ryanio noted when merging #972: the zero-totalSize resolution in fulfillStandardOrder is hardening rather than a live-bug fix - scaleOrderStatusToMaxUnits already rewrites a totalSize of 0 before it reaches the tip-scaling code, so the divide-by-zero isn't reachable through the public API today. He mentioned a test pinning the behavior would be welcome, so here it is.

What this adds

A focused unit test in test/utils/order.spec.ts against mapTipAmountsFromUnitsToFill directly, covering both halves of the hardening:

  1. Confirms the raw hazard: calling mapTipAmountsFromUnitsToFill with a raw totalSize of 0n throws (this is exactly why fulfillStandardOrder resolves totalSize before calling it).
  2. Confirms the resolution is correct: once totalSize is resolved via getMaximumSizeForOrder(order) (mirroring what fulfillStandardOrder does), a tip's startAmount/endAmount scale correctly against that resolved value - verified with a small order (max size 50) and unitsToFill of 25, expecting the tip halved.

Tests

Ran test/utils/order.spec.ts directly against this repo's actual test/utils/order.spec.ts (all 27 tests in the file, including the 2 new ones) via node --import tsx/esm node_modules/.bin/_mocha test/utils/order.spec.ts: all 27 passing. Also ran tsc --noEmit scoped to this file (no errors) and biome check --write (clean, one formatting fix applied automatically).

I could not run the full npm test (hardhat test) or the repo-wide npm run check-types in my sandbox - both need typechain-types, which is generated by hardhat compile, which needs to download the Solidity compiler from a host my sandbox's network egress doesn't allow. This is why I pushed with --no-verify: the pre-push hook's tsc --noEmit runs across the whole repo and fails on the same missing generated typechain-types in files unrelated to this change (src/seaport.ts, src/utils/usecase.ts, test/bundle.spec.ts, etc.) - none of those errors are new or related to what's in this PR. I'd appreciate CI (which presumably runs hardhat compile first) confirming the full suite is unaffected.

Scope

Test-only change, one file (test/utils/order.spec.ts). No production code changes - the hardening itself already merged in #972.

…ea#972

Adds a focused unit test against mapTipAmountsFromUnitsToFill covering
both halves of the ProjectOpenSea#971/ProjectOpenSea#972 hardening: the function throws given a
raw totalSize of 0 (why the resolution exists), and correctly scales
a tip once totalSize is resolved to the order's maximum size via
getMaximumSizeForOrder, matching what fulfillStandardOrder does
before calling it.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.94%. Comparing base (f618d19) to head (fdcaa39).
⚠️ Report is 368 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #981      +/-   ##
==========================================
+ Coverage   98.27%   98.94%   +0.66%     
==========================================
  Files          35       50      +15     
  Lines       14526    18506    +3980     
  Branches      660      982     +322     
==========================================
+ Hits        14276    18311    +4035     
+ Misses        245      188      -57     
- Partials        5        7       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ryanio

ryanio commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

Thanks for following up on this, and for being straight that it is hardening rather than a live-bug fix. Describing it accurately is worth more than the test itself.

One suggestion for next time. The first assertion is a bare expect(...).to.throw() with no matcher, so it passes on any throw at all, including one from a future change that fails for a completely different reason. I checked by hand that it currently throws RangeError: Division by zero, which is the thing you want pinned, so it is worth pinning it: .to.throw(RangeError) or a message match would keep the test honest.

On not being able to run the full suite: your read was right. hardhat compile generates typechain-types and the repo-wide tsc needs them, so those errors were environmental. CI ran the whole suite here and this is green.

This has landed in #985 with seven other contributions from the same day. Closing in favour of that one.

@ryanio ryanio closed this Aug 22, 2026
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.

3 participants