Skip to content

Commit

Permalink
tx_out are pruned on new epoch test
Browse files Browse the repository at this point in the history
  • Loading branch information
Cmdv committed Jun 2, 2023
1 parent ac2fda1 commit d248368
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Expand Up @@ -57,6 +57,7 @@ unitTests iom knownMigrations =
, test "simple tx in Shelley era" BabTx.addSimpleTxShelley
, test "consume utxo same block" BabTx.consumeSameBlock
, test "migrate to consume tx-out" BabTx.isConsumeTxOutMigrated
, test "prune tx-out when correct config" BabTx.pruneTxoutWhenFlagActive
]
, testGroup
"stake addresses"
Expand Down
49 changes: 41 additions & 8 deletions cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage/Tx.hs
Expand Up @@ -3,6 +3,7 @@ module Test.Cardano.Db.Mock.Unit.Babbage.Tx (
addSimpleTxShelley,
consumeSameBlock,
isConsumeTxOutMigrated,
pruneTxoutWhenFlagActive,
) where

import Cardano.Mock.ChainSync.Server (IOManager)
Expand All @@ -15,11 +16,11 @@ import Test.Cardano.Db.Mock.Config (babbageConfigDir, startDBSync, withFullConfi
import Test.Cardano.Db.Mock.UnifiedApi (
withBabbageFindLeaderAndSubmit,
withBabbageFindLeaderAndSubmitTx,
withShelleyFindLeaderAndSubmitTx,
withShelleyFindLeaderAndSubmitTx, fillUntilNextEpoch, fillEpochPercentage,
)
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff, assertEqQuery)
import Test.Tasty.HUnit (Assertion)
import Cardano.Db (isMigrated)
import qualified Cardano.Db as DB

addSimpleTx :: IOManager -> [(Text, Text)] -> Assertion
addSimpleTx =
Expand Down Expand Up @@ -70,12 +71,44 @@ isConsumeTxOutMigrated = do
paramPruneTxOut = False
}
withTxOutParamConfig txOutParam babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do
-- translate the block to a real Cardano block.
void $
withBabbageFindLeaderAndSubmitTx interpreter mockServer $
Babbage.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10000 500
void $ withBabbageFindLeaderAndSubmitTx interpreter mockServer $
Babbage.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10000 500

startDBSync dbSync
assertBlockNoBackoff dbSync 1
assertEqQuery dbSync DB.isMigrated True "missing consumed_by_tx_in_id column when flag --consumed-tx-out active"
where
testLabel = "isConsumeTxOutMigrated"

pruneTxoutWhenFlagActive :: IOManager -> [(Text, Text)] -> Assertion
pruneTxoutWhenFlagActive = do
let txOutParam =
TxOutParam
{ paramMigrateConsumed = True,
paramPruneTxOut = True
}
withTxOutParamConfig txOutParam babbageConfigDir testLabel $ \interpreter mockServer dbSync -> do

startDBSync dbSync
assertEqQuery dbSync isMigrated False "missing consumed_by_tx_in_id column when flag migrate consume active"
-- fill in some blocks
b1 <- fillEpochPercentage interpreter mockServer 50

void $ withBabbageFindLeaderAndSubmitTx interpreter mockServer $ Babbage.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 10000 10000
void $ withBabbageFindLeaderAndSubmitTx interpreter mockServer $ Babbage.mkPaymentTx (UTxOIndex 1) (UTxOIndex 0) 10000 10000

-- add a couple of transactions
-- void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \st -> do
-- tx0 <- Babbage.mkPaymentTx (UTxOIndex 0) (UTxOIndex 1) 20000 20000 st
-- let utxo0 = head (Babbage.mkUTxOBabbage tx0)
-- tx1 <- Babbage.mkPaymentTx (UTxOPair utxo0) (UTxOIndex 2) 10000 500 st
-- pure [tx0, tx1]

-- add more blocks to
b2 <- fillUntilNextEpoch interpreter mockServer
assertBlockNoBackoff dbSync (fromIntegral $ length (b1 <> b2) + 2)
assertEqQuery dbSync DB.isMigrated True "missing consumed_by_tx_in_id column when flag --consumed-tx-out active"
-- check that the tx_out rows with consumed_by_tx_in_id = null are removed and there should just be 2 rows?
assertEqQuery dbSync DB.queryTxOutCount 2 "new epoch didn't prune tx_out columd that are null"

where
testLabel = "migrateConsumeTx"
testLabel = "pruneTxoutWhenFlagActive"

0 comments on commit d248368

Please sign in to comment.