Skip to content

Commit

Permalink
Move event and coinModuleName utilities into Utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Dec 22, 2024
1 parent a2a82ba commit 7556d8a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions chainweb.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ library chainweb-test-utils
, pact-time:numeric >=0.3.0.1
, pact-tng >=5.0
, pact-tng:pact-request-api >=5.0
, property-matchers ^>= 0.2
, quickcheck-instances >= 0.3
, random >= 1.2
, resourcet >= 1.3
Expand Down
25 changes: 24 additions & 1 deletion test/lib/Chainweb/Test/Pact5/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ module Chainweb.Test.Pact5.Utils
, withBlockDbs
, withTestBlockHeaderDb
, testRocksDb

-- * Properties
, event
-- * Utilities
, coinModuleName
)
where

Expand All @@ -56,7 +61,6 @@ import Chainweb.Pact.Service.PactQueue
import Chainweb.Pact.Types
import Chainweb.Pact4.Transaction qualified as Pact4
import Chainweb.Pact5.Transaction qualified as Pact5
import Pact.Core.Pretty qualified as Pact5
import Chainweb.Payload.PayloadStore
import Chainweb.Payload.PayloadStore.RocksDB
import Chainweb.Storage.Table.RocksDB
Expand Down Expand Up @@ -87,12 +91,17 @@ import Data.Word (Word64)
import Database.RocksDB.Internal qualified as R
import Pact.Core.Command.Types qualified as Pact5
import Pact.Core.Hash qualified as Pact5
import Pact.Core.Pretty qualified as Pact5
import Pact.JSON.Encode qualified as J
import Pact.Types.Gas qualified as Pact4
import System.Environment (lookupEnv)
import System.IO.Temp (createTempDirectory, getCanonicalTemporaryDirectory)
import System.LogLevel
import System.Random (randomIO)
import PropertyMatchers qualified as P
import Pact.Core.PactValue
import Pact.Core.Capabilities
import Pact.Core.Names

withBlockDbs :: ChainwebVersion -> RocksDb -> ResourceT IO (PayloadDb RocksDbTable, WebBlockHeaderDb)
withBlockDbs v rdb = do
Expand Down Expand Up @@ -251,3 +260,17 @@ getTestLogger = do
logLevel <- getTestLogLevel
return $ genericLogger logLevel (testLogFn logLevel)

-- usually we don't want to check the module hash
event
:: P.Prop Text
-> P.Prop [PactValue]
-> P.Prop ModuleName
-> P.Prop (PactEvent PactValue)
event n args modName = P.allTrue
[ P.fun _peName n
, P.fun _peArgs args
, P.fun _peModule modName
]

coinModuleName :: ModuleName
coinModuleName = ModuleName "coin" Nothing
3 changes: 0 additions & 3 deletions test/unit/Chainweb/Test/Pact5/PactServiceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@ cid = unsafeChainId 0
v :: ChainwebVersion
v = pact5InstantCpmTestVersion singletonChainGraph

coinModuleName :: ModuleName
coinModuleName = ModuleName "coin" Nothing

advanceAllChainsWithTxs :: Fixture -> ChainMap [Pact5.Transaction] -> IO (ChainMap (Vector TestPact5CommandResult))
advanceAllChainsWithTxs fixture txsPerChain =
advanceAllChains fixture $
Expand Down
18 changes: 1 addition & 17 deletions test/unit/Chainweb/Test/Pact5/TransactionExecTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ import Data.IORef
import Data.Maybe (fromMaybe)
import Data.Set qualified as Set
import Data.String (fromString)
import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.Encoding qualified as T
import Data.Text.IO qualified as T
import Chainweb.Test.Pact5.Utils (getTestLogLevel)
import Chainweb.Test.Pact5.Utils hiding (testRocksDb, withTempSQLiteResource)
import GHC.Stack
import Pact.Core.Capabilities
import Pact.Core.Command.Types
Expand All @@ -72,21 +71,6 @@ import Text.Printf
import Chainweb.Logger
import Chainweb.Pact.Backend.Types

coinModuleName :: ModuleName
coinModuleName = ModuleName "coin" Nothing

-- usually we don't want to check the module hash
event
:: P.Prop Text
-> P.Prop [PactValue]
-> P.Prop ModuleName
-> P.Prop (PactEvent PactValue)
event n args modName = P.allTrue
[ P.fun _peName n
, P.fun _peArgs args
, P.fun _peModule modName
]

tests :: RocksDb -> TestTree
tests baseRdb = testGroup "Pact5 TransactionExecTest"
[ testCase "buyGas should take gas tokens from the transaction sender" (buyGasShouldTakeGasTokensFromTheTransactionSender baseRdb)
Expand Down

0 comments on commit 7556d8a

Please sign in to comment.