diff --git a/agora-specs/Property/Utils.hs b/agora-specs/Property/Utils.hs new file mode 100644 index 0000000..e8994cf --- /dev/null +++ b/agora-specs/Property/Utils.hs @@ -0,0 +1,39 @@ +module Property.Utils (props) where + +import Agora.Utils (phashDatum) +import Cardano.Prelude (ByteString) +import Plutarch.Api.V2 (datumHash) +import Plutarch.Test.QuickCheck ( + Equality (OnPEq), + Partiality (ByComplete), + haskEquiv', + ) +import Plutarch.Test.QuickCheck.Instances () +import PlutusCore.Data (Data (B)) +import PlutusLedgerApi.V1 (Datum (Datum)) +import PlutusLedgerApi.V2 (BuiltinData (BuiltinData), DatumHash) +import Test.Tasty (TestTree, adjustOption) +import Test.Tasty.QuickCheck ( + Property, + QuickCheckTests, + testProperty, + ) + +propHashDatumCorrect :: Property +propHashDatumCorrect = + haskEquiv' + @'OnPEq + @'ByComplete + hashDatum + phashDatum + where + hashDatum :: ByteString -> DatumHash + hashDatum = datumHash . Datum . BuiltinData . B + +props :: [TestTree] +props = + [ adjustOption go $ testProperty "Correct 'phashDatum'" propHashDatumCorrect + ] + where + go :: QuickCheckTests -> QuickCheckTests + go = max 20_000 diff --git a/agora-specs/Spec/Utils.hs b/agora-specs/Spec/Utils.hs index 16e62d9..cb68b2b 100644 --- a/agora-specs/Spec/Utils.hs +++ b/agora-specs/Spec/Utils.hs @@ -7,7 +7,8 @@ Tests for utility functions in 'Agora.Utils'. -} module Spec.Utils (tests) where -import Test.Tasty (TestTree) +import Property.Utils qualified as Props +import Test.Tasty (TestTree, testGroup) tests :: [TestTree] -tests = [] +tests = [testGroup "properties" Props.props] diff --git a/agora.cabal b/agora.cabal index c32de4c..149414e 100644 --- a/agora.cabal +++ b/agora.cabal @@ -194,6 +194,7 @@ library agora-specs exposed-modules: Property.Generator Property.Governor + Property.Utils Sample.AuthorityToken.UnauthorizedMintingExploit Sample.Effect.GovernorMutation Sample.Effect.TreasuryWithdrawal