Skip to content

Commit

Permalink
Add tests for wrong cost models sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jan 9, 2025
1 parent 942cf60 commit ad333c5
Show file tree
Hide file tree
Showing 4 changed files with 607 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Cardano.Api (MonadIO)
import Control.Monad (void)
import Control.Monad.Catch (MonadCatch)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.List (isInfixOf)
import System.Exit (ExitCode (ExitSuccess))

import Test.Cardano.CLI.Hash (exampleAnchorDataHash, exampleAnchorDataHash2,
exampleAnchorDataIpfsHash, exampleAnchorDataIpfsHash2,
Expand Down Expand Up @@ -497,6 +499,50 @@ hprop_golden_conway_governance_action_create_protocol_parameters_update_partial_
"test/cardano-cli-golden/files/golden/governance/action/conway-create-protocol-parameters-update-partial-costmodels.action"
H.diffFileVsGoldenFile actionFile goldenActionFile

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway governance action create protocol parameters bad costmodel size/"'@
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size
:: Property
hprop_golden_conway_governance_action_create_protocol_parameters_bad_costmodel_size =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- This file has 184 entries, whereas PV1 requires 166
-- TODO @smelc this test does not pass: the command succeeds, whereas it should fail!
-- runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v1-wrong.json"
-- This file has 184 entries, whereas PV2 requires 185
runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v2-wrong.json"
-- This file has 184 entries, whereas PV3 requires 297
runOnCostModelFile tempDir "test/cardano-cli-golden/files/input/governance/costmodels-v3-wrong.json"
where
runOnCostModelFile tempDir costModelsFile = do
stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey"

actionFile <- noteTempFile tempDir "action"

(exitCode, _stdout, stderr) <-
H.noteShowM $
H.execDetailCardanoCLI
[ "conway"
, "governance"
, "action"
, "create-protocol-parameters-update"
, "--anchor-url"
, "example.com"
, "--anchor-data-hash"
, "c7ddb5b493faa4d3d2d679847740bdce0c5d358d56f9b1470ca67f5652a02745"
, "--mainnet"
, "--deposit-return-stake-verification-key-file"
, stakeAddressVKeyFile
, "--governance-action-deposit"
, "12345"
, "--cost-model-file"
, costModelsFile
, "--out-file"
, actionFile
]

H.assert (exitCode /= ExitSuccess)
H.assertWith stderr $ \msg -> "The decoded cost model has the wrong size" `isInfixOf` msg

hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails :: Property
hprop_golden_conway_governance_action_create_hardfork_wrong_hash_fails =
propertyOnce . expectFailure . H.moduleWorkspace "tmp" $ \tempDir -> do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{ "PlutusV1": [
812,
1,
1,
1000,
571,
0,
1,
1000,
24177,
4,
1,
1000,
32,
117366,
10475,
4,
23000,
100,
23000,
100,
23000,
100,
23000,
100,
23000,
100,
23000,
100,
100,
100,
23000,
100,
19537,
32,
175354,
32,
46417,
4,
221973,
511,
0,
1,
89141,
32,
497525,
14068,
4,
2,
196500,
453240,
220,
0,
1,
1,
1000,
28662,
4,
2,
245000,
216773,
62,
1,
1060367,
12586,
1,
208512,
421,
1,
187000,
1000,
52998,
1,
80436,
32,
43249,
32,
1000,
32,
80556,
1,
57667,
4,
1000,
10,
197145,
156,
1,
197145,
156,
1,
204924,
473,
1,
208896,
511,
1,
52467,
32,
64832,
32,
65493,
32,
22558,
32,
16563,
32,
76511,
32,
196500,
453240,
220,
0,
1,
1,
69522,
11687,
0,
1,
60091,
32,
196500,
453240,
220,
0,
1,
1,
196500,
453240,
220,
0,
1,
1,
1159724,
392670,
0,
2,
806990,
30482,
4,
1927926,
82523,
4,
265318,
0,
4,
0,
85931,
32,
205665,
812,
1,
1,
41182,
32,
212342,
32,
31220,
32,
32696,
32,
43357,
32,
32247,
32,
38314,
32,
35892428,
10,
9462713,
1021,
10,
38887044,
32947,
10,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
]
}
Loading

0 comments on commit ad333c5

Please sign in to comment.