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 10, 2025
1 parent 942cf60 commit a2ce41c
Show file tree
Hide file tree
Showing 7 changed files with 1,306 additions and 0 deletions.
104 changes: 104 additions & 0 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/Action.hs
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,108 @@ 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 too small costmodel size/"'@
hprop_golden_conway_governance_action_create_protocol_parameters_too_small_costmodel_size
:: Property
hprop_golden_conway_governance_action_create_protocol_parameters_too_small_costmodel_size =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- This file has 165 entries, whereas PV1 requires 166
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v1-too-small.json"
-- This file has 184 entries, whereas PV2 requires 185
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v2-too-small.json"
-- This file has 184 entries, whereas PV3 requires 297
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v3-too-small.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

-- | Execute me with:
-- @cabal test cardano-cli-golden --test-options '-p "/golden conway governance action create protocol parameters too large costmodel size/"'@
hprop_golden_conway_governance_action_create_protocol_parameters_too_large_costmodel_size
:: Property
hprop_golden_conway_governance_action_create_protocol_parameters_too_large_costmodel_size =
propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do
-- From https://input-output-rnd.slack.com/archives/CCRB7BU8Y/p1727096158830419?thread_ts=1727089226.813099&cid=CCRB7BU8Y
--
-- Having too large models is fine:
--
-- Ziyang Liu
-- 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.
-- Theoretically they can also possibly decrease but that's very unlikely, certainly not below the current numbers.

-- This file has 167 entries, whereas PV1 requires 166
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v1-too-large.json"
-- This file has 186 entries, whereas PV2 requires 185
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v2-too-large.json"
-- This file has 298 entries, whereas PV3 requires 297
runOnCostModelFile
tempDir
"test/cardano-cli-golden/files/input/governance/costmodels-v3-too-large.json"
where
runOnCostModelFile tempDir costModelsFile = do
stakeAddressVKeyFile <- H.note "test/cardano-cli-golden/files/input/governance/stake-address.vkey"

actionFile <- noteTempFile tempDir "action"

H.noteShowM_ $
H.execCardanoCLI
[ "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
]

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,170 @@
{ "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,
0,
0,
0,
0,
0,
1,
1
]
}
Loading

0 comments on commit a2ce41c

Please sign in to comment.