Skip to content

Commit ad333c5

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

File tree

4 files changed

+607
-0
lines changed

4 files changed

+607
-0
lines changed

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

+46
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,50 @@ 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 bad costmodel size/"'@
504+
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size
505+
:: Property
506+
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size =
507+
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
508+
-- This file has 184 entries, whereas PV1 requires 166
509+
-- TODO @smelc this test does not pass: the command succeeds, whereas it should fail!
510+
-- runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v1-wrong.json"
511+
-- This file has 184 entries, whereas PV2 requires 185
512+
runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v2-wrong.json"
513+
-- This file has 184 entries, whereas PV3 requires 297
514+
runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v3-wrong.json"
515+
where
516+
runOnCostModelFile tempDir costModelsFile = do
517+
stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey"
518+
519+
actionFile <- noteTempFile tempDir "action"
520+
521+
(exitCode, _stdout, stderr) <-
522+
H.noteShowM $
523+
H.execDetailCardanoCLI
524+
[ "conway"
525+
, "governance"
526+
, "action"
527+
, "create-protocol-parameters-update"
528+
, "--anchor-url"
529+
, "example.com"
530+
, "--anchor-data-hash"
531+
, "c7ddb5b493faa4d3d2d679847740bdce0c5d358d56f9b1470ca67f5652a02745"
532+
, "--mainnet"
533+
, "--deposit-return-stake-verification-key-file"
534+
, stakeAddressVKeyFile
535+
, "--governance-action-deposit"
536+
, "12345"
537+
, "--cost-model-file"
538+
, costModelsFile
539+
, "--out-file"
540+
, actionFile
541+
]
542+
543+
H.assert (exitCode /= ExitSuccess)
544+
H.assertWith stderr $ \msg -> "The decoded cost model has the wrong size" `isInfixOf` msg
545+
500546
hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails :: Property
501547
hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails =
502548
propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
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+
43357,
163+
32,
164+
32247,
165+
32,
166+
38314,
167+
32,
168+
35892428,
169+
10,
170+
9462713,
171+
1021,
172+
10,
173+
38887044,
174+
32947,
175+
10,
176+
0,
177+
0,
178+
0,
179+
0,
180+
0,
181+
0,
182+
0,
183+
0,
184+
0,
185+
0
186+
]
187+
}

0 commit comments

Comments
 (0)