Skip to content

Commit

Permalink
Migrate to property-matchers
Browse files Browse the repository at this point in the history
This comes with a few API changes, and uses a version that hackage
hasn't yet published in the index, but will soon.
  • Loading branch information
edmundnoble committed Dec 16, 2024
1 parent cdcec78 commit 893efb2
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 238 deletions.
12 changes: 6 additions & 6 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ package yet-another-logger
--
-- nix-prefetch-git --url <location> --rev <tag>

source-repository-package
type: git
location: https://gitlab.com/edmundnoble/property-matchers.git
tag: bb123833a2b11934cac366df62681bc2c24bd82f
--sha256: 18xgvzb3p8chch85747ln9a2191df09vwwrv9v3njr2h69n3rhxj

source-repository-package
type: git
location: https://github.com/kadena-io/pact.git
Expand Down Expand Up @@ -150,12 +156,6 @@ source-repository-package
tag: 90247042ab3b8662809210af2a78e6dee0f9b4ac
--sha256: 0dqsrjxm0cm35xcihm49dhwdvmz79vsv4sd5qs2izc4sbnd0d8n6

source-repository-package
type: git
location: https://gitlab.com/edmundnoble/predicate-transformers
tag: 67c77e68ade204f56d91ad5952fe432188b40d23
--sha256: 0q7nwl56lgic5andc956zv4zipdv5rxjkalm21cxr75r6grkzfmy

-- -------------------------------------------------------------------------- --
-- Relaxed Bounds

Expand Down
2 changes: 1 addition & 1 deletion chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ test-suite chainweb-tests
, pact-tng:pact-request-api
, pact-tng:test-utils
, patience >= 0.3
, predicate-transformers == 0.15.0.0
, property-matchers ^>= 0.2
, pretty-show
, quickcheck-instances >= 0.3
, random >= 1.2
Expand Down
29 changes: 15 additions & 14 deletions test/unit/Chainweb/Test/Pact5/PactServiceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ import Pact.Core.Hash qualified as Pact5
import Pact.Core.Names
import Pact.Core.PactValue
import Pact.Types.Gas qualified as Pact4
import PredicateTransformers as PT
import PropertyMatchers ((?))
import PropertyMatchers qualified as P
import Test.Tasty
import Test.Tasty.HUnit (assertBool, assertEqual, assertFailure, testCase)
import Text.Printf (printf)
Expand Down Expand Up @@ -134,8 +135,8 @@ tests baseRdb = testGroup "Pact5 PactServiceTest"
, testCase "failed txs should go into blocks" (failedTxsShouldGoIntoBlocks baseRdb)
]

successfulTx :: Predicatory p => Pred p (CommandResult log err)
successfulTx = pt _crResult ? match _PactResultOk something
successfulTx :: P.Prop (CommandResult log err)
successfulTx = P.fun _crResult ? P.match _PactResultOk P.succeed

simpleEndToEnd :: RocksDb -> IO ()
simpleEndToEnd baseRdb = runResourceT $ do
Expand All @@ -148,8 +149,8 @@ simpleEndToEnd baseRdb = runResourceT $ do

-- we only care that they succeed; specifics regarding their outputs are in TransactionExecTest
results &
predful ? onChain cid ?
predful ? Vector.replicate 2 successfulTx
P.propful ? onChain cid ?
P.propful ? Vector.replicate 2 successfulTx

newBlockEmpty :: RocksDb -> IO ()
newBlockEmpty baseRdb = runResourceT $ do
Expand All @@ -171,8 +172,8 @@ newBlockEmpty baseRdb = runResourceT $ do
return $ finalizeBlock nonEmptyBip

results &
predful ? onChain cid ?
predful ? Vector.replicate 1 successfulTx
P.propful ? onChain cid ?
P.propful ? Vector.replicate 1 successfulTx

continueBlockSpec :: RocksDb -> IO ()
continueBlockSpec baseRdb = runResourceT $ do
Expand All @@ -194,8 +195,8 @@ continueBlockSpec baseRdb = runResourceT $ do
return $ finalizeBlock bipAllAtOnce
-- assert that 3 successful txs are in the block
allAtOnceResults &
predful ? onChain cid ?
predful ? Vector.replicate 3 successfulTx
P.propful ? onChain cid ?
P.propful ? Vector.replicate 3 successfulTx

-- reset back to the empty block for the next phase
-- next, produce the same block by repeatedly extending a block
Expand Down Expand Up @@ -231,7 +232,7 @@ continueBlockSpec baseRdb = runResourceT $ do
return $ finalizeBlock bipFinal

-- assert that the continued results are equal to doing it all at once
continuedResults & equals allAtOnceResults
continuedResults & P.equals allAtOnceResults

-- * test that the NewBlock timeout works properly and doesn't leave any extra state from a timed-out transaction
newBlockTimeoutSpec :: RocksDb -> IO ()
Expand Down Expand Up @@ -276,10 +277,10 @@ newBlockTimeoutSpec baseRdb = runResourceT $ do
newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
-- Mempool orders by GasPrice. 'buildCwCmd' sets the gas price to the transfer amount.
-- We hope for 'timeoutTx' to fail, meaning that only 'txTransfer2' is in the block.
bip & pt _blockInProgressTransactions ? pt _transactionPairs
? predful ? Vector.fromList
[ pair
(pt _cmdHash ? equals (_cmdHash tx2))
bip & P.fun _blockInProgressTransactions ? P.fun _transactionPairs
? P.propful ? Vector.fromList
[ P.pair
(P.fun _cmdHash ? P.equals (_cmdHash tx2))
successfulTx
]
return $ finalizeBlock bip
Expand Down
30 changes: 14 additions & 16 deletions test/unit/Chainweb/Test/Pact5/RemotePactTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import Chainweb.Test.Pact5.CmdBuilder
import Chainweb.Test.Pact5.CutFixture qualified as CutFixture
import Chainweb.Test.Pact5.Utils
import Chainweb.Test.TestVersions
import Chainweb.Test.Utils (deadbeef)
import Chainweb.Test.Utils (deadbeef, TestPact5CommandResult)
import Chainweb.Test.Utils (testRetryPolicy)
import Chainweb.Utils
import Chainweb.Version
Expand Down Expand Up @@ -93,7 +93,8 @@ import Pact.Core.Errors
import Pact.Core.Gas.Types
import Pact.Core.Hash qualified as Pact5
import Pact.JSON.Encode qualified as J
import PredicateTransformers as PT
import PropertyMatchers ((?))
import PropertyMatchers qualified as P
import Servant.Client
import Test.Tasty
import Test.Tasty.HUnit (assertBool, assertEqual, assertFailure, testCase)
Expand Down Expand Up @@ -276,21 +277,20 @@ spvTest baseRdb = runResourceT $ do
_ <- CutFixture.advanceAllChains v (fixture ^. cutFixture)
recvCr <- fmap (HashMap.! recvReqKey) $ polling v targetChain clientEnv (NE.singleton recvReqKey)
recvCr
& allTrue
[ pt _crResult ? match _PactResultOk something
, pt _crEvents ? predful
[ something
, allTrue
[ pt _peName ? equals "TRANSFER_XCHAIN_RECD"
, pt _peArgs ? traceFailShow ? equals
& P.allTrue
[ P.fun _crResult ? P.match _PactResultOk P.succeed
, P.fun _crEvents ? P.propful
[ P.succeed
, P.allTrue
[ P.fun _peName ? P.equals "TRANSFER_XCHAIN_RECD"
, P.fun _peArgs ? P.equals
[PString "", PString "sender01", PDecimal 1.0, PString (chainIdToText srcChain)]
]
, pt _peName ? equals "X_RESUME"
, something
, P.fun _peName ? P.equals "X_RESUME"
, P.succeed
]
]


pure ()

pure ()
Expand Down Expand Up @@ -419,11 +419,9 @@ trivialTx cid n = defaultCmd
, _cbGasLimit = GasLimit (Gas 1_000)
}

_successfulTx :: Predicatory p => Pred p (CommandResult log err)
_successfulTx = pt _crResult ? match _PactResultOk something
_successfulTx :: P.Prop (CommandResult log err)
_successfulTx = P.fun _crResult ? P.match _PactResultOk P.succeed

pactDeadBeef :: RequestKey
pactDeadBeef = case deadbeef of
TransactionHash bytes -> RequestKey (Pact5.Hash bytes)

type TestPact5CommandResult = CommandResult Pact5.Hash (PactErrorCompat (LocatedErrorInfo Info))
7 changes: 4 additions & 3 deletions test/unit/Chainweb/Test/Pact5/SPVTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ import Pact.Core.Serialise
import Pact.Core.StableEncoding (encodeStable)
import Pact.Core.Verifiers
import Pact.Types.Gas qualified as Pact4
import PredicateTransformers as PT
import PropertyMatchers ((?))
import PropertyMatchers qualified as P
import Streaming.Prelude qualified as Stream
import System.LogLevel
import System.LogLevel (LogLevel (..))
Expand Down Expand Up @@ -252,8 +253,8 @@ tests baseRdb = testGroup "Pact5 SPVTest"
[ --testCase "simple end to end" (simpleEndToEnd baseRdb)
]

successfulTx :: Predicatory p => Pred p (CommandResult log err)
successfulTx = pt _crResult ? match _PactResultOk something
successfulTx :: P.Prop (CommandResult log err)
successfulTx = P.fun _crResult ? P.match _PactResultOk P.succeed

cid = unsafeChainId 0
v = pact5InstantCpmTestVersion singletonChainGraph
Loading

0 comments on commit 893efb2

Please sign in to comment.