Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import Cardano.Ledger.BaseTypes (
ProtVer,
ToKeyValuePairs (..),
UnitInterval,
Vote (..),
maybeToStrictMaybe,
)
import Cardano.Ledger.Binary (
Expand All @@ -100,12 +101,10 @@ import Cardano.Ledger.Binary (
Interns,
ToCBOR (toCBOR),
decNoShareCBOR,
decodeEnumBounded,
decodeMapByKey,
decodeNullStrictMaybe,
decodeRecordNamed,
decodeRecordNamedT,
encodeEnum,
encodeListLen,
encodeNullStrictMaybe,
encodeWord8,
Expand Down Expand Up @@ -373,24 +372,6 @@ instance NoThunks Voter

instance NFData Voter

data Vote
= VoteNo
| VoteYes
| Abstain
deriving (Ord, Generic, Eq, Show, Enum, Bounded)

instance ToJSON Vote

instance NoThunks Vote

instance NFData Vote

instance DecCBOR Vote where
decCBOR = decodeEnumBounded

instance EncCBOR Vote where
encCBOR = encodeEnum

newtype VotingProcedures era = VotingProcedures
{ unVotingProcedures :: Map Voter (Map GovActionId (VotingProcedure era))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Test.Cardano.Ledger.Conway.Arbitrary (
genParameterChange,
genNewConstitution,
govActionGenerators,
genConwayTxCertPool,
genConwayPlutusPurposePointer,
genGovAction,
genGovActionState,
Expand Down Expand Up @@ -76,7 +77,8 @@ import Test.Cardano.Ledger.Alonzo.Arbitrary (genValidAndUnknownCostModels, genVa
import Test.Cardano.Ledger.Babbage.Arbitrary ()
import Test.Cardano.Ledger.Binary.Random (QC (..))
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary (uniformSubMap)
import Test.Cardano.Ledger.Core.Arbitrary (genPoolParamsNoDefaultVote, uniformSubMap)
import Test.Cardano.Ledger.Shelley.Arbitrary ()

instance
(Era era, Arbitrary (PParamsUpdate era)) =>
Expand Down Expand Up @@ -163,10 +165,18 @@ instance Era era => Arbitrary (ConwayTxCert era) where
arbitrary =
oneof
[ ConwayTxCertDeleg <$> arbitrary
, ConwayTxCertPool <$> arbitrary
, genConwayTxCertPool
, ConwayTxCertGov <$> arbitrary
]

genConwayTxCertPool :: Gen (ConwayTxCert era)
genConwayTxCertPool =
ConwayTxCertPool
<$> oneof
[ RegPool <$> genPoolParamsNoDefaultVote
, RetirePool <$> arbitrary <*> arbitrary
]

instance Arbitrary ConwayGovCert where
arbitrary =
oneof
Expand Down Expand Up @@ -562,10 +572,6 @@ instance Arbitrary Voter where
]
shrink = genericShrink

instance Arbitrary Vote where
arbitrary = arbitraryBoundedEnum
shrink = shrinkBoundedEnum

instance Arbitrary (TxBody ConwayEra) where
arbitrary =
ConwayTxBody
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import qualified Test.Cardano.Ledger.Babbage.Translation.TranslatableGen as Babb
utxoWithTx,
)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Conway.Arbitrary (genConwayTxCertPool)

instance TranslatableGen ConwayEra where
tgRedeemers = genRedeemers
Expand Down Expand Up @@ -65,7 +65,7 @@ genTxBody l@(SupportedLanguage slang) = do
genOSet $
frequency
[ (33, ConwayTxCertDeleg <$> genDelegCert)
, (33, ConwayTxCertPool <$> arbitrary)
, (33, genConwayTxCertPool)
, (offPrePlutusV3 33, ConwayTxCertGov <$> arbitrary)
]
genForPlutusV3 :: Arbitrary a => a -> Gen a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ instance ToExpr (PParamsHKD StrictMaybe era) => ToExpr (GovActionState era)

instance ToExpr Voter

instance ToExpr Vote

instance Era era => ToExpr (VotingProcedures era)

instance ToExpr (VotingProcedure era)
Expand Down
2 changes: 1 addition & 1 deletion eras/dijkstra/impl/cardano-ledger-dijkstra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ test-suite tests
cardano-ledger-alonzo,
cardano-ledger-babbage:testlib,
cardano-ledger-binary:testlib,
cardano-ledger-conway,
cardano-ledger-conway:{cardano-ledger-conway, testlib},
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-dijkstra:{cardano-ledger-dijkstra, testlib},
cardano-ledger-shelley:testlib,
2 changes: 2 additions & 0 deletions eras/dijkstra/impl/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Cardano.Ledger.Plutus (SLanguage (..))
import Test.Cardano.Ledger.Babbage.TxInfoSpec (txInfoSpec)
import qualified Test.Cardano.Ledger.Babbage.TxInfoSpec as BabbageTxInfo
import Test.Cardano.Ledger.Common
import qualified Test.Cardano.Ledger.Conway.BinarySpec as Binary
import Test.Cardano.Ledger.Dijkstra.Binary.Annotator ()
import qualified Test.Cardano.Ledger.Dijkstra.Binary.CddlSpec as Cddl
import Test.Cardano.Ledger.Dijkstra.Binary.RoundTrip ()
Expand All @@ -29,3 +30,4 @@ main =
BabbageTxInfo.spec @DijkstraEra
txInfoSpec @DijkstraEra SPlutusV3
txInfoSpec @DijkstraEra SPlutusV4
Binary.spec @DijkstraEra
18 changes: 10 additions & 8 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/TxCert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ module Cardano.Ledger.Shelley.TxCert (
import Cardano.Ledger.BaseTypes (invalidKey, kindObject)
import Cardano.Ledger.Binary (
DecCBOR (decCBOR),
DecCBORGroup (..),
Decoder,
EncCBOR (..),
EncCBORGroup (..),
Encoding,
FromCBOR (..),
ToCBOR (..),
Expand All @@ -90,7 +88,6 @@ import Cardano.Ledger.Binary (
decodeWord,
encodeListLen,
encodeWord8,
listLenInt,
peekTokenType,
)
import Cardano.Ledger.Coin (Coin (..), DeltaCoin)
Expand All @@ -105,7 +102,12 @@ import Cardano.Ledger.Internal.Era (AllegraEra, AlonzoEra, BabbageEra, MaryEra)
import Cardano.Ledger.Keys (asWitness)
import Cardano.Ledger.Shelley.Era (ShelleyEra)
import Cardano.Ledger.Shelley.PParams ()
import Cardano.Ledger.State (PoolParams (..))
import Cardano.Ledger.State (
PoolParams (..),
decCBORGroupPoolParams,
encCBORGroupPoolParams,
poolParamsCount,
)
import Cardano.Ledger.Val ((<+>), (<×>))
import Control.DeepSeq (NFData (..), rwhnf)
import Data.Aeson (ToJSON (..), (.=))
Expand Down Expand Up @@ -434,9 +436,9 @@ encodeShelleyDelegCert = \case
encodePoolCert :: PoolCert -> Encoding
encodePoolCert = \case
RegPool poolParams ->
encodeListLen (1 + listLen poolParams)
encodeListLen (1 + fromIntegral poolParamsCount)
<> encodeWord8 3
<> encCBORGroup poolParams
<> encCBORGroupPoolParams poolParams
RetirePool vk epoch ->
encodeListLen 3
<> encodeWord8 4
Expand Down Expand Up @@ -504,8 +506,8 @@ shelleyTxCertDelegDecoder = \case
poolTxCertDecoder :: EraTxCert era => Word -> Decoder s (Int, TxCert era)
poolTxCertDecoder = \case
3 -> do
group <- decCBORGroup
pure (1 + listLenInt group, RegPoolTxCert group)
group <- decCBORGroupPoolParams
pure (1 + fromIntegral poolParamsCount, RegPoolTxCert group)
4 -> do
a <- decCBOR
b <- decCBOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import Cardano.Ledger.Shelley.Tx (Tx (..))
import Cardano.Ledger.Shelley.TxAuxData
import Cardano.Ledger.Shelley.TxCert (
GenesisDelegCert (..),
ShelleyTxCert,
ShelleyTxCert (..),
)
import Cardano.Ledger.Shelley.TxOut
import Cardano.Ledger.Shelley.TxWits (ShelleyTxWits (ShelleyTxWits))
Expand All @@ -93,7 +93,7 @@ import Data.Word (Word64)
import Generic.Random (genericArbitraryU)
import Test.Cardano.Chain.UTxO.Gen (genCompactTxOut)
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary (genPoolParamsNoDefaultVote)
import Test.Cardano.Ledger.Core.Utils (unsafeBoundRational)
import Test.QuickCheck.Hedgehog (hedgehog)

Expand Down Expand Up @@ -248,7 +248,7 @@ instance Arbitrary PoolRewardInfo where
PoolRewardInfo
<$> arbitrary
<*> arbitrary
<*> arbitrary
<*> genPoolParamsNoDefaultVote
<*> arbitrary
<*> arbitrary
shrink = genericShrink
Expand Down Expand Up @@ -439,8 +439,18 @@ vectorOfMetadatumSimple = do
------------------------------------------------------------------------------------------

instance Era era => Arbitrary (ShelleyTxCert era) where
arbitrary = genericArbitraryU
shrink = genericShrink
arbitrary =
oneof
[ ShelleyTxCertDelegCert <$> arbitrary
, ShelleyTxCertPool
<$> oneof
[ RegPool <$> genPoolParamsNoDefaultVote
, RetirePool <$> arbitrary <*> arbitrary
]
, ShelleyTxCertGenesisDeleg <$> arbitrary
, ShelleyTxCertMir <$> arbitrary
]

instance Arbitrary ShelleyDelegCert where
arbitrary = genericArbitraryU
Expand Down Expand Up @@ -608,7 +618,17 @@ instance
pure ShelleyGenesis {..}

instance Arbitrary ShelleyGenesisStaking where
arbitrary = ShelleyGenesisStaking <$> arbitrary <*> arbitrary
arbitrary = ShelleyGenesisStaking <$> genPoolParamsListMap <*> arbitrary

genPoolParamsListMap :: Gen (LM.ListMap (KeyHash 'StakePool) PoolParams)
genPoolParamsListMap =
LM.fromList <$> listOf pair
where
pair :: Gen (KeyHash 'StakePool, PoolParams)
pair = do
k <- arbitrary
v <- genPoolParamsNoDefaultVote
pure (k, v)

instance
( Era era
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ examplePoolParams =
{ pmUrl = fromJust $ textToUrl 64 "consensus.pool"
, pmHash = "{}"
}
, ppDefaultVote = SNothing
}

examplePayKey :: KeyPair 'Payment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,7 @@ freshPoolParams khPool rewardAccount = do
let minCost = pp ^. ppMinPoolCostL
poolCostExtra <- uniformRM (Coin 0, Coin 100_000_000)
pledge <- uniformRM (Coin 0, Coin 100_000_000)
defaultVote <- arbitrary
pure
PoolParams
{ ppVrf = vrfHash
Expand All @@ -1690,6 +1691,7 @@ freshPoolParams khPool rewardAccount = do
, ppMargin = def
, ppId = khPool
, ppCost = minCost <> poolCostExtra
, ppDefaultVote = defaultVote
}

registerPool ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Data.MonoTuple (TupleN)
import qualified Data.VMap as VMap
import Lens.Micro
import Test.Cardano.Ledger.Common
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary (genPoolParamsNoDefaultVote)
import Test.Cardano.Ledger.Core.KeyPair (mkAddr)
import Test.Cardano.Ledger.Shelley.Era
import Test.Cardano.Ledger.Shelley.ImpTest
Expand All @@ -36,7 +36,7 @@ arbitraryLens l b = (l .~ b) <$> arbitrary

instantStakeIncludesRewards :: forall era. ShelleyEraImp era => Gen Property
instantStakeIncludesRewards = do
(pool1, pool2) <- arbitrary @(TupleN 2 PoolParams)
(pool1, pool2) <- (,) <$> genPoolParamsNoDefaultVote <*> genPoolParamsNoDefaultVote
let
poolId1 = pool1 ^. ppIdL
poolId2 = pool2 ^. ppIdL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ genChainInEpoch epoch = do
, ppOwners = Set.singleton owner
, ppRelays = StrictSeq.empty
, ppMetadata = SNothing
, ppDefaultVote = SNothing
}
]
, sgsStake =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ mkPoolParameters keys =
, ppOwners = Set.singleton $ hashKey (vKey stakeKeyOne)
, ppRelays = StrictSeq.empty
, ppMetadata = SNothing
, ppDefaultVote = SNothing
}

-- Create stake pool registration certs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ alicePoolParams =
{ pmUrl = fromJust $ textToUrl 64 "alice.pool"
, pmHash = BS.pack "{}"
}
, ppDefaultVote = SNothing
}

-- | Alice's VRF key hash
Expand Down Expand Up @@ -187,6 +188,7 @@ bobPoolParams =
, ppOwners = Set.singleton $ hashKey (vKey bobStake)
, ppRelays = StrictSeq.empty
, ppMetadata = SNothing
, ppDefaultVote = SNothing
}

-- | Bob's VRF key hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ genStakePool poolKeys skeys (Coin minPoolCost) =
Set.empty
StrictSeq.empty
SNothing
SNothing
in (pps, aikCold allPoolKeys)

-- | Generate `RegPool` and the key witness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ genPoolInfo PoolSetUpArgs {poolPledge, poolCost, poolMargin, poolMembers} = do
, ppOwners = Set.fromList [hashKey $ vKey ownerKey]
, ppRelays = StrictSeq.empty
, ppMetadata = SNothing
, ppDefaultVote = SNothing
}
pure $ PoolInfo {params, coldKey, ownerKey, ownerStake, rewardKey, members}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ alicePoolParams =
{ pmUrl = fromJust $ textToUrl 64 "alice.pool"
, pmHash = BS.pack "{}"
}
, ppDefaultVote = SNothing
}

aliceAddr :: Addr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ tests =
{ pmUrl = Maybe.fromJust $ textToUrl 64 poolUrl
, pmHash = poolMDHash
}
, ppDefaultVote = SNothing
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ exampleShelleyGenesis =
{ L.pmUrl = fromJust $ textToUrl 64 "best.pool.com"
, L.pmHash = BS.pack "100ab{}100ab{}"
}
, L.ppDefaultVote = L.SNothing
}
staking =
ShelleyGenesisStaking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ alicePoolParamsSmallCost =
{ pmUrl = fromJust $ textToUrl 64 "alice.pool"
, pmHash = BS.pack "{}"
}
, ppDefaultVote = SNothing
}
where
vkVrf = vrfVerKey $ mkVRFKeyPair @MockCrypto (RawSeed 0 0 0 0 2)
Expand Down
1 change: 1 addition & 0 deletions libs/cardano-ledger-api/cardano-ledger-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ library testlib
cardano-ledger-binary:{cardano-ledger-binary, testlib},
cardano-ledger-core:{cardano-ledger-core, testlib},
cardano-ledger-dijkstra:testlib,
containers,
data-default,
prettyprinter,

Expand Down
Loading
Loading