{-# LANGUAGE OverloadedStrings #-}
module Test.Gen.Cardano.Api.Metadata
( genTxMetadata
, genTxMetadataValue
, genJsonForTxMetadata
)
where
import Cardano.Api
import Data.Aeson (ToJSON (..))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as Aeson
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Word (Word64)
import GHC.Exts (IsList (..))
import Hedgehog (Gen)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Internal.Gen as Gen
import qualified Hedgehog.Range as Range
genJsonForTxMetadata :: TxMetadataJsonSchema -> Gen Aeson.Value
genJsonForTxMetadata :: TxMetadataJsonSchema -> Gen Value
genJsonForTxMetadata TxMetadataJsonSchema
mapping =
(Size -> Gen Value) -> Gen Value
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> Gen Value) -> Gen Value)
-> (Size -> Gen Value) -> Gen Value
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
[Pair] -> Value
Aeson.object
([Pair] -> Value) -> GenT Identity [Pair] -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Pair -> GenT Identity [Pair]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz))
( ((,) (Key -> Value -> Pair)
-> (Word64 -> Key) -> Word64 -> Value -> Pair
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Key
Aeson.fromString (String -> Key) -> (Word64 -> String) -> Word64 -> Key
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> String
forall a. Show a => a -> String
show (Word64 -> Value -> Pair)
-> GenT Identity Word64 -> GenT Identity (Value -> Pair)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Word64 -> GenT Identity Word64
forall (m :: * -> *). MonadGen m => Range Word64 -> m Word64
Gen.word64 Range Word64
forall a. (Bounded a, Num a) => Range a
Range.constantBounded)
GenT Identity (Value -> Pair) -> Gen Value -> GenT Identity Pair
forall a b.
GenT Identity (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TxMetadataJsonSchema -> Gen Value
genJsonForTxMetadataValue TxMetadataJsonSchema
mapping
)
genJsonForTxMetadataValue :: TxMetadataJsonSchema -> Gen Aeson.Value
genJsonForTxMetadataValue :: TxMetadataJsonSchema -> Gen Value
genJsonForTxMetadataValue TxMetadataJsonSchema
TxMetadataJsonNoSchema = Gen Value
genJsonValue
where
genJsonValue :: Gen Aeson.Value
genJsonValue :: Gen Value
genJsonValue =
(Size -> Gen Value) -> Gen Value
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> Gen Value) -> Gen Value)
-> (Size -> Gen Value) -> Gen Value
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
[(Int, Gen Value)] -> Gen Value
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
Gen.frequency
[ (Int
1, Integer -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON (Integer -> Value) -> GenT Identity Integer -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Integer
genJsonNumber)
, (Int
2, Text -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON (Text -> Value) -> GenT Identity Text -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Text
genJsonText)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, [Value] -> Value
forall a. ToJSON a => a -> Value
Aeson.toJSON ([Value] -> Value) -> GenT Identity [Value] -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size) -> GenT Identity [Value] -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) GenT Identity [Value]
genJsonList
)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, [Pair] -> Value
Aeson.object ([Pair] -> Value) -> GenT Identity [Pair] -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size) -> GenT Identity [Pair] -> GenT Identity [Pair]
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) GenT Identity [Pair]
genJsonMap
)
]
genJsonNumber :: Gen Integer
genJsonNumber :: GenT Identity Integer
genJsonNumber =
Range Integer -> GenT Identity Integer
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral
( Integer -> Integer -> Range Integer
forall a. Integral a => a -> a -> Range a
Range.linear
(-Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
(Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
)
genJsonText :: Gen Text
genJsonText :: GenT Identity Text
genJsonText =
[GenT Identity Text] -> GenT Identity Text
forall (m :: * -> *) a. MonadGen m => [m a] -> m a
Gen.choice
[ (Text -> Bool) -> GenT Identity Text -> GenT Identity Text
forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
Gen.ensure Text -> Bool
validText (Int -> GenT Identity Text
forall {f :: * -> *}. MonadGen f => Int -> f Text
genText Int
64)
, (Text -> Bool) -> GenT Identity Text -> GenT Identity Text
forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
Gen.ensure Text -> Bool
validText ((Text
bytesPrefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>) (Text -> Text) -> GenT Identity Text -> GenT Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> GenT Identity Text
forall {f :: * -> *}. MonadGen f => Int -> f Text
genText Int
62)
, GenT Identity Text
genBytes
, String -> Text
Text.pack (String -> Text) -> (Integer -> String) -> Integer -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> String
forall a. Show a => a -> String
show (Integer -> Text) -> GenT Identity Integer -> GenT Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Integer
genJsonNumber
]
where
validText :: Text -> Bool
validText Text
t = ByteString -> Int
BS.length (Text -> ByteString
Text.encodeUtf8 Text
t) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
64
bytesPrefix :: Text
bytesPrefix = Text
"0x"
genText :: Int -> f Text
genText Int
sz = String -> Text
Text.pack (String -> Text) -> f String -> f Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> f Char -> f String
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
sz) f Char
forall (m :: * -> *). MonadGen m => m Char
Gen.alphaNum
genBytes :: GenT Identity Text
genBytes =
(Text
bytesPrefix Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>)
(Text -> Text) -> ([Word8] -> Text) -> [Word8] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeUtf8
(ByteString -> Text) -> ([Word8] -> ByteString) -> [Word8] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Base16.encode
(ByteString -> ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack
([Word8] -> Text) -> GenT Identity [Word8] -> GenT Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Word8 -> GenT Identity [Word8]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
64)
(Range Word8 -> GenT Identity Word8
forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
Gen.word8 Range Word8
forall a. (Bounded a, Num a) => Range a
Range.constantBounded)
genJsonList :: Gen [Aeson.Value]
genJsonList :: GenT Identity [Value]
genJsonList = (Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [Value]) -> GenT Identity [Value])
-> (Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int -> Gen Value -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz)) Gen Value
genJsonValue
genJsonKey :: Gen Aeson.Key
genJsonKey :: Gen Key
genJsonKey = (Text -> Key) -> GenT Identity Text -> Gen Key
forall a b. (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Key
Aeson.fromText GenT Identity Text
genJsonText
genJsonMap :: Gen [(Aeson.Key, Aeson.Value)]
genJsonMap :: GenT Identity [Pair]
genJsonMap = (Size -> GenT Identity [Pair]) -> GenT Identity [Pair]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [Pair]) -> GenT Identity [Pair])
-> (Size -> GenT Identity [Pair]) -> GenT Identity [Pair]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int -> GenT Identity Pair -> GenT Identity [Pair]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz)) (GenT Identity Pair -> GenT Identity [Pair])
-> GenT Identity Pair -> GenT Identity [Pair]
forall a b. (a -> b) -> a -> b
$
(,) (Key -> Value -> Pair) -> Gen Key -> GenT Identity (Value -> Pair)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Key
genJsonKey GenT Identity (Value -> Pair) -> Gen Value -> GenT Identity Pair
forall a b.
GenT Identity (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Value
genJsonValue
genJsonForTxMetadataValue TxMetadataJsonSchema
TxMetadataJsonDetailedSchema = Gen Value
genJsonValue
where
genJsonValue :: Gen Aeson.Value
genJsonValue :: Gen Value
genJsonValue =
(Size -> Gen Value) -> Gen Value
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> Gen Value) -> Gen Value)
-> (Size -> Gen Value) -> Gen Value
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
[(Int, Gen Value)] -> Gen Value
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
Gen.frequency
[ (Int
1, Key -> Value -> Value
singleFieldObject Key
"int" (Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonNumber)
, (Int
1, Key -> Value -> Value
singleFieldObject Key
"bytes" (Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonBytes)
, (Int
1, Key -> Value -> Value
singleFieldObject Key
"string" (Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonText)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, Key -> Value -> Value
singleFieldObject Key
"list"
(Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size) -> Gen Value -> Gen Value
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) Gen Value
genJsonList
)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, Key -> Value -> Value
singleFieldObject Key
"map"
(Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size) -> Gen Value -> Gen Value
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) Gen Value
genJsonMap
)
]
singleFieldObject :: Key -> Value -> Value
singleFieldObject Key
name Value
v = [Pair] -> Value
Aeson.object [(Key
name, Value
v)]
genJsonNumber :: Gen Aeson.Value
genJsonNumber :: Gen Value
genJsonNumber =
Integer -> Value
forall a. ToJSON a => a -> Value
toJSON
(Integer -> Value) -> GenT Identity Integer -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Integer -> GenT Identity Integer
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral
( Integer -> Integer -> Range Integer
forall a. Integral a => a -> a -> Range a
Range.linear
(-Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
(Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
)
genJsonBytes :: Gen Aeson.Value
genJsonBytes :: Gen Value
genJsonBytes =
Text -> Value
forall a. ToJSON a => a -> Value
toJSON
(Text -> Value) -> ([Word8] -> Text) -> [Word8] -> Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
Text.decodeLatin1
(ByteString -> Text) -> ([Word8] -> ByteString) -> [Word8] -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
Base16.encode
(ByteString -> ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Word8] -> ByteString
BS.pack
([Word8] -> Value) -> GenT Identity [Word8] -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Word8 -> GenT Identity [Word8]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
64)
(Range Word8 -> GenT Identity Word8
forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
Gen.word8 Range Word8
forall a. (Bounded a, Num a) => Range a
Range.constantBounded)
genJsonText :: Gen Aeson.Value
genJsonText :: Gen Value
genJsonText =
(Text -> Value) -> GenT Identity Text -> Gen Value
forall a b. (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> Value
forall a. ToJSON a => a -> Value
toJSON (GenT Identity Text -> Gen Value)
-> GenT Identity Text -> Gen Value
forall a b. (a -> b) -> a -> b
$
(Text -> Bool) -> GenT Identity Text -> GenT Identity Text
forall (m :: * -> *) a. MonadGen m => (a -> Bool) -> m a -> m a
Gen.ensure Text -> Bool
validText (GenT Identity Text -> GenT Identity Text)
-> GenT Identity Text -> GenT Identity Text
forall a b. (a -> b) -> a -> b
$
String -> Text
Text.pack (String -> Text) -> GenT Identity String -> GenT Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Char -> GenT Identity String
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
64) GenT Identity Char
forall (m :: * -> *). MonadGen m => m Char
Gen.alphaNum
where
validText :: Text -> Bool
validText Text
t = ByteString -> Int
BS.length (Text -> ByteString
Text.encodeUtf8 Text
t) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
64
genJsonList :: Gen Aeson.Value
genJsonList :: Gen Value
genJsonList = ([Value] -> Value) -> GenT Identity [Value] -> Gen Value
forall a b. (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON (GenT Identity [Value] -> Gen Value)
-> GenT Identity [Value] -> Gen Value
forall a b. (a -> b) -> a -> b
$
(Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [Value]) -> GenT Identity [Value])
-> (Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int -> Gen Value -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz)) Gen Value
genJsonValue
genJsonMap :: Gen Aeson.Value
genJsonMap :: Gen Value
genJsonMap = ([Value] -> Value) -> GenT Identity [Value] -> Gen Value
forall a b. (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Value] -> Value
forall a. ToJSON a => a -> Value
toJSON (GenT Identity [Value] -> Gen Value)
-> GenT Identity [Value] -> Gen Value
forall a b. (a -> b) -> a -> b
$
(Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [Value]) -> GenT Identity [Value])
-> (Size -> GenT Identity [Value]) -> GenT Identity [Value]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int -> Gen Value -> GenT Identity [Value]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz)) (Gen Value -> GenT Identity [Value])
-> Gen Value -> GenT Identity [Value]
forall a b. (a -> b) -> a -> b
$
Value -> Value -> Value
mkKVPair (Value -> Value -> Value)
-> Gen Value -> GenT Identity (Value -> Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonValue GenT Identity (Value -> Value) -> Gen Value -> Gen Value
forall a b.
GenT Identity (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Value
genJsonValue
where
mkKVPair :: Aeson.Value -> Aeson.Value -> Aeson.Value
mkKVPair :: Value -> Value -> Value
mkKVPair Value
k Value
v = [Pair] -> Value
Aeson.object [(Key
"k", Value
k), (Key
"v", Value
v)]
genTxMetadata :: Gen TxMetadata
genTxMetadata :: Gen TxMetadata
genTxMetadata =
(Size -> Gen TxMetadata) -> Gen TxMetadata
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> Gen TxMetadata) -> Gen TxMetadata)
-> (Size -> Gen TxMetadata) -> Gen TxMetadata
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Map Word64 TxMetadataValue -> TxMetadata
TxMetadata (Map Word64 TxMetadataValue -> TxMetadata)
-> ([(Word64, TxMetadataValue)] -> Map Word64 TxMetadataValue)
-> [(Word64, TxMetadataValue)]
-> TxMetadata
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Word64, TxMetadataValue)] -> Map Word64 TxMetadataValue
[Item (Map Word64 TxMetadataValue)] -> Map Word64 TxMetadataValue
forall l. IsList l => [Item l] -> l
fromList
([(Word64, TxMetadataValue)] -> TxMetadata)
-> GenT Identity [(Word64, TxMetadataValue)] -> Gen TxMetadata
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int
-> GenT Identity (Word64, TxMetadataValue)
-> GenT Identity [(Word64, TxMetadataValue)]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz))
( (,)
(Word64 -> TxMetadataValue -> (Word64, TxMetadataValue))
-> GenT Identity Word64
-> GenT Identity (TxMetadataValue -> (Word64, TxMetadataValue))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Word64 -> GenT Identity Word64
forall (m :: * -> *). MonadGen m => Range Word64 -> m Word64
Gen.word64 Range Word64
forall a. (Bounded a, Num a) => Range a
Range.constantBounded
GenT Identity (TxMetadataValue -> (Word64, TxMetadataValue))
-> GenT Identity TxMetadataValue
-> GenT Identity (Word64, TxMetadataValue)
forall a b.
GenT Identity (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GenT Identity TxMetadataValue
genTxMetadataValue
)
genTxMetadataValue :: Gen TxMetadataValue
genTxMetadataValue :: GenT Identity TxMetadataValue
genTxMetadataValue =
(Size -> GenT Identity TxMetadataValue)
-> GenT Identity TxMetadataValue
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity TxMetadataValue)
-> GenT Identity TxMetadataValue)
-> (Size -> GenT Identity TxMetadataValue)
-> GenT Identity TxMetadataValue
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
[(Int, GenT Identity TxMetadataValue)]
-> GenT Identity TxMetadataValue
forall (m :: * -> *) a. MonadGen m => [(Int, m a)] -> m a
Gen.frequency
[ (Int
1, Integer -> TxMetadataValue
TxMetaNumber (Integer -> TxMetadataValue)
-> GenT Identity Integer -> GenT Identity TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Integer
genTxMetaNumber)
, (Int
1, ByteString -> TxMetadataValue
TxMetaBytes (ByteString -> TxMetadataValue)
-> GenT Identity ByteString -> GenT Identity TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity ByteString
genTxMetaBytes)
, (Int
1, Text -> TxMetadataValue
TxMetaText (Text -> TxMetadataValue)
-> GenT Identity Text -> GenT Identity TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Text
genTxMetaText)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, [TxMetadataValue] -> TxMetadataValue
TxMetaList ([TxMetadataValue] -> TxMetadataValue)
-> GenT Identity [TxMetadataValue] -> GenT Identity TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size)
-> GenT Identity [TxMetadataValue]
-> GenT Identity [TxMetadataValue]
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) GenT Identity [TxMetadataValue]
genTxMetaList
)
,
( Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Size -> Size
forall a. Num a => a -> a
signum Size
sz)
, [(TxMetadataValue, TxMetadataValue)] -> TxMetadataValue
TxMetaMap ([(TxMetadataValue, TxMetadataValue)] -> TxMetadataValue)
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
-> GenT Identity TxMetadataValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Size -> Size)
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
forall (m :: * -> *) a. MonadGen m => (Size -> Size) -> m a -> m a
Gen.scale (Size -> Size -> Size
forall a. Integral a => a -> a -> a
`div` Size
2) GenT Identity [(TxMetadataValue, TxMetadataValue)]
genTxMetaMap
)
]
where
genTxMetaNumber :: Gen Integer
genTxMetaNumber :: GenT Identity Integer
genTxMetaNumber =
Range Integer -> GenT Identity Integer
forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral
( Integer -> Integer -> Range Integer
forall a. Integral a => a -> a -> Range a
Range.linear
(-Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
(Word64 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64
forall a. Bounded a => a
maxBound :: Word64) :: Integer)
)
genTxMetaBytes :: Gen ByteString
genTxMetaBytes :: GenT Identity ByteString
genTxMetaBytes =
[Word8] -> ByteString
BS.pack
([Word8] -> ByteString)
-> GenT Identity [Word8] -> GenT Identity ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Word8 -> GenT Identity [Word8]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
64)
(Range Word8 -> GenT Identity Word8
forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
Gen.word8 Range Word8
forall a. (Bounded a, Num a) => Range a
Range.constantBounded)
genTxMetaText :: Gen Text
genTxMetaText :: GenT Identity Text
genTxMetaText = String -> Text
Text.pack (String -> Text) -> GenT Identity String -> GenT Identity Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range Int -> GenT Identity Char -> GenT Identity String
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 Int
64) GenT Identity Char
forall (m :: * -> *). MonadGen m => m Char
Gen.alphaNum
genTxMetaList :: Gen [TxMetadataValue]
genTxMetaList :: GenT Identity [TxMetadataValue]
genTxMetaList = (Size -> GenT Identity [TxMetadataValue])
-> GenT Identity [TxMetadataValue]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [TxMetadataValue])
-> GenT Identity [TxMetadataValue])
-> (Size -> GenT Identity [TxMetadataValue])
-> GenT Identity [TxMetadataValue]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int
-> GenT Identity TxMetadataValue -> GenT Identity [TxMetadataValue]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list
(Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz))
GenT Identity TxMetadataValue
genTxMetadataValue
genTxMetaMap :: Gen [(TxMetadataValue, TxMetadataValue)]
genTxMetaMap :: GenT Identity [(TxMetadataValue, TxMetadataValue)]
genTxMetaMap = (Size -> GenT Identity [(TxMetadataValue, TxMetadataValue)])
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
forall (m :: * -> *) a. MonadGen m => (Size -> m a) -> m a
Gen.sized ((Size -> GenT Identity [(TxMetadataValue, TxMetadataValue)])
-> GenT Identity [(TxMetadataValue, TxMetadataValue)])
-> (Size -> GenT Identity [(TxMetadataValue, TxMetadataValue)])
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
forall a b. (a -> b) -> a -> b
$ \Size
sz ->
Range Int
-> GenT Identity (TxMetadataValue, TxMetadataValue)
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
forall (m :: * -> *) a. MonadGen m => Range Int -> m a -> m [a]
Gen.list (Int -> Int -> Range Int
forall a. Integral a => a -> a -> Range a
Range.linear Int
0 (Size -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Size
sz)) (GenT Identity (TxMetadataValue, TxMetadataValue)
-> GenT Identity [(TxMetadataValue, TxMetadataValue)])
-> GenT Identity (TxMetadataValue, TxMetadataValue)
-> GenT Identity [(TxMetadataValue, TxMetadataValue)]
forall a b. (a -> b) -> a -> b
$
(,) (TxMetadataValue
-> TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
-> GenT Identity TxMetadataValue
-> GenT
Identity (TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity TxMetadataValue
genTxMetadataValue GenT
Identity (TxMetadataValue -> (TxMetadataValue, TxMetadataValue))
-> GenT Identity TxMetadataValue
-> GenT Identity (TxMetadataValue, TxMetadataValue)
forall a b.
GenT Identity (a -> b) -> GenT Identity a -> GenT Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GenT Identity TxMetadataValue
genTxMetadataValue