diff --git a/cardano-api/cardano-api.cabal b/cardano-api/cardano-api.cabal index e3cfd7fc32..1c5862fe5d 100644 --- a/cardano-api/cardano-api.cabal +++ b/cardano-api/cardano-api.cabal @@ -210,7 +210,9 @@ test-suite cardano-api-test , cardano-ledger-shelley , cardano-ledger-shelley-test , tasty + , tasty-hedgehog , tasty-quickcheck + , tasty-th , time other-modules: Test.Cardano.Api.Crypto diff --git a/cardano-api/gen/Gen/Cardano/Api/Typed.hs b/cardano-api/gen/Gen/Cardano/Api/Typed.hs index 721fc9fc00..471b488bce 100644 --- a/cardano-api/gen/Gen/Cardano/Api/Typed.hs +++ b/cardano-api/gen/Gen/Cardano/Api/Typed.hs @@ -30,6 +30,7 @@ module Gen.Cardano.Api.Typed , genScriptHash , genScriptData + , genAssetName , genOperationalCertificate , genOperationalCertificateIssueCounter , genShelleyWitness @@ -227,8 +228,8 @@ genAssetName = Gen.frequency -- mostly from a small number of choices, so we get plenty of repetition [ (9, Gen.element ["", "a", "b", "c"]) - , (1, AssetName <$> Gen.utf8 (Range.singleton 32) Gen.alphaNum) - , (1, AssetName <$> Gen.utf8 (Range.constant 1 31) Gen.alphaNum) + , (1, AssetName <$> Gen.bytes (Range.singleton 32)) + , (1, AssetName <$> Gen.bytes (Range.constant 1 31)) ] genPolicyId :: Gen PolicyId diff --git a/cardano-api/test/Test/Cardano/Api/Typed/Value.hs b/cardano-api/test/Test/Cardano/Api/Typed/Value.hs index 639bafd292..68c19568aa 100644 --- a/cardano-api/test/Test/Cardano/Api/Typed/Value.hs +++ b/cardano-api/test/Test/Cardano/Api/Typed/Value.hs @@ -4,16 +4,19 @@ module Test.Cardano.Api.Typed.Value ( tests ) where -import Cardano.Api.Shelley -import Data.Aeson +import Prelude + +import Data.Aeson (eitherDecode, encode) import Data.List (groupBy, sort) -import Gen.Cardano.Api.Typed +import qualified Data.Map.Strict as Map import Gen.Tasty.Hedgehog.Group (fromGroup) import Hedgehog (Property, discover, forAll, property, tripping, (===)) -import Prelude import Test.Tasty (TestTree) -import qualified Data.Map.Strict as Map +import Cardano.Api (ValueNestedBundle (ValueNestedBundle, ValueNestedBundleAda), + ValueNestedRep (..), valueFromNestedRep, valueToNestedRep) + +import Gen.Cardano.Api.Typed (genAssetName, genValueDefault, genValueNestedRep) prop_roundtrip_Value_JSON :: Property prop_roundtrip_Value_JSON = @@ -65,6 +68,20 @@ canonicalise = isZeroOrEmpty (ValueNestedBundleAda q) = q == 0 isZeroOrEmpty (ValueNestedBundle _ as) = Map.null as + +prop_roundtrip_AssetName_JSON :: Property +prop_roundtrip_AssetName_JSON = + property $ do + v <- forAll genAssetName + tripping v encode eitherDecode + +prop_roundtrip_AssetName_JSONKey :: Property +prop_roundtrip_AssetName_JSONKey = + property $ do + v <- forAll genAssetName + tripping (Map.singleton v ()) encode eitherDecode + + -- ----------------------------------------------------------------------------- tests :: TestTree