test(b20): add Rust-parity gap coverage + guard mock-only privileged tests#146
Draft
amiecorso wants to merge 3 commits into
Draft
test(b20): add Rust-parity gap coverage + guard mock-only privileged tests#146amiecorso wants to merge 3 commits into
amiecorso wants to merge 3 commits into
Conversation
…tests Adds base-std unit tests for externally-observable behaviors the Rust precompile suite covers but base-std did not exercise (surfaced by a Rust -> base-std test-parity audit of the B20 precompiles): - supply: zero-amount mint / burn / burnBlocked no-ops, exact supply-cap boundary, multi-call mint accumulation - erc20: self-transfer no-inflation, privileged sender/receiver policy bypass, external-allowlist sender/receiver allow + sender deny, privileged transferFrom executor-policy bypass - B20Asset: toScaledBalance arithmetic-overflow revert - B20Factory: createB20 invalid-params decode revert Also guards the pre-existing privileged transferFrom / transferFromWithMemo tests under LIVE_PRECOMPILES. Those tests reopen the factory bootstrap window via vm.store on the mock-only `initialized` slot, which the live precompile omits from its namespaced layout; the guard matches the convention already used by the other mock-only tests. Validated in both modes: mock (256 fuzz runs) and fork against the live Rust precompile at base/base main (non-privileged tests pass; privileged tests skip by construction).
Interface Coverage✅ All interface functions have test coverage. |
📊 Forge Coverage (
|
| File | Lines | Stmts | Branches | Funcs |
|---|---|---|---|---|
| 🟢 B20FactoryLib.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockActivationRegistry.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockActivationRegistryStorage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20Asset.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟡 MockB20Factory.sol | 98.95% | 99.08% | 100.00% | 100.00% |
| 🟢 MockB20Stablecoin.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockB20Storage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockPolicyRegistry.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| 🟢 MockPolicyRegistryStorage.sol | 100.00% | 100.00% | 100.00% | 100.00% |
| Total | 99.86% | 99.88% | 100.00% | 100.00% |
Full report: download artifact. To browse locally: make coverage (runs forge coverage + genhtml + opens the HTML report).
✅ Fork tests: all 608 passedbase/base is fully in sync with the base-std spec. |
- drop redundant zero-amount mint/burn/burnBlocked tests (already exercised by the unbounded-fuzz happy-path tests, whose domain includes 0) - simplify the self-transfer no-inflation test to a single transfer - rewrite the privileged transfer sender/receiver-policy bypass tests to reach privilege via a genuine factory bootstrap initCall chain (mint -> updatePolicy -> transfer) instead of a vm.store window reopen, so they run against the live precompile under LIVE_PRECOMPILES - correct the skip rationale on the privileged transferFrom/memo allowance tests: a pre-existing third-party allowance cannot coexist with an open bootstrap window, so there is no fork-reachable construction (the prior slot-layout explanation was misleading) Validation: mock 271 pass / 0 fail / 0 skip; fork 266 pass / 0 fail / 5 skip (the 5 privileged allowance tests) via run-fork-tests.sh against base-anvil.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds base-std unit tests for externally-observable B20 behaviors that the
Rust precompile suite covers but base-std did not exercise, surfaced by a
Rust → base-std test-parity audit of the B20 precompiles.
New coverage
mint/burn/burnBlockedno-ops, exactsupply-cap boundary (
totalSupply + amount == cap), multi-call mintaccumulation
bypass, external-allowlist sender/receiver allow + sender deny (custom
policy id, exercising the registry path beyond the ALWAYS_ALLOW /
ALWAYS_BLOCK sentinels), privileged
transferFromexecutor-policy bypasstoScaledBalancearithmetic-overflow revertcreateB20invalid-params (ABI decode) revertMock-only test guards
Guards the pre-existing privileged
transferFrom/transferFromWithMemotests under
LIVE_PRECOMPILES. They reopen the factory bootstrap window viavm.storeon the mock-onlyinitializedslot, which the live precompileomits from its namespaced layout (it derives init-state from code presence).
This matches the convention the other mock-only tests already use
(
MockB20SlotHelpers,createPolicy_revertOrder, etc.). The 3 newprivileged tests carry the same guard.
Why
These are the "mutation-blindspot" gaps: behaviors the Rust impl asserts but
base-std never exercised, so fork testing couldn't catch a divergence in them.
The canonical example (0-amount) turned out to already agree on both sides
(InvalidAmount is defined but unused) — the tests pin that agreement so a
future re-divergence is caught.
Validation
11 non-privileged new tests pass; the 3 privileged tests skip by
construction. Full suite: 609 passed / 0 failed / 12 skipped.
Notes