test(precompiles): add golden tests for asset V1 (BOP-423)#3972
Open
stephancill wants to merge 10 commits into
Open
test(precompiles): add golden tests for asset V1 (BOP-423)#3972stephancill wants to merge 10 commits into
stephancill wants to merge 10 commits into
Conversation
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Collaborator
🟡 Heimdall Review Status
|
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
…pwire Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Comment on lines
+24
to
+29
| use alloy_sol_types::{SolCall, SolError, SolEvent, SolInterface, SolValue}; | ||
| use base_common_genesis::BaseUpgrade; | ||
| use base_common_precompiles::{ | ||
| Asset, AssetAccounting, AssetV1, AssetVersion, AssetVersions, B20_MAX_SUPPLY_CAP, B20AssetInit, | ||
| B20AssetStorage, B20AssetToken, B20PolicyType, B20TokenRole, IB20, IB20Asset, InMemoryPolicy, | ||
| NoopPrecompileCallObserver, PermitArgs, TokenAccounting, |
Contributor
There was a problem hiding this comment.
Three unused imports: SolError (line 24), Asset and TokenAccounting (lines 27, 29). Clippy should catch these — remove them to keep CI clean.
Suggested change
| use alloy_sol_types::{SolCall, SolError, SolEvent, SolInterface, SolValue}; | |
| use base_common_genesis::BaseUpgrade; | |
| use base_common_precompiles::{ | |
| Asset, AssetAccounting, AssetV1, AssetVersion, AssetVersions, B20_MAX_SUPPLY_CAP, B20AssetInit, | |
| B20AssetStorage, B20AssetToken, B20PolicyType, B20TokenRole, IB20, IB20Asset, InMemoryPolicy, | |
| NoopPrecompileCallObserver, PermitArgs, TokenAccounting, | |
| use alloy_sol_types::{SolCall, SolEvent, SolInterface, SolValue}; | |
| use base_common_genesis::BaseUpgrade; | |
| use base_common_precompiles::{ | |
| AssetAccounting, AssetV1, AssetVersion, AssetVersions, B20_MAX_SUPPLY_CAP, B20AssetInit, | |
| B20AssetStorage, B20AssetToken, B20PolicyType, B20TokenRole, IB20, IB20Asset, InMemoryPolicy, | |
| NoopPrecompileCallObserver, PermitArgs, |
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
… goldens Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
… (review) Co-authored-by: OpenCode <opencode-noreply@coinbase.com>
Contributor
Review SummaryTest-only PR adding 2711 lines of golden/snapshot tests for Asset V1. No production code changes. FindingUnused imports (already flagged inline): General observations
|
Contributor
❌ base-std fork tests did not runThe build or setup step failed before any tests could execute. Check the workflow logs for details.
|
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.
Summary
Adds a golden/snapshot test suite pinning current Asset V1 behavior of the B-20 precompile (BOP-423), before/while it is frozen behind the versioning seam from #3969 (BOP-417). Sibling of the stablecoin golden suite (#3971).
Every op is driven through the version-resolver-gated path (
inner(..., BaseUpgrade::Beryl)→AssetVersions::from_base_upgrade→ V1) against the real EVM-backedB20AssetStorageoverHashMapStorageProvider, withInMemoryPolicyfor deterministic allow/block. Each mutation case asserts:hash_state) — a reference baseline for the CI frozen-manifest check (BOP-421).Plus a dedicated
golden_gas_footprintstest pinning each mutating op's storage-access footprint — the(SLOAD, SSTORE, KECCAK256)op counts, the deterministic gas-schedule-independent signal that drives real gas — so an extra storage access in V1 is caught even when bytes/state/events match.Op coverage: the shared B-20 surface (transfer / transferFrom / approve + memo variants, mint / burn / burnBlocked, pause / unpause, updateSupplyCap|Name|Symbol|ContractURI, grant/revoke/renounce/renounceLastAdmin/setRoleAdmin, updatePolicy, permit, all reads + role/policy constants), plus the asset-specific ops:
updateMultiplier(operator role, zero-reject),updateExtraMetadata(metadata role, empty-key reject),batchMint(mint role, length-mismatch / empty-batch),announce(operator role, internal-call loop, reused-id, nested-announce, malformed / failing internal call), and the scaled-balance reads (multiplier,toScaledBalance,toRawBalance,scaledBalanceOf, configurabledecimals). Privileged vs unprivileged viainner_with_privilegevsinner; the guard envelope (nonpayable / uninitialized / pre-Beryl) viadispatch_with_observer; plus the factorygrant_role_uncheckedbootstrap.Edge cases: zero-address (sender / receiver / approver), insufficient balance/allowance, supply-cap, paused, policy-blocked sender + executor policy, empty-feature-set, last-admin protection (revoke/renounce), expired permit, and every unprivileged authorization revert (caller lacking the required role) — including the asset-specific
batchMint/updateExtraMetadata/announce/updateMultiplierrole checks.Meta coverage guard: a compile-time
v1_op_coverage_checklist— an exhaustivematchover the generatedIB20Calls/IB20AssetCallsenums whose arms reference the covering golden#[test]fns. Adding an ABI op fails the build (non-exhaustive match) until a golden is added; renaming/removing a golden fails the build (missing fn reference). This intentionally couples to the shared ABI surface: when a future version extends the ABI, this suite is expected to be updated to assert the new op reverts for V1.No source/logic changes — frozen V1 is untouched; only a new integration test file and one
[[test]]stanza are added.Coverage
Region/line coverage of the frozen logic from this suite alone (via
cargo llvm-cov, this test target only):b20_asset/logic/v1.rs: 100% line, 100% function, 91.1% regionb20_asset/dispatch.rs: 97.2% line, 92.7% regionRemaining uncovered regions are defensive
checked_*().ok_or_else(under_overflow)closures (incl. the scaled-balance overflow guard) and&&/||short-circuit halves — unreachable without contriving arithmetic overflow.Testing
cargo test -p base-common-precompiles --features test-utils --test b20_asset_v1_golden→ 98 passedcargo test -p base-common-precompiles --features test-utils) green; clippy (--all-targets) + fmt cleanState hashes are pinned; regenerate with
BLESS_GOLDEN=1 cargo test ... -- --nocapture(documented in the file header).