Skip to content

Port Hardhat-only test coverage to Foundry - #1432

Merged
ryanio merged 10 commits into
mainfrom
ryan/port-hardhat-tests
Nov 10, 2026
Merged

ryanio merged 10 commits into
mainfrom
ryan/port-hardhat-tests

Conversation

@ryanio

@ryanio ryanio commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #1431. Part 6 of the modernization series, and the first of two PRs that remove Hardhat. The next PR deletes the Hardhat suite and every npm dependency. This one adds the Foundry tests that make that safe.

How the gaps were found

Both suites ran under coverage and the line and branch reports were compared. Two things in the existing tooling hid gaps:

  • The Hardhat coverage config never instrumented seaport-core, because it's a dependency import. The comparison used a temporary config that added it.
  • CI's forge coverage drops libraries unless it gets --include-libs, so codecov has never shown Seaport's core logic. This PR fixes the CI command (see below).

Everything Hardhat covered that Foundry didn't fell into four areas: SeaportRouter and the PausableZone pair (zero Foundry coverage), the admin and getter half of ConduitController, and about 15 revert paths. None of the four test/findings specs covered a line Foundry misses.

New tests (90)

File Tests Ported from
test/foundry/SeaportRouter.t.sol 10 all of router.spec.ts
test/foundry/zone/PausableZone.t.sol 18 the PausableZone block of zone.spec.ts, plus getSeaportMetadata and supportsInterface
test/foundry/conduit/ConduitController.t.sol 13 conduit.spec.ts: create reverts, channels with swap-and-pop, two-step ownership, every getter, Conduit.updateChannel reverts
TransferHelperSingleRecipientTest.sol, TransferHelperMultipleRecipientsTest.sol 8 transferhelper.spec.ts: zero conduit key, zero recipient, receiver reverting with data
test/foundry/GetterTests.t.sol 4 getter.spec.ts: deploys Seaport itself and checks name() and the domain separator
test/foundry/RevertParity.t.sol 25 revert paths from revert.spec.ts, counter.spec.ts, advanced.spec.ts and conduit.spec.ts
test/foundry/NonReentrantPreCancun.t.sol 12 new, see below

Tests that touch Seaport run against both the optimized and reference builds, like the existing suites. Reverts are checked with exact selectors and arguments, including many Hardhat only checked as bare reverts.

The pre-Cancun file deploys Seaport under Shanghai (vm.setEvmVersion), so it starts with the SSTORE reentrancy guard, as it does on chains that lacked TSTORE at deployment. It runs the existing reentrancy matrix in that mode, then tests __activateTstore after a simulated upgrade. Neither suite covered that path before. Hardhat only reached it by accident, because its coverage config fell back to Shanghai.

Hardhat test to Foundry test mapping

Router: every it in router.spec.ts maps one to one (testGetAllowedSeaportContracts, testFulfillThroughSingleSeaport, testFulfillThroughMultipleSeaports, testMaximumFulfilledAcrossSeaports, testFulfillThroughMultipleSeaportsWithConduit, testSkipsInvalidOrders, testRevertsOnAllErrorsExceptNoSpecifiedOrdersAvailable, testRevertsIfExcessEtherCannotBeReturned, testCannotReenterThroughReceive, testReceiveOnlyFromAllowedSeaports).

PausableZone: each of the 16 tests maps to one Foundry test with the same intent. Two Hardhat titles describe something other than what the test does ("caller being offerer" and "non-owner tries to self destruct"), and the ports follow the test bodies.

ConduitController: deployNewConduit fixture to testCreateConduit, plus testCreateConduitRevertsInvalidCreator, testCreateConduitRevertsConduitAlreadyExists, testUpdateChannelRevertsCallerIsNotOwner, testConduitUpdateChannelRevertsInvalidController, testConduitUpdateChannelRevertsChannelStatusAlreadySet, testAddsAndRemovesChannels, testTransferOwnershipTwoStep, testOwnerOf, testGetKey, testGetPotentialOwner, testGetChannelStatus, testGetChannels. Each case runs against ConduitController and ReferenceConduitController.

Revert parity: basic InvalidMsgValue both ways, ERC721 amount above 1 (basic, standard, via conduit), InsufficientNativeTokensSupplied for offerer and additional recipient, OrderPartiallyFilled via basic fulfillment, validate() skipping a contract order and rejecting a length mismatch, a match whose consideration aggregates to zero, a 1/1 partial fill after earlier partial fills, Seaport as an ether recipient, a zone failing with no revert data, and the TokenTransferrer non-token, falsey-return and batch-1155 bubbling cases.

Dropped on purpose: Hardhat's generic checkExpectedEvents and withBalanceChecks wrappers on success fills, replaced by explicit balance, ownership and order-status checks; the callStatic dry run before each zone match call, since the real call's return value and logs are checked; and the contract offerer that Hardhat deployed for the validate() test, which validate() never calls.

Coverage

Forge line coverage before and after, with seaport-core included:

File Before After
helpers/SeaportRouter.sol 0/60 60/60
zones/PausableZoneController.sol 0/67 67/67
zones/PausableZone.sol 0/39 38/39
seaport-core ConduitController.sol 35/96 96/96
seaport-core Conduit.sol 40/42 42/42
helpers/TransferHelper.sol 65/69 69/69
seaport-core BasicOrderFulfiller.sol 220/224 224/224
seaport-core ReentrancyGuard.sol 39/88 88/88
seaport-core OrderValidator.sol 178/191 183/191

The CI coverage job now passes --include-libs with a filter that keeps seaport-core and drops the other libraries. docs/Development.md gives the same command.

Found along the way

  • SeaportRouter's tally loop only advances its index when an order was filled. If a Seaport returns a skipped order in a batch, the loop runs until it's out of gas. This is the bug fix(SeaportRouter): terminate tally loop on partially-available batches #1415 proposed fixing. The deployed router is frozen, so the fix is noted in docs/Seaport-1.7-candidates.md for a future router deployment. No test pins the broken behavior.
  • Hardhat's "reverts with generic error if it has insufficient gas to copy revert data" test points at a recipient that reverts with no data, so it never reached the gas check. The port adds a token that returns about 100 KB of revert data to reach it.

Verification

  • FOUNDRY_PROFILE=test forge test: 574 passed (484 before).
  • FOUNDRY_PROFILE=reference MOAT_PROFILE=reference forge test: 574 passed.
  • FOUNDRY_PROFILE=offerers forge test: 39 passed.
  • DeployedBytecode.t.sol passes, scripts/frozen-contracts.sha256 checks clean, and no file under contracts/ or lib/ changed.
  • scripts/lint.sh check passes. The new test files add no compiler warnings.

🤖 Generated with Claude Code

ryanio and others added 8 commits November 10, 2026 02:46
Add Foundry coverage that only the Hardhat suite had:

- ConduitController.t.sol: createConduit reverts, channel add/remove
  including swap-and-pop and the desynced close branch, two-step
  ownership transfer, every getter, and Conduit.updateChannel's
  InvalidController and ChannelStatusAlreadySet. Each case runs against
  the optimized and reference controllers.
- TransferHelper single and multiple recipient tests: InvalidConduit for
  a zero conduit key, RecipientCannotBeZeroAddress, and
  ERC721ReceiverErrorRevertBytes.
- GetterTests: deploy Seaport itself and check name(), its raw
  encoding, information(), and the domain separator on the current and
  a changed chain id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
forge coverage skips libraries unless given --include-libs, so the
codecov report never showed Seaport's core logic. Include libraries and
filter out the third-party ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add SeaportRouter.t.sol covering all 10 tests in test/router.spec.ts and
zone/PausableZone.t.sol covering the 16 tests in the "Zone - PausableZone"
block of test/zone.spec.ts, plus getSeaportMetadata and supportsInterface.
Tests that touch Seaport run against both the optimized and reference
builds. The router and controller deploy from optimized-out, or with `new`
under SEAPORT_COVERAGE so coverage attributes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RevertParity.t.sol ports the revert and edge cases only revert.spec.ts,
counter.spec.ts, advanced.spec.ts and conduit.spec.ts reached: basic order
InvalidMsgValue and InsufficientNativeTokensSupplied, ERC721 amount > 1 on
the basic and standard paths, OrderPartiallyFilled via basic fulfillment,
validate() contract-order skip and length mismatch, the zero-amount
aggregation early return in a match, 1/1 after earlier partial fills,
receive() rejection, zone calls that revert with no data, and
TokenTransferrer generic failures (non-token accounts, falsey ERC20,
batch 1155 bubbling, encoding check, uncopyable revert data). Each runs
against the optimized and reference builds and pins both payloads where
they differ.

NonReentrantPreCancun.t.sol deploys Seaport on Shanghai via
vm.setEvmVersion, so it starts with the SSTORE guard, and runs the
NonReentrant matrix, basic and advanced fills, receive() rejection, and
every __activateTstore outcome (not supported, guard set, already active,
successful activation followed by the matrix on the activated branch)
plus TloadTestContractDeploymentFailed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI 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.

🟡 Changes recommended

The conduit test does not exercise conduit-backed transfers or assert key forwarding, so it can pass even if the router ignores fulfillerConduitKey.

1 open issue
What changed in this PR

Ports Hardhat-only coverage to Foundry ahead of the planned Hardhat removal, while leaving deployed contracts unchanged.

Changes:

  • Adds router, zone, conduit-controller, getter, transfer-helper, and revert-path tests.
  • Exercises pre-Cancun reentrancy guards and activation of transient storage after an upgrade.
  • Includes Seaport core libraries in coverage reports and documents the deferred router fix.
File Description
test/​foundry/​zone/​PausableZone.t.sol Tests zone fulfillment, permissions, ownership, and interfaces.
test/​foundry/​utils/​RevertParityMocks.sol Adds mocks for empty and oversized revert data.
test/​foundry/​TransferHelperSingleRecipientTest.sol Adds single-recipient transfer failure cases.
test/​foundry/​TransferHelperMultipleRecipientsTest.sol Adds multiple-recipient transfer failure cases.
test/​foundry/​SeaportRouter.t.sol Ports router fulfillment, refund, and access tests.
test/​foundry/​RevertParity.t.sol Covers missing revert paths and fulfillment edge cases.
test/​foundry/​NonReentrantPreCancun.t.sol Tests storage guards and post-upgrade transient-storage activation.
test/​foundry/​GetterTests.t.sol Checks Seaport wrapper names and domain separators.
test/​foundry/​conduit/​ConduitController.t.sol Tests conduit creation, channels, ownership, and getters.
docs/​Seaport-1.7-candidates.md Records the router tally-loop fix for a future deployment.
docs/​Development.md Documents coverage commands that include Seaport core.
.github/​workflows/​test.yml Includes Seaport core in CI coverage while filtering other libraries.

Review effort: Balanced

Comment thread test/foundry/SeaportRouter.t.sol Resolved
ryanio and others added 2 commits November 10, 2026 03:53
The router is the fulfiller and pays only native consideration, so no
conduit moves tokens in the conduit variant. Check the exact call to
each Seaport instead, including the fulfiller conduit key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanio
ryanio changed the base branch from ryan/bump-deps to main November 10, 2026 18:14
@ryanio
ryanio merged commit ed6c011 into main Nov 10, 2026
12 of 22 checks passed
@ryanio
ryanio deleted the ryan/port-hardhat-tests branch November 10, 2026 22:15
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.

4 participants