Removed Apropos
This commit is contained in:
parent
8c312a46bd
commit
339dad0165
5 changed files with 1060 additions and 1980 deletions
94
agora-specs/Property/Generator.hs
Normal file
94
agora-specs/Property/Generator.hs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
{- |
|
||||
Module : Property.Generator
|
||||
Maintainer : seungheon.ooh@gmail.com
|
||||
Description: Generic generators for property tests
|
||||
|
||||
Shared generators for all Agora property tests
|
||||
-}
|
||||
module Property.Generator (
|
||||
-- * Credentials
|
||||
genPubKeyHash,
|
||||
genUserCredential,
|
||||
genScriptCredential,
|
||||
genCredential,
|
||||
genAddress,
|
||||
|
||||
-- * Values
|
||||
genValue,
|
||||
genAssetClass,
|
||||
genAnyValue,
|
||||
) 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 (..),
|
||||
PubKeyHash (PubKeyHash),
|
||||
ValidatorHash (ValidatorHash),
|
||||
Value,
|
||||
toBuiltin,
|
||||
)
|
||||
import Plutus.V1.Ledger.Value (
|
||||
AssetClass (AssetClass),
|
||||
assetClassValue,
|
||||
currencySymbol,
|
||||
tokenName,
|
||||
)
|
||||
import Test.QuickCheck (
|
||||
Arbitrary (arbitrary),
|
||||
Gen,
|
||||
chooseAny,
|
||||
elements,
|
||||
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
|
||||
|
|
@ -28,7 +28,7 @@ import Plutus.V1.Ledger.Api (
|
|||
ScriptContext (scriptContextTxInfo),
|
||||
TxInfo (txInfoSignatories),
|
||||
)
|
||||
import Spec.Generator (genAnyValue, genPubKeyHash)
|
||||
import Property.Generator (genAnyValue, genPubKeyHash)
|
||||
import Test.Tasty (TestTree)
|
||||
import Test.Tasty.Plutarch.Property (classifiedProperty)
|
||||
import Test.Tasty.QuickCheck (
|
||||
|
|
@ -40,7 +40,7 @@ import Test.Tasty.QuickCheck (
|
|||
vectorOf,
|
||||
)
|
||||
|
||||
-- | apropos model for testing multisigs.
|
||||
-- | Model for testing multisigs.
|
||||
type MultiSigModel = (MultiSig, ScriptContext)
|
||||
|
||||
-- | Propositions that may hold true of a `MultiSigModel`.
|
||||
|
|
@ -63,7 +63,7 @@ genMultiSigProp :: MultiSigProp -> Gen MultiSigModel
|
|||
genMultiSigProp prop = do
|
||||
size <- chooseInt (4, 20)
|
||||
pkhs <- vectorOf size genPubKeyHash
|
||||
vutxo <- pure . ValidatorUTXO () <$> genAnyValue
|
||||
vutxo <- ValidatorUTXO () <$> genAnyValue
|
||||
minSig <- chooseInt (1, length pkhs)
|
||||
othersigners <- take 20 <$> listOf genPubKeyHash
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue