Skip to content

Commit a2ce41c

Browse files
committed
Add tests for wrong cost models sizes
1 parent 942cf60 commit a2ce41c

File tree

7 files changed

+1306
-0
lines changed

7 files changed

+1306
-0
lines changed

cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import Cardano.Api (MonadIO)
99
import Control.Monad (void)
1010
import Control.Monad.Catch (MonadCatch)
1111
import Control.Monad.Trans.Control (MonadBaseControl)
12+
import Data.List (isInfixOf)
13+
import System.Exit (ExitCode (ExitSuccess))
1214

1315
import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataHash2,
1416
exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2,
@@ -497,6 +499,108 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update_partial_
497499
"test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update-partial-costmodels.action"
498500
H.diffFileVsGoldenFile actionFile goldenActionFile
499501

502+
-- | Execute me with:
503+
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway governance action create protocol parameters too small costmodel size/"'@
504+
hprop_golden_conway_governance_action_create_protocol_parameters_too_small_costmodel_size
505+
:: Property
506+
hprop_golden_conway_governance_action_create_protocol_parameters_too_small_costmodel_size =
507+
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
508+
-- This file has 165 entries, whereas PV1 requires 166
509+
runOnCostModelFile
510+
tempDir
511+
"test/cardano-cli-golden/files/input/governance/costmodels-v1-too-small.json"
512+
-- This file has 184 entries, whereas PV2 requires 185
513+
runOnCostModelFile
514+
tempDir
515+
"test/cardano-cli-golden/files/input/governance/costmodels-v2-too-small.json"
516+
-- This file has 184 entries, whereas PV3 requires 297
517+
runOnCostModelFile
518+
tempDir
519+
"test/cardano-cli-golden/files/input/governance/costmodels-v3-too-small.json"
520+
where
521+
runOnCostModelFile tempDir costModelsFile = do
522+
stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey"
523+
524+
actionFile <- noteTempFile tempDir "action"
525+
526+
(exitCode, _stdout, stderr) <-
527+
H.noteShowM $
528+
H.execDetailCardanoCLI
529+
[ "conway"
530+
, "governance"
531+
, "action"
532+
, "create-protocol-parameters-update"
533+
, "--anchor-url"
534+
, "example.com"
535+
, "--anchor-data-hash"
536+
, "c7ddb5b493faa4d3d2d679847740bdce0c5d358d56f9b1470ca67f5652a02745"
537+
, "--mainnet"
538+
, "--deposit-return-stake-verification-key-file"
539+
, stakeAddressVKeyFile
540+
, "--governance-action-deposit"
541+
, "12345"
542+
, "--cost-model-file"
543+
, costModelsFile
544+
, "--out-file"
545+
, actionFile
546+
]
547+
548+
H.assert (exitCode /= ExitSuccess)
549+
H.assertWith stderr $ \msg -> "The decoded cost model has the wrong size" `isInfixOf` msg
550+
551+
-- | Execute me with:
552+
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway governance action create protocol parameters too large costmodel size/"'@
553+
hprop_golden_conway_governance_action_create_protocol_parameters_too_large_costmodel_size
554+
:: Property
555+
hprop_golden_conway_governance_action_create_protocol_parameters_too_large_costmodel_size =
556+
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
557+
-- From https://input-output-rnd.slack.com/archives/CCRB7BU8Y/p1727096158830419?thread_ts=1727089226.813099&cid=CCRB7BU8Y
558+
--
559+
-- Having too large models is fine:
560+
--
561+
-- Ziyang Liu
562+
-- There should not be any check on the upper bound. The number of parameters for V1, V2 and V3 can increase at any time as we add new builtins or other features to the languages.
563+
-- Theoretically they can also possibly decrease but that's very unlikely, certainly not below the current numbers.
564+
565+
-- This file has 167 entries, whereas PV1 requires 166
566+
runOnCostModelFile
567+
tempDir
568+
"test/cardano-cli-golden/files/input/governance/costmodels-v1-too-large.json"
569+
-- This file has 186 entries, whereas PV2 requires 185
570+
runOnCostModelFile
571+
tempDir
572+
"test/cardano-cli-golden/files/input/governance/costmodels-v2-too-large.json"
573+
-- This file has 298 entries, whereas PV3 requires 297
574+
runOnCostModelFile
575+
tempDir
576+
"test/cardano-cli-golden/files/input/governance/costmodels-v3-too-large.json"
577+
where
578+
runOnCostModelFile tempDir costModelsFile = do
579+
stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey"
580+
581+
actionFile <- noteTempFile tempDir "action"
582+
583+
H.noteShowM_ $
584+
H.execCardanoCLI
585+
[ "conway"
586+
, "governance"
587+
, "action"
588+
, "create-protocol-parameters-update"
589+
, "--anchor-url"
590+
, "example.com"
591+
, "--anchor-data-hash"
592+
, "c7ddb5b493faa4d3d2d679847740bdce0c5d358d56f9b1470ca67f5652a02745"
593+
, "--mainnet"
594+
, "--deposit-return-stake-verification-key-file"
595+
, stakeAddressVKeyFile
596+
, "--governance-action-deposit"
597+
, "12345"
598+
, "--cost-model-file"
599+
, costModelsFile
600+
, "--out-file"
601+
, actionFile
602+
]
603+
500604
hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails :: Property
501605
hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails =
502606
propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
{ "PlutusV1": [
2+
812,
3+
1,
4+
1,
5+
1000,
6+
571,
7+
0,
8+
1,
9+
1000,
10+
24177,
11+
4,
12+
1,
13+
1000,
14+
32,
15+
117366,
16+
10475,
17+
4,
18+
23000,
19+
100,
20+
23000,
21+
100,
22+
23000,
23+
100,
24+
23000,
25+
100,
26+
23000,
27+
100,
28+
23000,
29+
100,
30+
100,
31+
100,
32+
23000,
33+
100,
34+
19537,
35+
32,
36+
175354,
37+
32,
38+
46417,
39+
4,
40+
221973,
41+
511,
42+
0,
43+
1,
44+
89141,
45+
32,
46+
497525,
47+
14068,
48+
4,
49+
2,
50+
196500,
51+
453240,
52+
220,
53+
0,
54+
1,
55+
1,
56+
1000,
57+
28662,
58+
4,
59+
2,
60+
245000,
61+
216773,
62+
62,
63+
1,
64+
1060367,
65+
12586,
66+
1,
67+
208512,
68+
421,
69+
1,
70+
187000,
71+
1000,
72+
52998,
73+
1,
74+
80436,
75+
32,
76+
43249,
77+
32,
78+
1000,
79+
32,
80+
80556,
81+
1,
82+
57667,
83+
4,
84+
1000,
85+
10,
86+
197145,
87+
156,
88+
1,
89+
197145,
90+
156,
91+
1,
92+
204924,
93+
473,
94+
1,
95+
208896,
96+
511,
97+
1,
98+
52467,
99+
32,
100+
64832,
101+
32,
102+
65493,
103+
32,
104+
22558,
105+
32,
106+
16563,
107+
32,
108+
76511,
109+
32,
110+
196500,
111+
453240,
112+
220,
113+
0,
114+
1,
115+
1,
116+
69522,
117+
11687,
118+
0,
119+
1,
120+
60091,
121+
32,
122+
196500,
123+
453240,
124+
220,
125+
0,
126+
1,
127+
1,
128+
196500,
129+
453240,
130+
220,
131+
0,
132+
1,
133+
1,
134+
1159724,
135+
392670,
136+
0,
137+
2,
138+
806990,
139+
30482,
140+
4,
141+
1927926,
142+
82523,
143+
4,
144+
265318,
145+
0,
146+
4,
147+
0,
148+
85931,
149+
32,
150+
205665,
151+
812,
152+
1,
153+
1,
154+
41182,
155+
32,
156+
212342,
157+
32,
158+
31220,
159+
32,
160+
32696,
161+
32,
162+
0,
163+
0,
164+
0,
165+
0,
166+
0,
167+
1,
168+
1
169+
]
170+
}

0 commit comments

Comments
 (0)