Add valueOf golden coverage in Spec.Data.Budget#7800
Draft
Unisay wants to merge 2 commits into
Draft
Conversation
Contributor
0ac70fa to
cd7c252
Compare
592ee78 to
3f78512
Compare
cd7c252 to
8271c9e
Compare
3f78512 to
614ac9e
Compare
8271c9e to
613670c
Compare
614ac9e to
ef47fc2
Compare
Rewrites `PlutusLedgerApi.V1.Data.Value.valueOf` so the non-builtin lookup path walks the underlying `BuiltinList` directly via `unsafeDataAsMap` / `unsafeDataAsB` / `unsafeDataAsI`, compares keys with `equalsByteString`, and short-circuits on the first match. No `Maybe` is materialised: the "absent" answer is `0`, returned in-place by the `nilCase` of each traversal. Avoids `withCurrencySymbol`'s continuation + `Map.lookup`'s `Maybe`-wrapping, and bypasses the `ToData k`/`UnsafeFromData a` dictionary work that `AssocMap.lookup` does per element. Semantics preserved. Adds `Spec.Data.Value.test_valueOf`: a QuickCheck property that compiles `valueOf` via TH, evaluates it on the CEK machine, and compares the result against the host-Haskell `valueOf` for the same inputs. Differential test against the Plinth compiler — any divergence is a compilation bug, not a semantics bug. Budget evidence (lookup matrix, `unsafeDataAsValue` baseline) lives on the companion experimental branch `yura/issue-2242-valueof-evidence`, kept out of this PR to avoid carrying ~96 golden files that would only ever regenerate on upstream plugin/cost-model changes. For IntersectMBO/plutus-private#2242.
613670c to
b4d1df4
Compare
Adds a PIR-readable snapshot and four budget snapshots for the new `valueOf` implementation, registered alongside the existing golden coverage for `gt`, `geq`, and `currencySymbolValueOf`. Scenarios: - valueOf_hit_first: ada-like first-position lookup, exercises short-circuit on the first outer step. - valueOf_hit_middle: key at the middle of the outer map. - valueOf_hit_last: key at the last entry, full outer scan. - valueOf_miss: absent key, full scan with no inner walk. These tests catch regressions in `valueOf` compilation and cost that would otherwise surface only through downstream callers (`currencySymbolValueOf`, `assetClassValueOf`, `geq`, etc.).
ef47fc2 to
d97a546
Compare
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 direct golden coverage for
PlutusLedgerApi.V1.Data.Value.valueOfinSpec.Data.Budget, alongside the existing snapshots forgt,geq, andcurrencySymbolValueOf. Stacks on top of #7797 (the rewrite); merge after #7797.Before this PR there was no golden test that fixed the PIR shape or the CEK cost of
valueOfdirectly. Any regression invalueOfwould only surface downstream through callers likecurrencySymbolValueOf,assetClassValueOf, orgeq, where the diagnosis is harder. The new snapshots act as a first-line regression gate.What changed
Spec.Data.Budget: registerscompiledValueOfand five golden bundles.plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/:valueOf.golden.pir— PIR-readable snapshot of the compiledvalueOf.valueOf_hit_first.golden.eval— short-circuit on the first outer entry.valueOf_hit_middle.golden.eval— key in the middle of the outer map.valueOf_hit_last.golden.eval— key at the last entry, full outer scan.valueOf_miss.golden.eval— absent key, full scan with no inner walk.The scenarios use the existing
value1helper (5 currencies × varying token counts) already defined in the module.Coverage characteristic
This is a static snapshot, not a property test. It catches changes in:
valueOf(newtype distillation, builtin-call generation).equalsByteString,unsafeDataAs*,caseList'.Map.toBuiltinListor the underlyingData.AssocMaprepresentation.It does not catch semantic regressions (those are caught by
Spec.Data.Value.test_valueOffrom #7797, which is a differential CEK-vs-Haskell property test).