Skip to content

Commit ef47fc2

Browse files
committed
Add valueOf golden coverage in Spec.Data.Budget
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.).
1 parent 613670c commit ef47fc2

6 files changed

Lines changed: 107 additions & 0 deletions

File tree

plutus-tx-plugin/test-ledger-api/Spec/Data/Budget.hs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tests =
3131
runTestNested ["test-ledger-api", "Spec", "Data", "Budget"] . pure . testNestedGhc $
3232
[ goldenPirReadable "gt" compiledGt
3333
, goldenPirReadable "currencySymbolValueOf" compiledCurrencySymbolValueOf
34+
, goldenPirReadable "valueOf" compiledValueOf
3435
]
3536
++ testCases
3637

@@ -49,6 +50,9 @@ compiledMintValueBurned = $$(compile [||MintValue.mintValueBurned||])
4950
compiledCurrencySymbolValueOf :: CompiledCode (Value -> CurrencySymbol -> Integer)
5051
compiledCurrencySymbolValueOf = $$(compile [||currencySymbolValueOf||])
5152

53+
compiledValueOf :: CompiledCode (Value -> CurrencySymbol -> TokenName -> Integer)
54+
compiledValueOf = $$(compile [||valueOf||])
55+
5256
mkValue :: [(Integer, [(Integer, Integer)])] -> Value
5357
mkValue = Value . mkCurrencyMap
5458

@@ -177,6 +181,34 @@ testCases =
177181
`unsafeApplyCode` liftCodeDef value2
178182
`unsafeApplyCode` liftCodeDef (toSymbol 6)
179183
)
184+
, goldenEvalCekCatchBudget
185+
"valueOf_hit_first"
186+
( compiledValueOf
187+
`unsafeApplyCode` liftCodeDef value1
188+
`unsafeApplyCode` liftCodeDef (toSymbol 1)
189+
`unsafeApplyCode` liftCodeDef (toToken 100)
190+
)
191+
, goldenEvalCekCatchBudget
192+
"valueOf_hit_middle"
193+
( compiledValueOf
194+
`unsafeApplyCode` liftCodeDef value1
195+
`unsafeApplyCode` liftCodeDef (toSymbol 3)
196+
`unsafeApplyCode` liftCodeDef (toToken 302)
197+
)
198+
, goldenEvalCekCatchBudget
199+
"valueOf_hit_last"
200+
( compiledValueOf
201+
`unsafeApplyCode` liftCodeDef value1
202+
`unsafeApplyCode` liftCodeDef (toSymbol 5)
203+
`unsafeApplyCode` liftCodeDef (toToken 508)
204+
)
205+
, goldenEvalCekCatchBudget
206+
"valueOf_miss"
207+
( compiledValueOf
208+
`unsafeApplyCode` liftCodeDef value1
209+
`unsafeApplyCode` liftCodeDef (toSymbol 99)
210+
`unsafeApplyCode` liftCodeDef (toToken 999)
211+
)
180212
, goldenEvalCekCatchBudget
181213
"mintValueMinted"
182214
( compiledMintValueMinted
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
\(ds :
2+
(\k a -> list (pair data data))
3+
bytestring
4+
((\k a -> list (pair data data)) bytestring integer))
5+
(ds : bytestring)
6+
(ds : bytestring) ->
7+
letrec
8+
!goInner : list (pair data data) -> integer
9+
= \(xs : list (pair data data)) ->
10+
case
11+
integer
12+
xs
13+
[ (\(hd : pair data data) ->
14+
case
15+
(all dead. list (pair data data) -> integer)
16+
(equalsByteString
17+
ds
18+
(unBData (case data hd [(\(l : data) (r : data) -> l)])))
19+
[ (/\dead -> goInner)
20+
, (/\dead ->
21+
\(ds : list (pair data data)) ->
22+
unIData
23+
(case data hd [(\(l : data) (r : data) -> r)])) ]
24+
{all dead. dead})
25+
, 0 ]
26+
in
27+
letrec
28+
!goOuter : list (pair data data) -> integer
29+
= \(xs : list (pair data data)) ->
30+
case
31+
integer
32+
xs
33+
[ (\(hd : pair data data) ->
34+
case
35+
(all dead. list (pair data data) -> integer)
36+
(equalsByteString
37+
ds
38+
(unBData (case data hd [(\(l : data) (r : data) -> l)])))
39+
[ (/\dead -> goOuter)
40+
, (/\dead ->
41+
\(ds : list (pair data data)) ->
42+
goInner
43+
(unMapData
44+
(case
45+
data
46+
hd
47+
[(\(l : data) (r : data) -> r)]))) ]
48+
{all dead. dead})
49+
, 0 ]
50+
in
51+
goOuter ds
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CPU: 1_343_411
2+
Memory: 7_730
3+
AST Size: 89
4+
Flat Size: 248
5+
6+
(con integer 101)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CPU: 4_551_187
2+
Memory: 25_594
3+
AST Size: 89
4+
Flat Size: 248
5+
6+
(con integer 509)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CPU: 2_546_327
2+
Memory: 14_429
3+
AST Size: 89
4+
Flat Size: 248
5+
6+
(con integer 303)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CPU: 2_484_960
2+
Memory: 14_265
3+
AST Size: 89
4+
Flat Size: 249
5+
6+
(con integer 0)

0 commit comments

Comments
 (0)