test(erc4626spec): add ERC-4626 spec compliance tests for OffchainAssetReceiptVault#324
test(erc4626spec): add ERC-4626 spec compliance tests for OffchainAssetReceiptVault#324thedavidmeister wants to merge 2 commits into
Conversation
…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>
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Adds
OffchainAssetReceiptVault.erc4626spec.t.solwith 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 includingid == 0testMaxWithdrawZeroIdDoesNotRevert— explicitid == 0pin (the concrete bug from Add ERC4626 spec compliance test suite #303)testMaxRedeemAnyIdDoesNotRevert— fuzz all(owner, id)pairstestMaxDepositAnyOwnerDoesNotRevert— pure, always returnstype(uint256).maxtestMaxMintAnyOwnerDoesNotRevert— pure, always returnstype(uint256).maxInverse relationship (ERC-4626 §4.9):
testConvertToInverses—convertToAssets(convertToShares(x)) == xfor allx > 0and allid > 0Immutability (ERC-4626 §4.1):
testAssetImmutableAfterOperations—asset()unchanged before/after deposit+withdrawpreview* consistency (ERC-4626 §4.3–4.6):
testPreviewDepositMatchesDeposit—previewDeposit(assets, 0)matches shares credited bydeposittestPreviewRedeemMatchesRedeem—previewRedeem(shares, 1)matches assets returned byredeemFor this vault
_shareRatioUserAgnosticalways returns1e18, so the 1:1 invariant holds across all functions. Theid == 0divide-by-zero guard (added toReceiptVault.maxWithdraw) is correct and these tests pin it against future subclass overrides.Note:
totalAssetsconsistency and decimals/rounding are already covered by the existingOffchainAssetReceiptVault.totalAssets.t.solandOffchainAssetReceiptVault.convertToAssets.t.sol/convertToShares.t.sol.Closes #303
Co-Authored-By: Claude noreply@anthropic.com