Replaced Apropos Property testing with PQ and PCB for MultiSig
This commit is contained in:
parent
cb9974324b
commit
8c312a46bd
7 changed files with 226 additions and 205 deletions
103
agora-specs/Spec/Generator.hs
Normal file
103
agora-specs/Spec/Generator.hs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
{- |
|
||||
Module : Spec.Generator
|
||||
Maintainer : seungheon.ooh@gmail.com
|
||||
Description: Generic generators for property tests
|
||||
|
||||
Shared generators for all Agora property tests
|
||||
-}
|
||||
module Spec.Generator (
|
||||
-- * Credentials
|
||||
genPubKeyHash,
|
||||
genUserCredential,
|
||||
genScriptCredential,
|
||||
genCredential,
|
||||
genAddress,
|
||||
|
||||
-- * Values
|
||||
genValue,
|
||||
genAssetClass,
|
||||
genAnyValue,
|
||||
|
||||
-- * Tx info
|
||||
genTxOut,
|
||||
genTxInInfo,
|
||||
) where
|
||||
|
||||
import Control.Applicative (Applicative (liftA2))
|
||||
import Data.ByteString.Char8 qualified as C (ByteString, pack)
|
||||
import Data.ByteString.Hash (sha2)
|
||||
import Plutus.V1.Ledger.Api (
|
||||
Address (Address),
|
||||
Credential (..),
|
||||
DatumHash (DatumHash),
|
||||
PubKeyHash (PubKeyHash),
|
||||
TxInInfo (TxInInfo),
|
||||
TxOut (..),
|
||||
TxOutRef (TxOutRef),
|
||||
ValidatorHash (ValidatorHash),
|
||||
Value,
|
||||
toBuiltin,
|
||||
)
|
||||
import Plutus.V1.Ledger.Value (
|
||||
AssetClass (AssetClass),
|
||||
assetClassValue,
|
||||
currencySymbol,
|
||||
tokenName,
|
||||
)
|
||||
import Test.QuickCheck (
|
||||
Arbitrary (arbitrary),
|
||||
Gen,
|
||||
chooseAny,
|
||||
elements,
|
||||
listOf,
|
||||
listOf1,
|
||||
oneof,
|
||||
)
|
||||
|
||||
{- | Generate a random Hash
|
||||
Hashs cannot be shrunken; functions utilizing this function,
|
||||
therefore, cannot be shrunken as well.
|
||||
-}
|
||||
genHashByteString :: Gen C.ByteString
|
||||
genHashByteString = sha2 . C.pack . show <$> (chooseAny :: Gen Integer)
|
||||
|
||||
-- TODO: How do I need to ensure uniqueness?
|
||||
|
||||
-- | Random PubKeyHash
|
||||
genPubKeyHash :: Gen PubKeyHash
|
||||
genPubKeyHash = PubKeyHash . toBuiltin <$> genHashByteString
|
||||
|
||||
-- | Random user credential.
|
||||
genUserCredential :: Gen Credential
|
||||
genUserCredential = PubKeyCredential . PubKeyHash . toBuiltin <$> genHashByteString
|
||||
|
||||
-- | Random script credential.
|
||||
genScriptCredential :: Gen Credential
|
||||
genScriptCredential = ScriptCredential . ValidatorHash . toBuiltin <$> genHashByteString
|
||||
|
||||
-- | Random credential: combination of user and script credential generators.
|
||||
genCredential :: Gen Credential
|
||||
genCredential = oneof [genUserCredential, genScriptCredential]
|
||||
|
||||
genAddress :: Gen Address
|
||||
genAddress = flip Address Nothing <$> genCredential
|
||||
|
||||
{- | Random Value of given AssetClass
|
||||
`genAnyValue` will create a random value with a random assetclass.
|
||||
-}
|
||||
genValue :: AssetClass -> Gen Value
|
||||
genValue ac = assetClassValue ac . abs <$> (arbitrary :: Gen Integer)
|
||||
|
||||
genPrettyByteString :: Gen C.ByteString
|
||||
genPrettyByteString = C.pack <$> listOf1 (elements ['a' .. 'z'])
|
||||
|
||||
genAssetClass :: Gen AssetClass
|
||||
genAssetClass =
|
||||
AssetClass
|
||||
<$> liftA2
|
||||
(,)
|
||||
(currencySymbol <$> genHashByteString)
|
||||
(tokenName <$> genPrettyByteString)
|
||||
|
||||
genAnyValue :: Gen Value
|
||||
genAnyValue = genAssetClass >>= genValue
|
||||
Loading…
Add table
Add a link
Reference in a new issue