Skip to content

Commit

Permalink
add test for isBootstrapRedeemer for CompactAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
goolord committed May 13, 2021
1 parent 90f1ce5 commit 4b63a10
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Expand Up @@ -10,6 +10,7 @@ module Test.Shelley.Spec.Ledger.Address.CompactAddr where
import qualified Cardano.Ledger.Crypto as CC (Crypto)
import qualified Data.ByteString.Short as SBS
import Shelley.Spec.Ledger.Address (Addr (..), serialiseAddr)
import qualified Shelley.Spec.Ledger.Address as Addr
import qualified Shelley.Spec.Ledger.CompactAddr as CA
import Shelley.Spec.Ledger.Credential
( PaymentCredential,
Expand Down Expand Up @@ -61,6 +62,14 @@ propDecompactShelleyLazyAddr = do
keyHash1 = unsafeGetHash . CA.decompactAddr . mangle . CA.compactAddr $ addr
in pure $ keyHash0 == keyHash1

propIsBootstrapRedeemer ::
forall crypto.
CC.Crypto crypto =>
Gen Bool
propIsBootstrapRedeemer = do
addr :: Addr crypto <- arbitrary
pure $ Addr.isBootstrapRedeemer addr == CA.isBootstrapRedeemer (CA.compactAddr addr)

unsafeGetHash :: Addr crypto -> PaymentCredential crypto
unsafeGetHash (Addr _ hash _) = hash
unsafeGetHash _ = error "this can't get a keyhash for a byron address"
Expand Down
Expand Up @@ -53,7 +53,7 @@ import Test.Shelley.Spec.Ledger.Address.CompactAddr
( propCompactAddrRoundTrip,
propCompactSerializationAgree,
propDecompactAddrLazy,
propDecompactShelleyLazyAddr,
propDecompactShelleyLazyAddr, propIsBootstrapRedeemer
)
import Test.Shelley.Spec.Ledger.ByronTranslation (testGroupByronTranslation)
import Test.Shelley.Spec.Ledger.Generator.Core (GenEnv)
Expand Down Expand Up @@ -117,7 +117,8 @@ minimalPropertyTests =
[ TQC.testProperty "Compact address round trip" (propCompactAddrRoundTrip @(Crypto era)),
TQC.testProperty "Compact address binary representation" (propCompactSerializationAgree @(Crypto era)),
TQC.testProperty "determining address type doesn't force contents" (propDecompactAddrLazy @(Crypto era)),
TQC.testProperty "reading the keyhash doesn't force the stake reference" (propDecompactShelleyLazyAddr @(Crypto era))
TQC.testProperty "reading the keyhash doesn't force the stake reference" (propDecompactShelleyLazyAddr @(Crypto era)),
TQC.testProperty "isBootstrapRedeemer is equivalent for CompactAddr and Addr" (propIsBootstrapRedeemer @(Crypto era))
]
]

Expand Down Expand Up @@ -199,6 +200,7 @@ propertyTests =
[ TQC.testProperty "Compact address round trip" (propCompactAddrRoundTrip @(Crypto era)),
TQC.testProperty "Compact address binary representation" (propCompactSerializationAgree @(Crypto era)),
TQC.testProperty "determining address type doesn't force contents" (propDecompactAddrLazy @(Crypto era)),
TQC.testProperty "reading the keyhash doesn't force the stake reference" (propDecompactShelleyLazyAddr @(Crypto era))
TQC.testProperty "reading the keyhash doesn't force the stake reference" (propDecompactShelleyLazyAddr @(Crypto era)),
TQC.testProperty "isBootstrapRedeemer is equivalent for CompactAddr and Addr" (propIsBootstrapRedeemer @(Crypto era))
]
]

0 comments on commit 4b63a10

Please sign in to comment.