Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CBOR Round trip for Byron signing key
- Loading branch information
Showing
5 changed files
with
66 additions
and
3 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
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,33 @@ | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module Test.Cardano.Api.KeysByron | ||
( tests | ||
) where | ||
|
||
import Cardano.Api | ||
import Cardano.Prelude | ||
import Hedgehog (Gen, Property, discover) | ||
import Test.Cardano.Api.Typed.Orphans () | ||
import Test.Tasty (TestTree) | ||
import Test.Tasty.Hedgehog.Group (fromGroup) | ||
|
||
import qualified Hedgehog as H | ||
import qualified Test.Cardano.Crypto.Seed.Gen as Gen | ||
|
||
{- HLINT ignore "Use camelCase" -} | ||
|
||
prop_roundtrip_byron_key_CBOR :: Property | ||
prop_roundtrip_byron_key_CBOR = | ||
roundtrip_CBOR (AsSigningKey AsByronKey) (deterministicSigningKey AsByronKey <$> Gen.genSeedForKey AsByronKey) | ||
|
||
roundtrip_CBOR | ||
:: (SerialiseAsCBOR a, Eq a, Show a) | ||
=> AsType a -> Gen a -> Property | ||
roundtrip_CBOR typeProxy gen = | ||
H.property $ do | ||
val <- H.forAll gen | ||
H.tripping val serialiseToCBOR (deserialiseFromCBOR typeProxy) | ||
|
||
tests :: TestTree | ||
tests = fromGroup $$discover |
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,22 @@ | ||
module Test.Cardano.Crypto.Seed.Gen | ||
( genSeed | ||
, genSeedForKey | ||
) where | ||
|
||
import Cardano.Api (AsType, Key) | ||
import Cardano.Crypto.Seed (Seed) | ||
import Data.Functor ((<$>)) | ||
import Data.Int (Int) | ||
import Hedgehog (MonadGen, Range) | ||
import Prelude (fromIntegral) | ||
|
||
import qualified Cardano.Api as API | ||
import qualified Cardano.Crypto.Seed as C | ||
import qualified Hedgehog.Gen as G | ||
import qualified Hedgehog.Range as R | ||
|
||
genSeed :: MonadGen m => Range Int -> m Seed | ||
genSeed r = C.mkSeedFromBytes <$> G.bytes r | ||
|
||
genSeedForKey :: (Key key, MonadGen m) => AsType key -> m Seed | ||
genSeedForKey keyRole = genSeed (R.singleton (fromIntegral (API.deterministicSigningKeySeedSize keyRole))) |
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