Skip to content

Commit 542198e

Browse files
authored
Merge pull request #1429 from input-output-hk/1417-txout-migration-tests
Test new tx-out feature flags
2 parents 4b32365 + b6a937c commit 542198e

20 files changed

+433
-36
lines changed

cardano-chain-gen/cardano-chain-gen.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ test-suite cardano-chain-gen
165165
Test.Cardano.Db.Mock.Unit.Alonzo.Stake
166166
Test.Cardano.Db.Mock.Unit.Alonzo.Tx
167167
Test.Cardano.Db.Mock.Unit.Babbage
168-
Test.Cardano.Db.Mock.Unit.Babbage.Other
168+
Test.Cardano.Db.Mock.Unit.Babbage.Flag.ConsumedTxOut
169169
Test.Cardano.Db.Mock.Unit.Babbage.InlineAndReference
170+
Test.Cardano.Db.Mock.Unit.Babbage.Other
170171
Test.Cardano.Db.Mock.Unit.Babbage.Plutus
171172
Test.Cardano.Db.Mock.Unit.Babbage.Reward
172173
Test.Cardano.Db.Mock.Unit.Babbage.Rollback

cardano-chain-gen/test/Test/Cardano/Db/Mock/Config.hs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
module Test.Cardano.Db.Mock.Config (
66
Config (..),
77
DBSyncEnv (..),
8+
TxOutParam(..),
89
babbageConfigDir,
910
alonzoConfigDir,
1011
emptyMetricsSetters,
@@ -29,6 +30,7 @@ module Test.Cardano.Db.Mock.Config (
2930
startDBSync,
3031
withDBSyncEnv,
3132
withFullConfig,
33+
withTxOutParamConfig,
3234
withFullConfig',
3335
) where
3436

@@ -89,6 +91,12 @@ data DBSyncEnv = DBSyncEnv
8991
, dbSyncThreadVar :: TMVar (Async ())
9092
}
9193

94+
-- used for testing of tx out pruning feature
95+
data TxOutParam = TxOutParam
96+
{ paramMigrateConsumed :: Bool,
97+
paramPruneTxOut :: Bool
98+
}
99+
92100
babbageConfigDir :: FilePath
93101
babbageConfigDir = "config"
94102

@@ -195,14 +203,14 @@ setupTestsDir dir = do
195203
0
196204
Nothing
197205

198-
mkConfig :: FilePath -> FilePath -> IO Config
199-
mkConfig staticDir mutableDir = do
206+
mkConfig :: FilePath -> FilePath -> Maybe TxOutParam -> IO Config
207+
mkConfig staticDir mutableDir mTxOutParam = do
200208
config <- readSyncNodeConfig $ ConfigFile (staticDir </> "test-db-sync-config.json")
201209
genCfg <- either (error . Text.unpack . renderSyncNodeError) id <$> runExceptT (readCardanoGenesisConfig config)
202210
let pInfoDbSync = mkProtocolInfoCardano genCfg []
203211
creds <- mkShelleyCredentials $ staticDir </> "pools" </> "bulk1.creds"
204212
let pInfoForger = mkProtocolInfoCardano genCfg creds
205-
syncPars <- mkSyncNodeParams staticDir mutableDir
213+
syncPars <- mkSyncNodeParams staticDir mutableDir mTxOutParam
206214
pure $ Config (Consensus.pInfoConfig pInfoDbSync) pInfoDbSync pInfoForger syncPars
207215

208216
mkShelleyCredentials :: FilePath -> IO [ShelleyLeaderCredentials StandardCrypto]
@@ -220,8 +228,8 @@ mkShelleyCredentials bulkFile = do
220228
}
221229

222230
-- | staticDir can be shared by tests running in parallel. mutableDir not.
223-
mkSyncNodeParams :: FilePath -> FilePath -> IO SyncNodeParams
224-
mkSyncNodeParams staticDir mutableDir = do
231+
mkSyncNodeParams :: FilePath -> FilePath -> Maybe TxOutParam -> IO SyncNodeParams
232+
mkSyncNodeParams staticDir mutableDir mTxOutParam = do
225233
pgconfig <- orDie Db.renderPGPassError $ newExceptT Db.readPGPassDefault
226234
pure $
227235
SyncNodeParams
@@ -242,8 +250,8 @@ mkSyncNodeParams staticDir mutableDir = do
242250
, enpHasOfflineData = True
243251
, enpTurboMode = False
244252
, enpFullMode = True
245-
, enpMigrateConsumed = False
246-
, enpPruneTxOut = False
253+
, enpMigrateConsumed = maybe False paramMigrateConsumed mTxOutParam
254+
, enpPruneTxOut = maybe False paramPruneTxOut mTxOutParam
247255
, enpSnEveryFollowing = 35
248256
, enpSnEveryLagging = 35
249257
, enpMaybeRollback = Nothing
@@ -265,19 +273,30 @@ withFullConfig ::
265273
IOManager ->
266274
[(Text, Text)] ->
267275
IO a
268-
withFullConfig = withFullConfig' True
276+
withFullConfig = withFullConfig' True Nothing
277+
278+
withTxOutParamConfig ::
279+
TxOutParam ->
280+
FilePath ->
281+
FilePath ->
282+
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a) ->
283+
IOManager ->
284+
[(Text, Text)] ->
285+
IO a
286+
withTxOutParamConfig txOutParam = withFullConfig' True (Just txOutParam)
269287

270288
withFullConfig' ::
271289
Bool ->
290+
Maybe TxOutParam ->
272291
FilePath ->
273292
FilePath ->
274293
(Interpreter -> ServerHandle IO CardanoBlock -> DBSyncEnv -> IO a) ->
275294
IOManager ->
276295
[(Text, Text)] ->
277296
IO a
278-
withFullConfig' hasFingerprint config testLabel action iom migr = do
297+
withFullConfig' hasFingerprint mTxOutParam config testLabel action iom migr = do
279298
recreateDir mutableDir
280-
cfg <- mkConfig configDir mutableDir
299+
cfg <- mkConfig configDir mutableDir mTxOutParam
281300
fingerFile <- if hasFingerprint then Just <$> prepareFingerprintFile testLabel else pure Nothing
282301
let dbsyncParams = syncNodeParams cfg
283302
-- Set to True to disable logging, False to enable it.

cardano-chain-gen/test/Test/Cardano/Db/Mock/Property/Property.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,4 @@ prop_empty_blocks iom knownMigrations = withMaxSuccess 20 $ noShrinking $ forAll
273273
prettyCommands smSymbolic hist (checkCommandNames cmds (res === Ok))
274274
where
275275
smSymbolic = sm (error "inter") (error "mockServer") (error "dbSync")
276-
runAction action = withFullConfig' False "config" "qsm" action iom knownMigrations
276+
runAction action = withFullConfig' False Nothing "config" "qsm" action iom knownMigrations

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Alonzo/Tx.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,18 @@ module Test.Cardano.Db.Mock.Unit.Alonzo.Tx (
55

66
import Cardano.Mock.ChainSync.Server (IOManager)
77
import qualified Cardano.Mock.Forging.Tx.Alonzo as Alonzo
8-
import Cardano.Mock.Forging.Types (UTxOIndex (UTxOIndex, UTxOPair))
8+
import Cardano.Mock.Forging.Types (UTxOIndex (..))
99
import Control.Monad (void)
1010
import Data.Text (Text)
11-
import Test.Cardano.Db.Mock.Config (alonzoConfigDir, startDBSync, withFullConfig)
12-
import Test.Cardano.Db.Mock.UnifiedApi (withAlonzoFindLeaderAndSubmit, withAlonzoFindLeaderAndSubmitTx)
11+
import Test.Cardano.Db.Mock.Config (
12+
alonzoConfigDir,
13+
startDBSync,
14+
withFullConfig,
15+
)
16+
import Test.Cardano.Db.Mock.UnifiedApi (
17+
withAlonzoFindLeaderAndSubmit,
18+
withAlonzoFindLeaderAndSubmitTx,
19+
)
1320
import Test.Cardano.Db.Mock.Validate (assertBlockNoBackoff)
1421
import Test.Tasty.HUnit (Assertion)
1522

cardano-chain-gen/test/Test/Cardano/Db/Mock/Unit/Babbage.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Data.Text (Text)
1111
import Test.Tasty (TestTree, testGroup)
1212
import Test.Tasty.HUnit (Assertion, testCase)
1313

14+
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Flag.ConsumedTxOut as FlagConsumedTxOut
1415
import qualified Test.Cardano.Db.Mock.Unit.Babbage.InlineAndReference as BabInlineRef
1516
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Other as BabOther
1617
import qualified Test.Cardano.Db.Mock.Unit.Babbage.Plutus as BabPlutus
@@ -33,6 +34,21 @@ unitTests iom knownMigrations =
3334
, test "node restart" BabSimple.nodeRestart
3435
, test "node restart boundary" BabSimple.nodeRestartBoundary
3536
]
37+
, testGroup
38+
"flags"
39+
[ testGroup
40+
"consumed-tx-out"
41+
[ test "flag check" FlagConsumedTxOut.flagCheck
42+
, test "basic prune" FlagConsumedTxOut.basicPrune
43+
, test "prune with simple rollback" FlagConsumedTxOut.pruneWithSimpleRollback
44+
, test "prune with full tx rollback" FlagConsumedTxOut.pruneWithFullTxRollback
45+
, test "pruning should keep some tx" FlagConsumedTxOut.pruningShouldKeepSomeTx
46+
, test "prune and rollback one block" FlagConsumedTxOut.pruneAndRollBackOneBlock
47+
, test "no pruning and rollback" FlagConsumedTxOut.noPruneAndRollBack
48+
, test "prune same block" FlagConsumedTxOut.pruneSameBlock
49+
, test "no pruning same block" FlagConsumedTxOut.noPruneSameBlock
50+
]
51+
]
3652
, testGroup
3753
"rollbacks"
3854
[ test "simple rollback" BabRollback.simpleRollback

0 commit comments

Comments
 (0)