-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PlutusV3 CostModel to UpgradeConwayPParams
Use `updateCostModels` to add them to Conway PParams during tranlation/upgrade from Babbage
- Loading branch information
Showing
14 changed files
with
262 additions
and
157 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
cabal-version: 3.0 | ||
name: cardano-ledger-conway | ||
version: 1.13.1.0 | ||
version: 1.14.0.0 | ||
license: Apache-2.0 | ||
maintainer: [email protected] | ||
author: IOHK | ||
|
@@ -90,7 +90,7 @@ library | |
cardano-ledger-allegra ^>=1.4, | ||
cardano-ledger-alonzo ^>=1.8, | ||
cardano-ledger-babbage ^>=1.8, | ||
cardano-ledger-core ^>=1.11, | ||
cardano-ledger-core ^>=1.11.1, | ||
cardano-ledger-mary ^>=1.5, | ||
cardano-ledger-shelley ^>=1.10, | ||
cardano-slotting, | ||
|
@@ -126,6 +126,7 @@ library testlib | |
Test.Cardano.Ledger.Conway.Imp.RatifySpec | ||
Test.Cardano.Ledger.Conway.Proposals | ||
Test.Cardano.Ledger.Conway.TreeDiff | ||
Test.Cardano.Ledger.Conway.Genesis | ||
|
||
visibility: public | ||
hs-source-dirs: testlib | ||
|
@@ -183,7 +184,6 @@ test-suite tests | |
build-depends: | ||
aeson, | ||
base, | ||
cardano-data, | ||
cardano-ledger-core:testlib, | ||
cardano-ledger-allegra, | ||
cardano-ledger-alonzo:testlib, | ||
|
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
151 changes: 33 additions & 118 deletions
151
eras/conway/impl/test/Test/Cardano/Ledger/Conway/GenesisSpec.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 |
---|---|---|
@@ -1,141 +1,56 @@ | ||
{-# LANGUAGE AllowAmbiguousTypes #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module Test.Cardano.Ledger.Conway.GenesisSpec (spec) where | ||
module Test.Cardano.Ledger.Conway.GenesisSpec (spec, expectedConwayGenesis) where | ||
|
||
import Cardano.Ledger.BaseTypes (textToUrl) | ||
import Cardano.Ledger.CertState (DRep (..), DRepState (..)) | ||
import Cardano.Ledger.Coin (Coin (..)) | ||
import Cardano.Ledger.Conway | ||
import Cardano.Ledger.Conway.Genesis (ConwayGenesis (..)) | ||
import Cardano.Ledger.Conway.Governance (Anchor (..), Committee (..)) | ||
import Cardano.Ledger.Conway.TxCert (Delegatee (..)) | ||
import Cardano.Ledger.Core | ||
import Cardano.Ledger.Credential | ||
import Cardano.Ledger.Crypto (StandardCrypto) | ||
import Cardano.Ledger.Keys | ||
import Cardano.Ledger.Slot (EpochNo (..)) | ||
import Cardano.Ledger.Babbage (Babbage) | ||
import Cardano.Ledger.Conway (Conway) | ||
import Cardano.Ledger.Conway.Core | ||
import Cardano.Ledger.Conway.PParams | ||
import Cardano.Ledger.Plutus.CostModels (costModelsValid) | ||
import Cardano.Ledger.Plutus.Language (Language (PlutusV3)) | ||
import Data.Aeson hiding (Encoding) | ||
import Data.Default.Class (Default (def)) | ||
import qualified Data.ListMap as ListMap | ||
import Data.Map as Map | ||
import Data.Maybe (fromJust) | ||
import Data.Maybe.Strict (StrictMaybe (..)) | ||
import Data.Ratio ((%)) | ||
import Data.Functor.Identity (Identity) | ||
import qualified Data.Map.Strict as Map | ||
import Lens.Micro | ||
import Paths_cardano_ledger_conway (getDataFileName) | ||
import Test.Cardano.Ledger.Common | ||
import Test.Cardano.Ledger.Core.Utils (unsafeBoundRational) | ||
import Test.Cardano.Ledger.Conway.Genesis (expectedConwayGenesis) | ||
import Test.Cardano.Slotting.Numeric () | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "Genesis Golden Spec" $ do | ||
goldenConwayGenesisJSON | ||
describe "ConwayGenesis" $ do | ||
describe "Golden Spec" goldenConwayGenesisJSON | ||
prop "Upgrades" propConwayPParamsUpgrade | ||
|
||
fileName :: String | ||
fileName = "test/data/conway-genesis.json" | ||
|
||
goldenConwayGenesisJSON :: Spec | ||
goldenConwayGenesisJSON = | ||
it "should deserialize to the default value" $ do | ||
let fileName = "test/data/conway-genesis.json" | ||
credMember = | ||
KeyHashObj | ||
(KeyHash "4e88cc2d27c364aaf90648a87dfb95f8ee103ba67fa1f12f5e86c42a") :: | ||
Credential 'ColdCommitteeRole StandardCrypto | ||
scriptMember = | ||
ScriptHashObj | ||
(ScriptHash "4e88cc2d27c364aaf90648a87dfb95f8ee103ba67fa1f12f5e86c42a") :: | ||
Credential 'ColdCommitteeRole StandardCrypto | ||
comm = | ||
Committee | ||
( Map.fromList | ||
[ | ||
( credMember | ||
, EpochNo 1 | ||
) | ||
, | ||
( scriptMember | ||
, EpochNo 2 | ||
) | ||
] | ||
) | ||
(unsafeBoundRational (1 % 2)) :: | ||
Committee Conway | ||
file <- getDataFileName fileName | ||
dec <- eitherDecodeFileStrict' file | ||
cg <- case dec of | ||
Left err -> error ("Failed to deserialize JSON: " ++ err) | ||
Right x -> pure x | ||
let | ||
expectedCg = | ||
def | ||
{ cgCommittee = comm | ||
, cgInitialDReps = | ||
ListMap.fromList | ||
[ | ||
( KeyHashObj | ||
(KeyHash "78301005df84ba67fa1f12f95f8ee10335bc5e86c42afbc593ab4cdd") | ||
, DRepState | ||
{ drepExpiry = 1000 | ||
, drepAnchor = SNothing | ||
, drepDeposit = Coin 5000 | ||
} | ||
) | ||
, | ||
( ScriptHashObj | ||
(ScriptHash "01305df84b078ac5e86c42afbc593ab4cdd67fa1f12f95f8ee10335b") | ||
, DRepState | ||
{ drepExpiry = 300 | ||
, drepAnchor = | ||
SJust $ | ||
Anchor | ||
{ anchorUrl = fromJust $ textToUrl 99 "example.com" | ||
, anchorDataHash = def | ||
} | ||
, drepDeposit = Coin 6000 | ||
} | ||
) | ||
] | ||
, cgDelegs = | ||
ListMap.fromList | ||
[ | ||
( KeyHashObj | ||
(KeyHash "35bc5e86c42afbc593ab4cdd78301005df84ba67fa1f12f95f8ee103") | ||
, DelegVote DRepAlwaysNoConfidence | ||
) | ||
, | ||
( KeyHashObj | ||
(KeyHash "4e88cc2d27c364aaf90648a87dfb95f8ee103ba67fa1f12f5e86c42a") | ||
, DelegVote DRepAlwaysAbstain | ||
) | ||
, | ||
( KeyHashObj | ||
(KeyHash "5df84bcdd7a5f8ee93aafbc500b435bc5e83067fa1f12f9110386c42") | ||
, DelegStake $ KeyHash "0335bc5e86c42afbc578301005df84ba67fa1f12f95f8ee193ab4cdd" | ||
) | ||
, | ||
( KeyHashObj | ||
(KeyHash "8ee93a5df84bc42cdd7a5fafbc500b435bc5e83067fa1f12f9110386") | ||
, DelegStakeVote | ||
(KeyHash "086c42afbc578301005df84ba67fa1f12f95f8ee193ab4cdd335bc5e") | ||
DRepAlwaysAbstain | ||
) | ||
, | ||
( KeyHashObj | ||
(KeyHash "df93ab435bc5eafbc500583067fa1f12f9110386c42cdd784ba5f8ee") | ||
, DelegVote $ | ||
DRepCredential | ||
(ScriptHashObj (ScriptHash "01305df84b078ac5e86c42afbc593ab4cdd67fa1f12f95f8ee10335b")) | ||
) | ||
, | ||
( ScriptHashObj | ||
(ScriptHash "afbc5005df84ba5f8ee93ab435bc5e83067fa1f12f9c42cdd7110386") | ||
, DelegVote $ | ||
DRepCredential | ||
(KeyHashObj (KeyHash "78301005df84ba67fa1f12f95f8ee10335bc5e86c42afbc593ab4cdd")) | ||
) | ||
] | ||
} | ||
cg `shouldBe` expectedCg | ||
cg `shouldBe` expectedConwayGenesis | ||
|
||
propConwayPParamsUpgrade :: UpgradeConwayPParams Identity -> PParams Babbage -> Property | ||
propConwayPParamsUpgrade ppu pp = property $ do | ||
let pp' = upgradePParams ppu pp :: PParams Conway | ||
pp' ^. ppPoolVotingThresholdsL `shouldBe` ucppPoolVotingThresholds ppu | ||
pp' ^. ppDRepVotingThresholdsL `shouldBe` ucppDRepVotingThresholds ppu | ||
pp' ^. ppCommitteeMinSizeL `shouldBe` ucppCommitteeMinSize ppu | ||
pp' ^. ppCommitteeMaxTermLengthL `shouldBe` ucppCommitteeMaxTermLength ppu | ||
pp' ^. ppGovActionLifetimeL `shouldBe` ucppGovActionLifetime ppu | ||
pp' ^. ppGovActionDepositL `shouldBe` ucppGovActionDeposit ppu | ||
pp' ^. ppDRepDepositL `shouldBe` ucppDRepDeposit ppu | ||
pp' ^. ppDRepActivityL `shouldBe` ucppDRepActivity ppu | ||
pp' ^. ppMinFeeRefScriptCostPerByteL `shouldBe` ucppMinFeeRefScriptCostPerByte ppu | ||
Map.lookup PlutusV3 (costModelsValid (pp' ^. ppCostModelsL)) | ||
`shouldBe` Just (ucppPlutusV3CostModel ppu) |
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
Oops, something went wrong.