Skip to content

Add valueOf golden coverage in Spec.Data.Budget#7800

Draft
Unisay wants to merge 2 commits into
masterfrom
yura/issue-2242-valueof-golden-gate
Draft

Add valueOf golden coverage in Spec.Data.Budget#7800
Unisay wants to merge 2 commits into
masterfrom
yura/issue-2242-valueof-golden-gate

Conversation

@Unisay

@Unisay Unisay commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds direct golden coverage for PlutusLedgerApi.V1.Data.Value.valueOf in Spec.Data.Budget, alongside the existing snapshots for gt, geq, and currencySymbolValueOf. 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 valueOf directly. Any regression in valueOf would only surface downstream through callers like currencySymbolValueOf, assetClassValueOf, or geq, where the diagnosis is harder. The new snapshots act as a first-line regression gate.

What changed

  • Spec.Data.Budget: registers compiledValueOf and five golden bundles.
  • Five new files in plutus-tx-plugin/test-ledger-api/Spec/Data/Budget/9.6/:
    • valueOf.golden.pir — PIR-readable snapshot of the compiled valueOf.
    • 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 value1 helper (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:

  • Plinth compilation of valueOf (newtype distillation, builtin-call generation).
  • Cost-model parameters that affect equalsByteString, unsafeDataAs*, caseList'.
  • Any incidental change to Map.toBuiltinList or the underlying Data.AssocMap representation.

It does not catch semantic regressions (those are caught by Spec.Data.Value.test_valueOf from #7797, which is a differential CEK-vs-Haskell property test).

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

Execution Budget Golden Diff

b4d1df4 (master) vs d97a546

output

This comment will get updated when changes are made.

@Unisay Unisay force-pushed the yura/issue-2242-optimal-valueof branch from 0ac70fa to cd7c252 Compare May 28, 2026 11:28
@Unisay Unisay force-pushed the yura/issue-2242-valueof-golden-gate branch from 592ee78 to 3f78512 Compare May 28, 2026 11:29
@Unisay Unisay force-pushed the yura/issue-2242-optimal-valueof branch from cd7c252 to 8271c9e Compare May 28, 2026 11:43
@Unisay Unisay force-pushed the yura/issue-2242-valueof-golden-gate branch from 3f78512 to 614ac9e Compare May 28, 2026 11:43
@Unisay Unisay force-pushed the yura/issue-2242-optimal-valueof branch from 8271c9e to 613670c Compare May 28, 2026 11:50
@Unisay Unisay force-pushed the yura/issue-2242-valueof-golden-gate branch from 614ac9e to ef47fc2 Compare May 28, 2026 11:50
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.
@Unisay Unisay force-pushed the yura/issue-2242-optimal-valueof branch from 613670c to b4d1df4 Compare May 29, 2026 10:35
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.).
@Unisay Unisay force-pushed the yura/issue-2242-valueof-golden-gate branch from ef47fc2 to d97a546 Compare May 29, 2026 10:36
Base automatically changed from yura/issue-2242-optimal-valueof to master June 2, 2026 10:04
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.

1 participant