Skip to content

Commit

Permalink
s/mempool{Insert,Lookup}5/mempool{Insert,Lookup}Pact5
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundnoble committed Jan 7, 2025
1 parent 0326a50 commit 8e0b6db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions test/lib/Chainweb/Test/Pact5/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module Chainweb.Test.Pact5.Utils
, getTestLogger

-- * Mempool
, mempoolInsert5
, mempoolLookup5
, mempoolInsertPact5
, mempoolLookupPact5

-- * Resources
, withTempSQLiteResource
Expand Down Expand Up @@ -200,8 +200,8 @@ withRunPactService logger v cid pactQueue mempool webBHDb payloadDb pactServiceC

-- | Insert a 'Pact5.Transaction' into the mempool. The mempool currently operates by default on
-- 'Pact4.UnparsedTransaction's, so the txs have to be converted.
mempoolInsert5 :: MempoolBackend Pact4.UnparsedTransaction -> InsertType -> [Pact5.Transaction] -> IO ()
mempoolInsert5 mp insertType txs = do
mempoolInsertPact5 :: MempoolBackend Pact4.UnparsedTransaction -> InsertType -> [Pact5.Transaction] -> IO ()
mempoolInsertPact5 mp insertType txs = do
let unparsedTxs :: [Pact4.UnparsedTransaction]
unparsedTxs = flip map txs $ \tx ->
case codecDecode Pact4.rawCommandCodec (codecEncode Pact5.payloadCodec tx) of
Expand All @@ -210,8 +210,8 @@ mempoolInsert5 mp insertType txs = do
mempoolInsert mp insertType $ Vector.fromList unparsedTxs

-- | Looks up transactions in the mempool. Returns a set which indicates pending membership of the mempool.
mempoolLookup5 :: MempoolBackend Pact4.UnparsedTransaction -> Vector Pact5.Hash -> IO (HashSet Pact5.Hash)
mempoolLookup5 mp hashes = do
mempoolLookupPact5 :: MempoolBackend Pact4.UnparsedTransaction -> Vector Pact5.Hash -> IO (HashSet Pact5.Hash)
mempoolLookupPact5 mp hashes = do
results <- mempoolLookup mp $ Vector.map (TransactionHash . Pact5.unHash) hashes
return $ HashSet.fromList $ Vector.toList $ flip Vector.mapMaybe results $ \case
Missing -> Nothing
Expand Down
26 changes: 13 additions & 13 deletions test/unit/Chainweb/Test/Pact5/PactServiceTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ newBlockEmpty baseRdb = runResourceT $ do
liftIO $ do
cmd <- buildCwCmd v (transferCmd 1.0)
_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert5 mempool CheckedInsert [cmd]
mempoolInsertPact5 mempool CheckedInsert [cmd]
-- -- Test that NewBlockEmpty ignores the mempool
emptyBip <- throwIfNotPact5 =<< throwIfNoHistory =<<
newBlock noMiner NewBlockEmpty (ParentHeader ph) pactQueue
Expand Down Expand Up @@ -188,7 +188,7 @@ continueBlockSpec baseRdb = runResourceT $ do

allAtOnceResults <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
-- insert all transactions
mempoolInsert5 mempool CheckedInsert [cmd1, cmd2, cmd3]
mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2, cmd3]
-- construct a new block with all of said transactions
bipAllAtOnce <- throwIfNotPact5 =<< throwIfNoHistory =<<
newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
Expand All @@ -207,14 +207,14 @@ continueBlockSpec baseRdb = runResourceT $ do
revert fixture startCut
continuedResults <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolClear mempool
mempoolInsert5 mempool CheckedInsert [cmd3]
mempoolInsertPact5 mempool CheckedInsert [cmd3]
bipStart <- throwIfNotPact5 =<< throwIfNoHistory =<<
newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue

mempoolInsert5 mempool CheckedInsert [cmd2]
mempoolInsertPact5 mempool CheckedInsert [cmd2]
bipContinued <- throwIfNoHistory =<< continueBlock bipStart pactQueue

mempoolInsert5 mempool CheckedInsert [cmd1]
mempoolInsertPact5 mempool CheckedInsert [cmd1]
bipFinal <- throwIfNoHistory =<< continueBlock bipContinued pactQueue

-- We must make progress on the same parent header
Expand Down Expand Up @@ -263,7 +263,7 @@ newBlockTimeoutSpec baseRdb = runResourceT $ do
}

_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert5 mempool CheckedInsert [tx2, timeoutTx, tx1]
mempoolInsertPact5 mempool CheckedInsert [tx2, timeoutTx, tx1]
bip <- throwIfNotPact5 =<< throwIfNoHistory =<<
newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
-- Mempool orders by GasPrice. 'buildCwCmd' sets the gas price to the transfer amount.
Expand Down Expand Up @@ -325,13 +325,13 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do

let pact4Hash = Pact5.Hash . Pact4.unHash . Pact4.toUntypedHash . Pact4._cmdHash
_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert5 mempool CheckedInsert [regularTx1]
mempoolInsertPact5 mempool CheckedInsert [regularTx1]
bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
return $ finalizeBlock bip

_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert mempool UncheckedInsert $ Vector.fromList [badParse, badSigs]
mempoolInsert5 mempool UncheckedInsert [badChain, badUnique, badFuture, badPast, badTxHash]
mempoolInsertPact5 mempool UncheckedInsert [badChain, badUnique, badFuture, badPast, badTxHash]
bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
let expectedTxs = []
let actualTxs = Vector.toList $ Vector.map (unRequestKey . _crReqKey . snd) $ _transactionPairs $ _blockInProgressTransactions bip
Expand All @@ -342,7 +342,7 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do
-- to disappear, because only the parent block is used to find txs to
-- delete from the mempool
let mempool = _fixtureMempools fixture ^?! atChain chain0
mempoolInsert5 mempool CheckedInsert [badUnique, badFuture, badPast, badTxHash]
mempoolInsertPact5 mempool CheckedInsert [badUnique, badFuture, badPast, badTxHash]

let badTxHashes =
[ pact4Hash badParse
Expand All @@ -352,7 +352,7 @@ testNewBlockExcludesInvalid baseRdb = runResourceT $ do
, _cmdHash badTxHash
, pact4Hash badSigs
]
inMempool <- mempoolLookup5 mempool (Vector.fromList badTxHashes)
inMempool <- mempoolLookupPact5 mempool (Vector.fromList badTxHashes)
forM_ (zip [0 :: Word ..] badTxHashes) $ \(i, badHash) -> do
assertBool ("bad tx [index = " <> sshow i <> ", hash = " <> sshow badTxHash <> "] should have been evicted from the mempool") $ not $ HashSet.member badHash inMempool

Expand All @@ -367,7 +367,7 @@ lookupPactTxsSpec baseRdb = runResourceT $ do

-- Depth 0
_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert5 mempool CheckedInsert [cmd1, cmd2]
mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2]
bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
return $ finalizeBlock bip

Expand Down Expand Up @@ -418,7 +418,7 @@ failedTxsShouldGoIntoBlocks baseRdb = runResourceT $ do

-- Depth 0
_ <- advanceAllChains fixture $ onChain chain0 $ \ph pactQueue mempool -> do
mempoolInsert5 mempool CheckedInsert [cmd1, cmd2]
mempoolInsertPact5 mempool CheckedInsert [cmd1, cmd2]
bip <- throwIfNotPact5 =<< throwIfNoHistory =<< newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
let block = finalizeBlock bip
assertEqual "block has 2 txs even though one of them failed" 2 (Vector.length $ _payloadWithOutputsTransactions block)
Expand Down Expand Up @@ -460,7 +460,7 @@ advanceAllChainsWithTxs fixture txsPerChain =
advanceAllChains fixture $
txsPerChain <&> \txs ph pactQueue mempool -> do
mempoolClear mempool
mempoolInsert5 mempool CheckedInsert txs
mempoolInsertPact5 mempool CheckedInsert txs
nb <- throwIfNotPact5 =<< throwIfNoHistory =<<
newBlock noMiner NewBlockFill (ParentHeader ph) pactQueue
return $ finalizeBlock nb
Expand Down

0 comments on commit 8e0b6db

Please sign in to comment.