Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Feb 21, 2024
1 parent 18ba6e3 commit 3e5dfe8
Show file tree
Hide file tree
Showing 7 changed files with 651 additions and 13 deletions.
38 changes: 38 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ package cardano-api
package cardano-api-gen
ghc-options: -Werror

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 504253f1eb4b05158ff2df51ac0a22725a4e4a95
subdir: eras/alonzo/impl
--sha256: sha256-xa5Dl2GEj6Q1bAPqjyAZAQDkINXdcYs2lPMsyLOVxbM=

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 504253f1eb4b05158ff2df51ac0a22725a4e4a95
subdir: eras/babbage/impl
--sha256: sha256-xa5Dl2GEj6Q1bAPqjyAZAQDkINXdcYs2lPMsyLOVxbM=

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 504253f1eb4b05158ff2df51ac0a22725a4e4a95
subdir: eras/shelley/impl
--sha256: sha256-xa5Dl2GEj6Q1bAPqjyAZAQDkINXdcYs2lPMsyLOVxbM=

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 504253f1eb4b05158ff2df51ac0a22725a4e4a95
subdir: eras/conway/impl
--sha256: sha256-xa5Dl2GEj6Q1bAPqjyAZAQDkINXdcYs2lPMsyLOVxbM=

source-repository-package
type: git
location: https://github.com/IntersectMBO/cardano-ledger.git
tag: 504253f1eb4b05158ff2df51ac0a22725a4e4a95
subdir: libs/cardano-ledger-core
--sha256: sha256-xa5Dl2GEj6Q1bAPqjyAZAQDkINXdcYs2lPMsyLOVxbM=




package cryptonite
-- Using RDRAND instead of /dev/urandom as an entropy source for key
-- generation is dubious. Set the flag so we use /dev/urandom by default.
Expand Down
4 changes: 4 additions & 0 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ test-suite cardano-api-test
Test.Cardano.Api.KeysByron
Test.Cardano.Api.Ledger
Test.Cardano.Api.Metadata
Test.Cardano.Api.ProtocolParameters
Test.Cardano.Api.Typed.Address
Test.Cardano.Api.Typed.Bech32
Test.Cardano.Api.Typed.CBOR
Expand All @@ -358,11 +359,13 @@ test-suite cardano-api-golden
, bytestring
, cardano-api
, cardano-api:gen
, cardano-api:internal
, cardano-binary
, cardano-crypto-class ^>= 2.1.2
, cardano-data >= 1.0
, cardano-ledger-alonzo
, cardano-ledger-api ^>= 1.8
, cardano-ledger-babbage >= 1.6.0
, cardano-ledger-core:{cardano-ledger-core, testlib} >= 1.8
, cardano-ledger-shelley
, cardano-ledger-shelley-test >= 1.2.0.1
Expand All @@ -389,4 +392,5 @@ test-suite cardano-api-golden
, Test.Golden.Cardano.Api.Ledger
, Test.Golden.Cardano.Api.Typed.Script
, Test.Golden.Cardano.Api.Value
, Test.Golden.Cardano.Api.ProtocolParameters
, Test.Golden.ErrorsSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
module Test.Golden.Cardano.Api.ProtocolParameters(test_golden_ProtocolParameters, test_golden_ProtocolParameters_to_PParams) where

import Cardano.Api.Ledger (EpochInterval (EpochInterval), StandardCrypto)
import Cardano.Api.ProtocolParameters (ExecutionUnitPrices (..), ProtocolParameters (..))
import Data.Map (Map)
import qualified Data.Map as M
import Cardano.Api (AnyPlutusScriptVersion (AnyPlutusScriptVersion), ExecutionUnits (..),
PlutusScriptVersion (..), Lovelace (..), CostModel(..), makePraosNonce)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.Hedgehog (testProperty)
import qualified Hedgehog.Extras.Aeson as H
import Data.Aeson (encode, eitherDecode, FromJSON)
import Hedgehog (success, property, Property)
import Hedgehog.Internal.Property (failWith)
import Data.ByteString.Lazy (ByteString)
import Data.Functor.Identity (Identity)
import Cardano.Ledger.Shelley (ShelleyEra)
import Cardano.Ledger.Alonzo (AlonzoEra)
import Cardano.Ledger.Babbage (BabbageEra)
import Cardano.Ledger.Shelley.PParams (ShelleyPParams(..))
import Cardano.Ledger.Alonzo.PParams (AlonzoPParams(..))
import Cardano.Ledger.Babbage.PParams (BabbagePParams(..))

test_golden_ProtocolParameters :: TestTree
test_golden_ProtocolParameters = testProperty "golden ProtocolParameters" $ do
H.goldenTestJsonValuePretty examplePP "test/cardano-api-golden/files/golden/ProtocolParameters"

test_golden_ProtocolParameters_to_PParams :: TestTree
test_golden_ProtocolParameters_to_PParams =
testGroup "golden ProtocolParameter tests"
[ testProperty "ShelleyPParams" $
goldenProtocolParametersToPParams (undefined :: (ShelleyPParams Identity (ShelleyEra StandardCrypto)))
, testProperty "AlonzoPParams" $
goldenProtocolParametersToPParams (undefined :: (AlonzoPParams Identity (AlonzoEra StandardCrypto)))
, testProperty "BabbagePParams" $
goldenProtocolParametersToPParams (undefined :: (BabbagePParams Identity (BabbageEra StandardCrypto)))
]

goldenProtocolParametersToPParams :: forall pp. FromJSON pp => pp -> Property
goldenProtocolParametersToPParams _ =
property $ case decodedPP of
Left err -> failWith Nothing ("could not decode: " <> show err)
Right _ -> success
where
bsExamplePP :: ByteString
bsExamplePP = encode examplePP

decodedPP :: Either String pp
decodedPP = eitherDecode bsExamplePP

examplePP :: ProtocolParameters
examplePP = ProtocolParameters { protocolParamUTxOCostPerByte = Just $ Lovelace 1000000
, protocolParamTxFeePerByte = Lovelace 2000000
, protocolParamTxFeeFixed = Lovelace 1500000
, protocolParamTreasuryCut = 0.1
, protocolParamStakePoolTargetNum = 100
, protocolParamStakePoolDeposit = Lovelace 1000000000
, protocolParamStakeAddressDeposit = Lovelace 10000000
, protocolParamProtocolVersion = (2, 3)
, protocolParamPrices = Just executionUnitPrices
, protocolParamPoolRetireMaxEpoch = Cardano.Api.Ledger.EpochInterval 4
, protocolParamPoolPledgeInfluence = 0.54
, protocolParamMonetaryExpansion = 0.23
, protocolParamMinUTxOValue = Just $ Lovelace 3000000
, protocolParamMinPoolCost = Lovelace 3500000
, protocolParamMaxValueSize = Just 10
, protocolParamMaxTxSize = 3000
, protocolParamMaxTxExUnits = Just executionUnits
, protocolParamMaxCollateralInputs = Just 10
, protocolParamMaxBlockHeaderSize = 1200
, protocolParamMaxBlockExUnits = Just executionUnits2
, protocolParamMaxBlockBodySize = 5000
, protocolParamExtraPraosEntropy = Just $ makePraosNonce "entropyEntropy"
, protocolParamDecentralization = Just 0.52
, protocolParamCostModels = costModels
, protocolParamCollateralPercent = Just 23
}
where
executionUnitPrices :: ExecutionUnitPrices
executionUnitPrices = ExecutionUnitPrices { priceExecutionSteps = 0.3
, priceExecutionMemory = 0.2
}

costModels :: Map AnyPlutusScriptVersion CostModel
costModels = M.fromList [ (AnyPlutusScriptVersion PlutusScriptV3, CostModel [223,222..1])
, (AnyPlutusScriptVersion PlutusScriptV2, CostModel [1..175])
]

executionUnits :: ExecutionUnits
executionUnits = ExecutionUnits { executionSteps = 4300
, executionMemory = 2300
}

executionUnits2 :: ExecutionUnits
executionUnits2 = ExecutionUnits { executionSteps = 5600
, executionMemory = 3400
}
Loading

0 comments on commit 3e5dfe8

Please sign in to comment.