Skip to content

Commit

Permalink
Update regression
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Sep 4, 2024
1 parent a3dd6b5 commit 3ec69ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pact/Pact/Core/Persistence/MockPersistence.hs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mockPactDb serial = do
writeIORef ptRollbackState Nothing
txId <- atomicModifyIORef' ptTxId (\(TxId i) -> (TxId (succ i), TxId i))
txLogQueue <- readIORef ptTxLogQueue
pure (M.findWithDefault [] txId txLogQueue)
pure $ reverse $ M.findWithDefault [] txId txLogQueue
Local -> do
-- in local, we simply roll back all tables
-- then and return the logs, then roll back the logs table
Expand Down Expand Up @@ -375,4 +375,4 @@ rightToMaybe = \case
record :: PactTables b i -> TxLog ByteString -> IO ()
record PactTables{..} entry = do
txIdNow <- readIORef ptTxId
modifyIORef ptTxLogQueue $ \txMap -> M.insertWith (<>) txIdNow [entry] txMap
modifyIORef ptTxLogQueue (M.insertWith (<>) txIdNow [entry])
3 changes: 2 additions & 1 deletion pact/Pact/Core/Persistence/SQLite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ commitTx :: IORef TxId -> SQL.Database -> IORef [TxLog ByteString] -> IO [TxLog
commitTx txid db txLog = do
_ <- atomicModifyIORef' txid (\old@(TxId n) -> (TxId (succ n), old))
SQL.exec db "COMMIT TRANSACTION"
readIORef txLog
txls <- atomicModifyIORef' txLog ([],)
pure $ reverse txls

beginTx :: IORef TxId -> SQL.Database -> IORef [TxLog ByteString] -> ExecutionMode -> IO (Maybe TxId)
beginTx txid db txLog em = do
Expand Down
26 changes: 14 additions & 12 deletions test-utils/Pact/Core/PactDbRegression.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ runPactDbRegression pdb = do
assertEqual "module should be identical to its saved/recalled value" md md'

txs2 <- _pdbCommitTx pdb
-- Tx logs should be emitted in order
flip (assertEqual "output of commit") txs2
[ TxLog "SYS:Modules" "test" mdEnc
, TxLog "SYS:KeySets" "ks1" ksEnc
[ TxLog "USER_someModule_user1" "key1" rowEnc
, TxLog "USER_someModule_user1" "key1" row2Enc
, TxLog "USER_someModule_user1" "key1" rowEnc
, TxLog "SYS:KeySets" "ks1" ksEnc
, TxLog "SYS:Modules" "test" mdEnc
]

-- begin tx
Expand All @@ -101,19 +102,20 @@ runPactDbRegression pdb = do
Just r -> pure r
assertEqual "user insert key2 pre-rollback" row r1

do
rkeys <- ignoreGas def $ _pdbKeys pdb (DUserTables usert)
assertEqual "keys pre-rollback [key1, key2]" [RowKey "key1", RowKey "key2"] rkeys
rkeys <- ignoreGas def $ _pdbKeys pdb (DUserTables usert)
assertEqual "keys pre-rollback [key1, key2]" [RowKey "key1", RowKey "key2"] rkeys

_pdbRollbackTx pdb
_ <- _pdbBeginTx pdb Transactional
r2 <- ignoreGas def $ _pdbRead pdb (DUserTables usert) (RowKey "key2")
assertEqual "rollback erases key2" Nothing r2
-- Roll back tx2
_pdbRollbackTx pdb

rkeys2 <- ignoreGas def $ _pdbKeys pdb (DUserTables usert)
assertEqual "keys post-rollback [key1]" [RowKey "key1"] rkeys2
_ <- _pdbBeginTx pdb Transactional
r2 <- ignoreGas def $ _pdbRead pdb (DUserTables usert) (RowKey "key2")
assertEqual "rollback erases key2" Nothing r2

rkeys2 <- ignoreGas def $ _pdbKeys pdb (DUserTables usert)
assertEqual "keys post-rollback [key1]" [RowKey "key1"] rkeys2
_ <- _pdbCommitTx pdb

return ()


Expand Down

0 comments on commit 3ec69ff

Please sign in to comment.