Skip to content

Commit

Permalink
organization
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Dec 15, 2023
1 parent b109e73 commit 26eb0cc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 56 deletions.
6 changes: 5 additions & 1 deletion pact-core-tests/Pact/Core/Test/LegacySerialiseTests.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
-- |
-- | Tests that values encoded by legacy pact deployments
-- decode into the expected pact-core values.
-- TODO: We need to write many more such tests during the legacy
-- pact compatibilty epic.

{-# LANGUAGE OverloadedStrings #-}

module Pact.Core.Test.LegacySerialiseTests where
Expand Down
116 changes: 61 additions & 55 deletions pact-core-tests/Pact/Core/Test/SerialiseTests.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- |
-- | Roundtrip tests for serialization of entities
-- appearing in the pact database and TxLogs.

module Pact.Core.Test.SerialiseTests where

Expand All @@ -14,6 +15,65 @@ import Codec.CBOR.Read (deserialiseFromBytes)
import Data.ByteString (fromStrict)
import Codec.CBOR.Write (toStrictByteString)



tests :: TestTree
tests = testGroup "Serialise Roundtrip"
[ testGroup "Document"
[ testProperty "DocumentVersion" serialiseRoundtripVersion
]
, testGroup "CBOR"
[ testProperty "NamespaceName" $ serialiseRoundtrip namespaceNameGen
, testProperty "ModuleName" $ serialiseRoundtrip moduleNameGen
, testProperty "KeySetName" $ serialiseRoundtrip keySetNameGen
, testProperty "QualifiedName" $ serialiseRoundtrip qualifiedNameGen
, testProperty "BareName" $ serialiseRoundtrip bareNameGen
, testProperty "DynamicName" $ serialiseRoundtrip dynamicNameGen
, testProperty "ParsedName" $ serialiseRoundtrip parsedNameGen
, testProperty "Hash" $ serialiseRoundtrip hashGen
, testProperty "ModuleHash" $ serialiseRoundtrip moduleHashGen
, testProperty "FullyQualifiedName" $ serialiseRoundtrip fullyQualifiedNameGen
, testProperty "DynamicRef" $ serialiseRoundtrip dynamicRefGen
, testProperty "NameKind" $ serialiseRoundtrip nameKindGen
, testProperty "Name" $ serialiseRoundtrip nameGen
, testProperty "resolvedGov" $ serialiseRoundtrip resolvedGovGen
, testProperty "Governance" $ serialiseRoundtrip governanceGen
, testProperty "PrimType" $ serialiseRoundtrip tyPrimGen
, testProperty "Field" $ serialiseRoundtrip fieldGen
, testProperty "Schema" $ serialiseRoundtrip schemaGen
, testProperty "Types" $ serialiseRoundtrip typeGen
, testProperty "Arg" $ serialiseRoundtrip argGen
, testProperty "Import" $ serialiseRoundtrip importGen
, testProperty "SpanInfo" $ serialiseRoundtrip infoGen
, testProperty "Builtin" $ serialiseRoundtrip builtinGen
, testProperty "Literal" $ serialiseRoundtrip literalGen
, testProperty "LamInfo" $ serialiseRoundtrip lamInfoGen
, testProperty "BuiltinForm" $ serialiseRoundtrip (builtinFormGen builtinGen infoGen)
, testProperty "Term" $ serialiseRoundtrip (termGen builtinGen infoGen)
, testProperty "Defun" $ serialiseRoundtrip (defunGen builtinGen infoGen)
, testProperty "DefConst" $ serialiseRoundtrip (defConstGen builtinGen infoGen)
, testProperty "FQNameRef" $ serialiseRoundtrip fqNameRefGen
, testProperty "DefManagedMeta" $ serialiseRoundtrip (defManagedMetaGen bareNameGen)
, testProperty "DefCapMeta" $ serialiseRoundtrip (defCapMetaGen bareNameGen)
, testProperty "DefCap" $ serialiseRoundtrip (defCapGen builtinGen infoGen)
, testProperty "Def" $ serialiseRoundtrip (defGen builtinGen infoGen)
, testProperty "Module" $ serialiseRoundtrip (evalModuleGen builtinGen infoGen)
, testProperty "DefSchema" $ serialiseRoundtrip (defSchemaGen infoGen)
, testProperty "DefTable" $ serialiseRoundtrip (defTableGen infoGen)
, testProperty "Step" $ serialiseRoundtrip (stepGen builtinGen infoGen)
, testProperty "DefPact" $ serialiseRoundtrip (defPactGen builtinGen infoGen)
],
testGroup "CBOR Serialise"
[ testProperty "KeySet roundtrip" serialiseKeySet
, testProperty "Module roundtrip" serialiseModule
, testProperty "DefPactExec roundtrip" serialiseDefPactExec
]
]

-- * Utility functions.

-- | For any CBOR-Serialisable and `Gen` type, assert that serialization
-- roundtrips.
serialiseRoundtrip :: forall a. (S.Serialise a, Show a, Eq a) => Gen a -> Property
serialiseRoundtrip g = property $ do
expr <- forAll g
Expand Down Expand Up @@ -71,57 +131,3 @@ serialiseRoundtripVersion = property $ do
case deserialiseFromBytes decodeVersion (fromStrict encoded) of
Left _ -> fail "fail"
Right (_, v') -> v === v'


tests :: TestTree
tests = testGroup "Serialise Roundtrip"
[ testGroup "Document"
[ testProperty "DocumentVersion" serialiseRoundtripVersion
]
, testGroup "CBOR"
[ testProperty "NamespaceName" $ serialiseRoundtrip namespaceNameGen
, testProperty "ModuleName" $ serialiseRoundtrip moduleNameGen
, testProperty "KeySetName" $ serialiseRoundtrip keySetNameGen
, testProperty "QualifiedName" $ serialiseRoundtrip qualifiedNameGen
, testProperty "BareName" $ serialiseRoundtrip bareNameGen
, testProperty "DynamicName" $ serialiseRoundtrip dynamicNameGen
, testProperty "ParsedName" $ serialiseRoundtrip parsedNameGen
, testProperty "Hash" $ serialiseRoundtrip hashGen
, testProperty "ModuleHash" $ serialiseRoundtrip moduleHashGen
, testProperty "FullyQualifiedName" $ serialiseRoundtrip fullyQualifiedNameGen
, testProperty "DynamicRef" $ serialiseRoundtrip dynamicRefGen
, testProperty "NameKind" $ serialiseRoundtrip nameKindGen
, testProperty "Name" $ serialiseRoundtrip nameGen
, testProperty "resolvedGov" $ serialiseRoundtrip resolvedGovGen
, testProperty "Governance" $ serialiseRoundtrip governanceGen
, testProperty "PrimType" $ serialiseRoundtrip tyPrimGen
, testProperty "Field" $ serialiseRoundtrip fieldGen
, testProperty "Schema" $ serialiseRoundtrip schemaGen
, testProperty "Types" $ serialiseRoundtrip typeGen
, testProperty "Arg" $ serialiseRoundtrip argGen
, testProperty "Import" $ serialiseRoundtrip importGen
, testProperty "SpanInfo" $ serialiseRoundtrip infoGen
, testProperty "Builtin" $ serialiseRoundtrip builtinGen
, testProperty "Literal" $ serialiseRoundtrip literalGen
, testProperty "LamInfo" $ serialiseRoundtrip lamInfoGen
, testProperty "BuiltinForm" $ serialiseRoundtrip (builtinFormGen builtinGen infoGen)
, testProperty "Term" $ serialiseRoundtrip (termGen builtinGen infoGen)
, testProperty "Defun" $ serialiseRoundtrip (defunGen builtinGen infoGen)
, testProperty "DefConst" $ serialiseRoundtrip (defConstGen builtinGen infoGen)
, testProperty "FQNameRef" $ serialiseRoundtrip fqNameRefGen
, testProperty "DefManagedMeta" $ serialiseRoundtrip (defManagedMetaGen bareNameGen)
, testProperty "DefCapMeta" $ serialiseRoundtrip (defCapMetaGen bareNameGen)
, testProperty "DefCap" $ serialiseRoundtrip (defCapGen builtinGen infoGen)
, testProperty "Def" $ serialiseRoundtrip (defGen builtinGen infoGen)
, testProperty "Module" $ serialiseRoundtrip (evalModuleGen builtinGen infoGen)
, testProperty "DefSchema" $ serialiseRoundtrip (defSchemaGen infoGen)
, testProperty "DefTable" $ serialiseRoundtrip (defTableGen infoGen)
, testProperty "Step" $ serialiseRoundtrip (stepGen builtinGen infoGen)
, testProperty "DefPact" $ serialiseRoundtrip (defPactGen builtinGen infoGen)
],
testGroup "CBOR Serialise"
[ testProperty "KeySet roundtrip" serialiseKeySet
, testProperty "Module roundtrip" serialiseModule
, testProperty "DefPactExec roundtrip" serialiseDefPactExec
]
]

0 comments on commit 26eb0cc

Please sign in to comment.