Skip to content

Commit

Permalink
Adapt to API changes in cardano-api
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Mar 26, 2024
1 parent d367b56 commit f675763
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
1 change: 1 addition & 0 deletions cardano-testnet/cardano-testnet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ test-suite cardano-testnet-test
, cardano-testnet
, containers
, directory
, exceptions
, filepath
, hedgehog
, hedgehog-extras
Expand Down
12 changes: 6 additions & 6 deletions cardano-testnet/src/Testnet/Components/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ import Hedgehog.Internal.Property (MonadTest)

-- | Block and wait for the desired epoch.
waitUntilEpoch
:: (MonadIO m, MonadTest m, HasCallStack)
:: (MonadCatch m, MonadIO m, MonadTest m, HasCallStack)
=> NodeConfigFile In
-> SocketPath
-> EpochNo -- ^ Desired epoch
-> m EpochNo
waitUntilEpoch nodeConfigFile socketPath desiredEpoch = withFrozenCallStack $ do
result <- runExceptT $
foldEpochState
nodeConfigFile socketPath QuickValidation desiredEpoch () (const $ pure ConditionNotMet)
nodeConfigFile socketPath QuickValidation desiredEpoch () (\_ _ _ -> pure ConditionNotMet)
case result of
Left (FoldBlocksApplyBlockError (TerminationEpochReached epochNo)) ->
pure epochNo
Expand Down Expand Up @@ -133,7 +133,7 @@ getEpochStateView
getEpochStateView nodeConfigFile socketPath = withFrozenCallStack $ do
epochStateView <- liftIO $ newIORef Nothing
runInBackground . runExceptT . foldEpochState nodeConfigFile socketPath QuickValidation (EpochNo maxBound) Nothing
$ \epochState -> do
$ \epochState _slotNb _blockNb -> do
liftIO $ writeIORef epochStateView (Just epochState)
pure ConditionNotMet
pure . EpochStateView $ epochStateView
Expand Down Expand Up @@ -229,7 +229,7 @@ findLargestUtxoForPaymentKey epochStateView sbe address =
-- wait for the number of DReps being @n@ for two epochs. If
-- this number is not attained before two epochs, the test is failed.
checkDRepsNumber ::
(HasCallStack, MonadIO m, MonadCatch m, MonadTest m)
(HasCallStack, MonadCatch m, MonadIO m, MonadTest m)
=> ShelleyBasedEra ConwayEra -- ^ The era in which the test runs
-> NodeConfigFile 'In
-> SocketPath
Expand All @@ -248,7 +248,7 @@ checkDRepsNumber sbe configurationFile socketPath execConfig expectedDRepsNb = d
-- So if you call this function, you are expecting the number of DReps to already
-- be @n@, or to be @n@ before @terminationEpoch@
checkDRepsNumber' ::
(HasCallStack, MonadIO m, MonadTest m)
(HasCallStack, MonadCatch m, MonadIO m, MonadTest m)
=> ShelleyBasedEra ConwayEra -- ^ The era in which the test runs
-> NodeConfigFile In
-> SocketPath
Expand All @@ -257,7 +257,7 @@ checkDRepsNumber' ::
-> m (Maybe [L.DRepState StandardCrypto]) -- ^ The DReps when the expected number of DReps was attained.
checkDRepsNumber' sbe nodeConfigFile socketPath maxEpoch expectedDRepsNb = do
result <- runExceptT $ foldEpochState nodeConfigFile socketPath QuickValidation maxEpoch Nothing
$ \(AnyNewEpochState actualEra newEpochState) -> do
$ \(AnyNewEpochState actualEra newEpochState) _slotNb _blockNb -> do
case testEquality sbe actualEra of
Just Refl -> do
let dreps = Map.elems $ shelleyBasedEraConstraints sbe newEpochState
Expand Down
2 changes: 1 addition & 1 deletion cardano-testnet/src/Testnet/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ startLedgerNewEpochStateLogging testnetRuntime tmpWorkspace = withFrozenCallStac
Api.QuickValidation
(EpochNo maxBound)
()
(handler logFile)
(\epochState _ _ -> handler logFile epochState)
H.note_ $ "Started logging epoch states to to: " <> logFile
where
handler :: FilePath -> AnyNewEpochState -> StateT () IO LedgerStateCondition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ txOutValue (TxOut _ v _ _) = v
txOutValueLovelace ::TxOutValue era -> L.Coin
txOutValueLovelace = \case
TxOutValueShelleyBased sbe v -> v ^. A.adaAssetL sbe
TxOutValueByron (Lovelace v) -> L.Coin v
TxOutValueByron v -> v
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ hprop_ledger_events_propose_new_constitution = H.integrationWorkspace "propose-n
FullValidation
(EpochNo 10)
()
(foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash)
(\epochState _ _ -> foldBlocksCheckConstitutionWasRatified constitutionHash constitutionScriptHash epochState)

void $ evalEither eConstitutionAdopted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Cardano.Testnet

import Prelude

import Control.Monad.Catch (MonadCatch)
import Control.Monad.Trans.State.Strict (put)
import Data.Bifunctor (Bifunctor (..))
import Data.List (isInfixOf)
Expand Down Expand Up @@ -231,16 +232,14 @@ hprop_ledger_events_propose_new_constitution_spo = H.integrationWorkspace "propo
H.assert $ "DisallowedVoters" `isInfixOf` stderr -- Did it fail for the expected reason?

getConstitutionProposal
:: HasCallStack
=> MonadIO m
=> MonadTest m
:: (HasCallStack, MonadCatch m, MonadIO m, MonadTest m)
=> NodeConfigFile In
-> SocketPath
-> EpochNo -- ^ The termination epoch: the constitution proposal must be found *before* this epoch
-> m (Maybe (L.GovActionId StandardCrypto))
getConstitutionProposal nodeConfigFile socketPath maxEpoch = do
result <- runExceptT $ foldEpochState nodeConfigFile socketPath QuickValidation maxEpoch Nothing
$ \(AnyNewEpochState actualEra newEpochState) ->
$ \(AnyNewEpochState actualEra newEpochState) _slotNb _blockNb ->
caseShelleyToBabbageOrConwayEraOnwards
(error $ "Expected Conway era onwards, got state in " <> docToString (pretty actualEra))
(\cEra -> conwayEraOnwardsConstraints cEra $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ prop_check_if_treasury_is_growing = H.integrationRetryWorkspace 0 "growing-treas
H.note_ "treasury is not growing"
H.failure
where
handler :: AnyNewEpochState -> StateT (Map EpochNo Integer) IO LedgerStateCondition
handler (AnyNewEpochState _ newEpochState) = do
handler :: AnyNewEpochState -> SlotNo -> BlockNo -> StateT (Map EpochNo Integer) IO LedgerStateCondition
handler (AnyNewEpochState _ newEpochState) _slotNo _blockNo = do
let (Coin coin) = newEpochState ^. L.nesEsL . L.esAccountStateL . L.asTreasuryL
epochNo = newEpochState ^. L.nesELL
-- handler is executed multiple times per epoch, so we keep only the latest treasury value
modify $ M.insert epochNo coin
if epochNo >= EpochNo 5
then pure ConditionMet
else pure ConditionNotMet
pure $ if epochNo >= EpochNo 5
then ConditionMet
else ConditionNotMet

-- | Check if the last element > first element
checkHasIncreased :: (Ord a) => [a] -> Bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ txOutValue (TxOut _ v _ _) = v
txOutValueLovelace ::TxOutValue era -> L.Coin
txOutValueLovelace = \case
TxOutValueShelleyBased sbe v -> v ^. A.adaAssetL sbe
TxOutValueByron (Lovelace v) -> L.Coin v
TxOutValueByron v -> v

0 comments on commit f675763

Please sign in to comment.