Skip to content

Commit 33edae7

Browse files
carbolymerana-pantilie
authored andcommitted
Fix tests, add more explanation to TODOs
1 parent f871fb0 commit 33edae7

File tree

7 files changed

+89
-70
lines changed

7 files changed

+89
-70
lines changed

cardano-cli/src/Cardano/CLI/Compatible/Json/Friendly.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ renderCertificate sbe = \case
746746
, "anchor " .= mbAnchor
747747
]
748748
-- TODO: Dijkstra
749+
-- Pattern is complete for Conway, we're missing COMPLETE pragma for Dijkstra in ledger to remove this error
749750
_ -> error "renderCertificate: Dijkstra"
750751
where
751752
conwayToObject

cardano-cli/src/Cardano/CLI/Environment.hs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE GADTs #-}
2+
{-# LANGUAGE ScopedTypeVariables #-}
23
{-# LANGUAGE TypeApplications #-}
34

45
-- | This module defines constants derived from the environment.
@@ -16,9 +17,11 @@ import Cardano.Api
1617
, CardanoEra (..)
1718
, NetworkId (..)
1819
, NetworkMagic (..)
20+
, forEraMaybeEon
1921
)
2022
import Cardano.Api.Experimental qualified as Exp
2123

24+
import Data.Type.Equality
2225
import Data.Word (Word32)
2326
import System.Environment qualified as IO
2427
import System.IO qualified as IO
@@ -43,21 +46,16 @@ getEnvCli = do
4346
, envCliAnyCardanoEra = mCardanoEra
4447
}
4548

46-
anyCardanoEraToEra :: AnyCardanoEra -> Maybe (Exp.Era Exp.ConwayEra)
47-
anyCardanoEraToEra (AnyCardanoEra era) =
48-
case era of
49-
ByronEra -> Nothing
50-
ShelleyEra -> Nothing
51-
AllegraEra -> Nothing
52-
MaryEra -> Nothing
53-
AlonzoEra -> Nothing
54-
BabbageEra -> Nothing
55-
ConwayEra -> Just Exp.ConwayEra
56-
DijkstraEra -> Nothing
57-
58-
envCliEra :: EnvCli -> Maybe (Exp.Era Exp.ConwayEra)
49+
envCliEra
50+
:: forall era
51+
. Exp.IsEra era
52+
=> EnvCli
53+
-> Maybe (Exp.Era era)
5954
envCliEra envCli = do
60-
anyCardanoEraToEra =<< envCliAnyCardanoEra envCli
55+
AnyCardanoEra cardanoEra <- envCliAnyCardanoEra envCli
56+
era1 <- forEraMaybeEon cardanoEra
57+
Refl <- testEquality era1 (Exp.useEra @era)
58+
pure era1
6159

6260
-- | If the environment variable @CARDANO_NODE_NETWORK_ID@ is set, then return the network id therein.
6361
-- Otherwise, return 'Nothing'.

cardano-cli/src/Cardano/CLI/EraBased/Genesis/CreateTestnetData/Run.hs

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ where
2828
import Cardano.Api hiding (ConwayEra)
2929
import Cardano.Api.Ledger (StandardCrypto, StrictMaybe (SNothing))
3030
import Cardano.Api.Ledger qualified as L
31-
import Cardano.Ledger.Compactible qualified as L
3231

3332
import Cardano.CLI.Byron.Genesis (NewDirectory (NewDirectory))
3433
import Cardano.CLI.Byron.Genesis qualified as Byron
@@ -57,17 +56,20 @@ import Cardano.CLI.Type.Error.NodeCmdError
5756
import Cardano.CLI.Type.Error.StakePoolCmdError
5857
import Cardano.CLI.Type.Key
5958
import Cardano.Crypto.Hash qualified as Crypto
59+
import Cardano.Ledger.Compactible qualified as L
6060
import Cardano.Prelude (canonicalEncodePretty)
6161
import Cardano.Protocol.Crypto qualified as C
6262

63+
import RIO (throwString)
64+
6365
import Control.DeepSeq (NFData, deepseq)
64-
import Control.Monad (forM, forM_, unless, void, when)
66+
import Control.Monad (forM, forM_, unless, when)
6567
import Data.Aeson.Encode.Pretty qualified as Aeson
6668
import Data.Bifunctor (Bifunctor (..))
6769
import Data.ByteString (ByteString)
6870
import Data.ByteString.Char8 qualified as BS
6971
import Data.ByteString.Lazy.Char8 qualified as LBS
70-
import Data.Function ((&))
72+
import Data.Functor
7173
import Data.Functor.Identity (Identity)
7274
import Data.ListMap (ListMap (..))
7375
import Data.Map.Strict (Map)
@@ -82,6 +84,7 @@ import Data.Word (Word64)
8284
import GHC.Exts (IsList (..))
8385
import GHC.Generics (Generic)
8486
import GHC.Num (Natural)
87+
import GHC.Stack
8588
import Lens.Micro ((^.))
8689
import System.Directory
8790
import System.FilePath ((</>))
@@ -373,9 +376,9 @@ runGenesisCreateTestNetDataCmd
373376
stuffedUtxoAddrs <-
374377
liftIO $ Lazy.replicateM (fromIntegral numStuffedUtxo) $ genStuffedAddress network
375378

376-
let conwayGenesis' =
377-
addDRepsToConwayGenesis dRepKeys (map snd delegatorKeys) conwayGenesis
378-
& addCommitteeToConwayGenesis ccColdKeys
379+
conwayGenesis' <-
380+
addDRepsToConwayGenesis dRepKeys (map snd delegatorKeys) conwayGenesis
381+
<&> addCommitteeToConwayGenesis ccColdKeys
379382

380383
let stake = second L.ppId . mkDelegationMapEntry <$> delegations
381384
stakePools = [(L.ppId poolParams', poolParams') | poolParams' <- snd . mkDelegationMapEntry <$> delegations]
@@ -467,15 +470,20 @@ runGenesisCreateTestNetDataCmd
467470
toCredential (CommitteeColdKeyHash v) = L.KeyHashObj v
468471

469472
addDRepsToConwayGenesis
470-
:: [VerificationKey DRepKey]
473+
:: forall m
474+
. HasCallStack
475+
=> MonadIO m
476+
=> [VerificationKey DRepKey]
471477
-> [VerificationKey StakeKey]
472478
-> L.ConwayGenesis
473-
-> L.ConwayGenesis
474-
addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis =
475-
conwayGenesis
476-
{ L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
477-
, L.cgInitialDReps = initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys
478-
}
479+
-> m L.ConwayGenesis
480+
addDRepsToConwayGenesis dRepKeys stakingKeys conwayGenesis = do
481+
cgInitialDReps <- initialDReps (L.ucppDRepDeposit $ L.cgUpgradePParams conwayGenesis) dRepKeys
482+
pure $
483+
conwayGenesis
484+
{ L.cgDelegs = delegs (zip stakingKeys (case dRepKeys of [] -> []; _ -> cycle dRepKeys))
485+
, L.cgInitialDReps
486+
}
479487
where
480488
delegs
481489
:: [(VerificationKey StakeKey, VerificationKey DRepKey)]
@@ -491,17 +499,22 @@ runGenesisCreateTestNetDataCmd
491499
initialDReps
492500
:: Lovelace
493501
-> [VerificationKey DRepKey]
494-
-> ListMap (L.Credential L.DRepRole) L.DRepState
495-
initialDReps minDeposit =
496-
fromList
497-
. map
502+
-> m (ListMap (L.Credential L.DRepRole) L.DRepState)
503+
initialDReps minDeposit verificationKeys = do
504+
drepDeposit <-
505+
maybe
506+
(throwString ("Initial DRep deposit value cannot be compacted: " <> show minDeposit))
507+
pure
508+
(L.toCompact $ max (L.Coin 1_000_000) minDeposit)
509+
pure
510+
. fromList
511+
$ map
498512
( \c ->
499513
( verificationKeyToDRepCredential c
500514
, L.DRepState
501515
{ L.drepExpiry = EpochNo 1_000
502516
, L.drepAnchor = SNothing
503-
-- FIXME: toCompactPartial might be unsafe here
504-
, L.drepDeposit = L.toCompactPartial $ max (L.Coin 1_000_000) minDeposit
517+
, L.drepDeposit
505518
, L.drepDelegs = Set.empty -- We don't need to populate this field (field "initialDReps"."keyHash-*"."delegators" in the JSON)
506519
-- because its content is derived from the "delegs" field ("cgDelegs" above). In other words, when the Conway genesis is applied,
507520
-- DRep delegations are computed from the "delegs" field. In the future the "delegators" field may
@@ -510,6 +523,7 @@ runGenesisCreateTestNetDataCmd
510523
}
511524
)
512525
)
526+
verificationKeys
513527

514528
verificationKeyToDRepCredential
515529
:: VerificationKey DRepKey -> L.Credential L.DRepRole

cardano-cli/src/Cardano/CLI/EraBased/Governance/Actions/Run.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,14 @@ addCostModelsToEraBasedProtocolParametersUpdate
377377
addCostModelsToEraBasedProtocolParametersUpdate
378378
AlonzoEraOnwardsDijkstra
379379
_
380-
_ = error "addCostModelsToEraBasedProtocolParametersUpdate: Dijkstra not supported yet" -- TODO: Dijkstra
380+
_ =
381+
-- TODO: Dijkstra
382+
-- Add new protocol parameters from
383+
-- https://github.com/IntersectMBO/cardano-ledger/blob/master/eras/dijkstra/src/Cardano/Ledger/Dijkstra/PParams.hs#L75
384+
-- to
385+
-- https://github.com/IntersectMBO/cardano-api/blob/master/cardano-api/src/Cardano/Api/ProtocolParameters.hs#L190
386+
-- and remove this `error`
387+
error "addCostModelsToEraBasedProtocolParametersUpdate: Dijkstra not supported yet"
381388

382389
runGovernanceActionTreasuryWithdrawalCmd
383390
:: forall era e

cardano-cli/test/cardano-cli-test/Test/Cli/Run/Hash.hs

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
module Test.Cli.Run.Hash where
66

7-
-- import Control.Monad (void)
8-
-- import Control.Monad.Catch (MonadCatch)
9-
-- import Control.Monad.Trans.Resource (MonadResource)
10-
-- import GHC.Stack
7+
import Control.Monad (void)
8+
import Control.Monad.Catch (MonadCatch)
9+
import Control.Monad.Trans.Resource (MonadResource)
10+
import GHC.Stack
1111

1212
import Test.Cardano.CLI.Util
1313

14-
import Hedgehog (Property)
15-
-- import Hedgehog qualified as H
16-
-- import Hedgehog.Extras qualified as H
14+
import Hedgehog
15+
import Hedgehog qualified as H
16+
import Hedgehog.Extras qualified as H
1717

1818
hprop_hash_trip :: Property
1919
hprop_hash_trip =
@@ -27,31 +27,30 @@ hprop_hash_trip =
2727
-- @cardano-cli --text --out-file file2@ yields
2828
-- similar @file1@ and @file2@ files.
2929
hash_trip_fun
30-
-- :: (MonadTest m, MonadCatch m, MonadResource m, H.MonadBaseControl IO m, HasCallStack)
31-
:: String -> m ()
30+
:: (MonadTest m, MonadCatch m, MonadResource m, H.MonadBaseControl IO m, HasCallStack)
31+
=> String -> m ()
3232
hash_trip_fun input =
33-
undefined input
34-
-- H.moduleWorkspace "tmp" $ \tempDir -> do
35-
-- hashFile <- noteTempFile tempDir "hash.txt"
36-
37-
-- hash <-
38-
-- execCardanoCLI
39-
-- [ "hash"
40-
-- , "anchor-data"
41-
-- , "--text"
42-
-- , input
43-
-- ]
44-
45-
-- void $
46-
-- execCardanoCLI
47-
-- [ "hash"
48-
-- , "anchor-data"
49-
-- , "--text"
50-
-- , input
51-
-- , "--out-file"
52-
-- , hashFile
53-
-- ]
54-
55-
-- hashFromFile <- H.readFile hashFile
56-
57-
-- H.diff hash (==) hashFromFile
33+
H.moduleWorkspace "tmp" $ \tempDir -> do
34+
hashFile <- noteTempFile tempDir "hash.txt"
35+
36+
hash <-
37+
execCardanoCLI
38+
[ "hash"
39+
, "anchor-data"
40+
, "--text"
41+
, input
42+
]
43+
44+
void $
45+
execCardanoCLI
46+
[ "hash"
47+
, "anchor-data"
48+
, "--text"
49+
, input
50+
, "--out-file"
51+
, hashFile
52+
]
53+
54+
hashFromFile <- H.readFile hashFile
55+
56+
H.diff hash (==) hashFromFile

cardano-cli/test/cardano-cli-test/files/input/conway/create-cardano/genesis.conway.spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dRepDeposit": 0,
2626
"dRepActivity": 0,
2727
"minFeeRefScriptCostPerByte": 0,
28-
"plutusV3CostModel": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
28+
"plutusV3CostModel": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
2929
"constitution": {
3030
"anchor": {
3131
"url": "",

cardano-cli/test/cardano-cli-test/files/input/conway/genesis.conway.spec.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"dRepDeposit": 0,
2626
"dRepActivity": 0,
2727
"minFeeRefScriptCostPerByte": 0,
28-
"plutusV3CostModel": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
28+
"plutusV3CostModel": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
2929
"constitution": {
3030
"anchor": {
3131
"url": "",

0 commit comments

Comments
 (0)