{-# LANGUAGE OverloadedStrings #-}

module Gen.Bcc.Api.Metadata
  ( genTxMetadata
  , genTxMetadataValue
  , genJsonForTxMetadata
  ) where

import           Bcc.Prelude
import           Bcc.Api
import           Data.Aeson (ToJSON (..))
import           Hedgehog (Gen)

import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Internal.Gen as Gen
import qualified Hedgehog.Range as Range

-- ----------------------------------------------------------------------------
-- Generators
--

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))
               ((,) (Text -> Value -> Pair)
-> GenT Identity Text -> GenT Identity (Value -> Pair)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> Text
Text.pack (String -> Text) -> (Word64 -> String) -> Word64 -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Word64 -> String
forall a b. (Show a, ConvertText String b) => a -> b
show (Word64 -> Text) -> GenT Identity Word64 -> GenT Identity Text
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 (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 k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Integer -> String
forall a b. (Show a, ConvertText String b) => a -> b
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 k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> Text
Text.decodeUtf8
                    (ByteString -> Text) -> ([Word8] -> ByteString) -> [Word8] -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> ByteString
Base16.encode
                    (ByteString -> ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> ByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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

    genJsonMap :: Gen [(Text, 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
$
                     (,) (Text -> Value -> Pair)
-> GenT Identity Text -> GenT Identity (Value -> Pair)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenT Identity Text
genJsonText GenT Identity (Value -> Pair) -> Gen Value -> GenT Identity Pair
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,         Text -> Value -> Value
singleFieldObject Text
"int"    (Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonNumber)
          , (Int
1,         Text -> Value -> Value
singleFieldObject Text
"bytes"  (Value -> Value) -> Gen Value -> Gen Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Value
genJsonBytes)
          , (Int
1,         Text -> Value -> Value
singleFieldObject Text
"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),
                        Text -> Value -> Value
singleFieldObject Text
"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),
                        Text -> Value -> Value
singleFieldObject Text
"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 :: Text -> Value -> Value
singleFieldObject Text
name Value
v = [Pair] -> Value
Aeson.object [(Text
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 k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> Text
Text.decodeLatin1
                 (ByteString -> Text) -> ([Word8] -> ByteString) -> [Word8] -> Text
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. ByteString -> ByteString
Base16.encode
                 (ByteString -> ByteString)
-> ([Word8] -> ByteString) -> [Word8] -> ByteString
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat 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 (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 (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 (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 (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 [ (Text
"k", Value
k), (Text
"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 k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. [(Word64, TxMetadataValue)] -> Map Word64 TxMetadataValue
forall k a. Ord k => [(k, a)] -> Map k a
Map.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 (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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> GenT Identity TxMetadataValue
genTxMetadataValue