Skip to content

test(erc4626spec): add ERC-4626 spec compliance tests for OffchainAssetReceiptVault#324

Open
thedavidmeister wants to merge 2 commits into
mainfrom
2026-06-21-issue-303-erc4626-spec-compliance
Open

test(erc4626spec): add ERC-4626 spec compliance tests for OffchainAssetReceiptVault#324
thedavidmeister wants to merge 2 commits into
mainfrom
2026-06-21-issue-303-erc4626-spec-compliance

Conversation

@thedavidmeister

Copy link
Copy Markdown
Collaborator

Summary

Adds OffchainAssetReceiptVault.erc4626spec.t.sol with 9 fuzz tests covering the ERC-4626 spec invariants flagged in #303.

max* MUST NOT revert (ERC-4626 §4.8):

  • testMaxWithdrawAnyIdDoesNotRevert — fuzz all (owner, id) pairs including id == 0
  • testMaxWithdrawZeroIdDoesNotRevert — explicit id == 0 pin (the concrete bug from Add ERC4626 spec compliance test suite #303)
  • testMaxRedeemAnyIdDoesNotRevert — fuzz all (owner, id) pairs
  • testMaxDepositAnyOwnerDoesNotRevert — pure, always returns type(uint256).max
  • testMaxMintAnyOwnerDoesNotRevert — pure, always returns type(uint256).max

Inverse relationship (ERC-4626 §4.9):

  • testConvertToInversesconvertToAssets(convertToShares(x)) == x for all x > 0 and all id > 0

Immutability (ERC-4626 §4.1):

  • testAssetImmutableAfterOperationsasset() unchanged before/after deposit+withdraw

preview* consistency (ERC-4626 §4.3–4.6):

  • testPreviewDepositMatchesDepositpreviewDeposit(assets, 0) matches shares credited by deposit
  • testPreviewRedeemMatchesRedeempreviewRedeem(shares, 1) matches assets returned by redeem

For this vault _shareRatioUserAgnostic always returns 1e18, so the 1:1 invariant holds across all functions. The id == 0 divide-by-zero guard (added to ReceiptVault.maxWithdraw) is correct and these tests pin it against future subclass overrides.

Note: totalAssets consistency and decimals/rounding are already covered by the existing OffchainAssetReceiptVault.totalAssets.t.sol and OffchainAssetReceiptVault.convertToAssets.t.sol/convertToShares.t.sol.

Closes #303

Co-Authored-By: Claude noreply@anthropic.com

…etReceiptVault

Adds OffchainAssetReceiptVault.erc4626spec.t.sol with 9 fuzz tests
covering the ERC-4626 invariants flagged in #303:

- testMaxWithdrawAnyIdDoesNotRevert: maxWithdraw MUST NOT revert for any
  (owner, id) pair, including id == 0 (share ratio is always 1e18 here,
  so no divide-by-zero risk, but pins the invariant against future overrides)
- testMaxWithdrawZeroIdDoesNotRevert: specific pin for id == 0 asserting
  the return value is 0 rather than a panic
- testMaxRedeemAnyIdDoesNotRevert: maxRedeem MUST NOT revert for any pair
- testMaxDepositAnyOwnerDoesNotRevert: pure function, always returns max
- testMaxMintAnyOwnerDoesNotRevert: pure function, always returns max
- testConvertToInverses: convertToAssets(convertToShares(x)) == x for all x,
  verifying the inverse relationship required by the spec
- testAssetImmutableAfterOperations: asset() returns the same address before
  and after deposit/withdraw
- testPreviewDepositMatchesDeposit: previewDeposit matches the shares
  credited by the corresponding deposit call under the same state
- testPreviewRedeemMatchesRedeem: previewRedeem matches the assets paid
  by the corresponding redeem call under the same state

Closes #303

Co-Authored-By: Claude <noreply@anthropic.com>
@thedavidmeister thedavidmeister self-assigned this Jun 21, 2026
@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@thedavidmeister, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 14 minutes and 47 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 607d362c-a6fd-48e6-980f-55af2b0efdbf

📥 Commits

Reviewing files that changed from the base of the PR and between 8f68b12 and 3f4f392.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • test/src/concrete/vault/OffchainAssetReceiptVault.erc4626spec.t.sol
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2026-06-21-issue-303-erc4626-spec-compliance

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude <noreply@anthropic.com>
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.

Add ERC4626 spec compliance test suite

1 participant