-
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 test to check deposits in translation of (un)reg certificates
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 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
66 changes: 66 additions & 0 deletions
66
eras/conway/impl/test/Test/Cardano/Ledger/Conway/TxInfoSpec.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,66 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Test.Cardano.Ledger.Conway.TxInfoSpec (spec) where | ||
|
||
import Cardano.Ledger.BaseTypes | ||
import Cardano.Ledger.Coin (Coin (..)) | ||
import Cardano.Ledger.Conway (Conway) | ||
import Cardano.Ledger.Conway.Core | ||
import Cardano.Ledger.Conway.TxCert | ||
import Cardano.Ledger.Conway.TxInfo | ||
import Cardano.Ledger.Credential (StakeCredential) | ||
import qualified PlutusLedgerApi.V2 as PV2 | ||
import qualified PlutusLedgerApi.V3 as PV3 | ||
import Test.Cardano.Ledger.Common | ||
import Test.Cardano.Ledger.Conway.Genesis () | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "TxInfo" $ do | ||
let transV9 = transTxCert @Conway (ProtVer (natVersion @9) 0) | ||
transV10 = transTxCert @Conway (ProtVer (natVersion @10) 0) | ||
|
||
prop "Deposit in registration certs" $ | ||
\(cred :: StakeCredential (EraCrypto Conway)) | ||
(coin :: Coin) -> do | ||
expectNoDeposit $ transV9 $ ConwayTxCertDeleg $ ConwayRegCert cred (SJust coin) | ||
expectNoDeposit $ transV9 $ RegDepositTxCert cred coin | ||
expectNoDeposit $ transV9 $ ConwayTxCertDeleg $ ConwayRegCert cred SNothing | ||
|
||
expectDeposit coin $ transV10 $ ConwayTxCertDeleg $ ConwayRegCert cred (SJust coin) | ||
expectDeposit coin $ transV10 $ RegDepositTxCert cred coin | ||
expectNoDeposit $ transV10 $ ConwayTxCertDeleg $ ConwayRegCert cred SNothing | ||
|
||
prop "Deposit in unregistration certs" $ | ||
\(cred :: StakeCredential (EraCrypto Conway)) | ||
(coin :: Coin) -> do | ||
expectNoDeposit $ transV9 $ ConwayTxCertDeleg $ ConwayUnRegCert cred (SJust coin) | ||
expectNoDeposit $ transV9 $ UnRegDepositTxCert cred coin | ||
expectNoDeposit $ transV9 $ ConwayTxCertDeleg $ ConwayUnRegCert cred SNothing | ||
|
||
expectDeposit coin $ transV10 $ ConwayTxCertDeleg $ ConwayUnRegCert cred (SJust coin) | ||
expectDeposit coin $ transV10 $ UnRegDepositTxCert cred coin | ||
expectNoDeposit $ transV10 $ ConwayTxCertDeleg $ ConwayUnRegCert cred SNothing | ||
where | ||
expectDeposit :: Coin -> PV3.TxCert -> IO () | ||
expectDeposit (Coin c) = | ||
\case | ||
PV3.TxCertRegStaking _ (Just d) -> PV2.Lovelace c `shouldBe` d | ||
PV3.TxCertUnRegStaking _ (Just d) -> PV2.Lovelace c `shouldBe` d | ||
txcert -> | ||
expectationFailure $ | ||
"Deposit: " <> show (Coin c) <> " expected in: " <> show txcert <> ", but not found" | ||
expectNoDeposit :: PV3.TxCert -> IO () | ||
expectNoDeposit = | ||
\case | ||
PV3.TxCertRegStaking _ Nothing -> pure () | ||
PV3.TxCertUnRegStaking _ Nothing -> pure () | ||
txcert -> | ||
expectationFailure $ | ||
"Deposit not expected, but found in: " <> show txcert |