-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sketch round trip test for cost model adding
- Loading branch information
1 parent
09acbfd
commit 4a81c6c
Showing
3 changed files
with
181 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
cardano-cli/test/cardano-cli-test/Test/Cli/AddCostModels.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
{-# LANGUAGE GADTs #-} | ||
|
||
module Test.Cli.AddCostModels where | ||
|
||
import Cardano.Api | ||
import Cardano.Api.Ledger (StrictMaybe (..)) | ||
import Cardano.Api.ProtocolParameters | ||
|
||
import Cardano.CLI.EraBased.Run.Governance.Actions | ||
import qualified Cardano.Ledger.Alonzo.Scripts as Alonzo | ||
|
||
import qualified Data.Map as Map | ||
|
||
import Test.Gen.Cardano.Api.Typed | ||
|
||
import Hedgehog | ||
import qualified Hedgehog.Gen as Gen | ||
import Hedgehog.Gen.QuickCheck (arbitrary) | ||
|
||
genStrictMaybe :: MonadGen m => m a -> m (StrictMaybe a) | ||
genStrictMaybe gen = | ||
Gen.sized $ \n -> | ||
Gen.frequency [ | ||
(2, pure SNothing), | ||
(1 + fromIntegral n, SJust<$> gen) | ||
] | ||
|
||
genCommonProtocolParametersUpdate :: MonadGen m => m CommonProtocolParametersUpdate | ||
genCommonProtocolParametersUpdate = | ||
CommonProtocolParametersUpdate | ||
<$> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
|
||
genDeprecatedAfterMaryPParams :: MonadGen m => m (DeprecatedAfterMaryPParams era) | ||
genDeprecatedAfterMaryPParams = DeprecatedAfterMaryPParams <$> genStrictMaybe arbitrary | ||
|
||
genShelleyToAlonzoPParams :: MonadGen m => m (ShelleyToAlonzoPParams era) | ||
genShelleyToAlonzoPParams = | ||
ShelleyToAlonzoPParams | ||
<$> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
|
||
genAlonzoOnwardsPParams :: MonadGen m => m (AlonzoOnwardsPParams era) | ||
genAlonzoOnwardsPParams = | ||
AlonzoOnwardsPParams | ||
SNothing -- No cost models here! | ||
<$> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
|
||
genIntroducedInBabbagePParams :: MonadGen m => m (IntroducedInBabbagePParams era) | ||
genIntroducedInBabbagePParams = IntroducedInBabbagePParams <$> genStrictMaybe arbitrary | ||
|
||
genIntroducedInConwayPParams :: MonadGen m => m (IntroducedInConwayPParams era) | ||
genIntroducedInConwayPParams = | ||
IntroducedInConwayPParams | ||
<$> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
<*> genStrictMaybe arbitrary | ||
|
||
genShelleyEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate ShelleyEra) | ||
genShelleyEraBasedProtocolParametersUpdate = | ||
ShelleyEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genDeprecatedAfterMaryPParams | ||
<*> genShelleyToAlonzoPParams | ||
|
||
genAllegraEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate AllegraEra) | ||
genAllegraEraBasedProtocolParametersUpdate = | ||
AllegraEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genDeprecatedAfterMaryPParams | ||
<*> genShelleyToAlonzoPParams | ||
|
||
genMaryEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate MaryEra) | ||
genMaryEraBasedProtocolParametersUpdate = | ||
MaryEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genDeprecatedAfterMaryPParams | ||
<*> genShelleyToAlonzoPParams | ||
|
||
genAlonzoEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate AlonzoEra) | ||
genAlonzoEraBasedProtocolParametersUpdate = | ||
AlonzoEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genShelleyToAlonzoPParams | ||
<*> genAlonzoOnwardsPParams | ||
|
||
genBabbageEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate BabbageEra) | ||
genBabbageEraBasedProtocolParametersUpdate = | ||
BabbageEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genAlonzoOnwardsPParams | ||
<*> genIntroducedInBabbagePParams | ||
|
||
genConwayEraBasedProtocolParametersUpdate :: MonadGen m => m (EraBasedProtocolParametersUpdate ConwayEra) | ||
genConwayEraBasedProtocolParametersUpdate = | ||
ConwayEraBasedProtocolParametersUpdate | ||
<$> genCommonProtocolParametersUpdate | ||
<*> genAlonzoOnwardsPParams | ||
<*> genIntroducedInBabbagePParams | ||
<*> genIntroducedInConwayPParams | ||
|
||
hprop_roundtrip_Alonzo_addCostModelsToEraBasedProtocolParametersUpdate :: Property | ||
hprop_roundtrip_Alonzo_addCostModelsToEraBasedProtocolParametersUpdate = | ||
property $ do | ||
ppu <- forAll genAlonzoEraBasedProtocolParametersUpdate | ||
cmdl <- forAll genCostModel | ||
let lang = Alonzo.getCostModelLanguage cmdl | ||
tripping | ||
(singletonCostModels lang cmdl) | ||
(flip (addCostModelsToEraBasedProtocolParametersUpdate AlonzoEraOnwardsAlonzo) ppu) | ||
getCostModels | ||
where | ||
getCostModels :: EraBasedProtocolParametersUpdate era -> Maybe Alonzo.CostModels | ||
getCostModels (AlonzoEraBasedProtocolParametersUpdate _ _ AlonzoOnwardsPParams {alCostModels = SJust cmdls}) = Just cmdls | ||
getCostModels _ = Nothing | ||
|
||
singletonCostModels lang cmdl = Alonzo.emptyCostModels { Alonzo.costModelsValid = Map.singleton lang cmdl} | ||
|
||
hprop_roundtrip_Babbage_addCostModelsToEraBasedProtocolParametersUpdate :: Property | ||
hprop_roundtrip_Babbage_addCostModelsToEraBasedProtocolParametersUpdate = | ||
property $ do | ||
ppu <- forAll genBabbageEraBasedProtocolParametersUpdate | ||
cmdl <- forAll genCostModel | ||
let lang = Alonzo.getCostModelLanguage cmdl | ||
tripping | ||
(singletonCostModels lang cmdl) | ||
(flip (addCostModelsToEraBasedProtocolParametersUpdate AlonzoEraOnwardsBabbage) ppu) | ||
getCostModels | ||
where | ||
getCostModels :: EraBasedProtocolParametersUpdate era -> Maybe Alonzo.CostModels | ||
getCostModels (AlonzoEraBasedProtocolParametersUpdate _ _ AlonzoOnwardsPParams {alCostModels = SJust cmdls}) = Just cmdls | ||
getCostModels _ = Nothing | ||
|
||
singletonCostModels lang cmdl = Alonzo.emptyCostModels { Alonzo.costModelsValid = Map.singleton lang cmdl} | ||
|
||
hprop_roundtrip_Conway_addCostModelsToEraBasedProtocolParametersUpdate :: Property | ||
hprop_roundtrip_Conway_addCostModelsToEraBasedProtocolParametersUpdate = | ||
property $ do | ||
ppu <- forAll genConwayEraBasedProtocolParametersUpdate | ||
cmdl <- forAll genCostModel | ||
let lang = Alonzo.getCostModelLanguage cmdl | ||
tripping | ||
(singletonCostModels lang cmdl) | ||
(flip (addCostModelsToEraBasedProtocolParametersUpdate AlonzoEraOnwardsConway) ppu) | ||
getCostModels | ||
where | ||
getCostModels :: EraBasedProtocolParametersUpdate era -> Maybe Alonzo.CostModels | ||
getCostModels (AlonzoEraBasedProtocolParametersUpdate _ _ AlonzoOnwardsPParams {alCostModels = SJust cmdls}) = Just cmdls | ||
getCostModels _ = Nothing | ||
|
||
singletonCostModels lang cmdl = Alonzo.emptyCostModels { Alonzo.costModelsValid = Map.singleton lang cmdl} |