@@ -18,7 +18,7 @@ import Data.Text (Text)
18
18
19
19
import Ouroboros.Consensus.Cardano.Block hiding (CardanoBlock )
20
20
21
- import Ouroboros.Network.Block (blockNo , blockPoint , blockSlot )
21
+ import Ouroboros.Network.Block (blockNo , blockPoint , blockSlot , genesisPoint )
22
22
23
23
import qualified Cardano.Db as DB
24
24
@@ -80,6 +80,8 @@ unitTests iom knownMigrations =
80
80
, test " lazy rollback on restart" lazyRollbackRestart
81
81
, test " rollback while rollbacking" doubleRollback
82
82
, test " rollback stake address cache" stakeAddressRollback
83
+ , test " rollback change order of txs" rollbackChangeTxOrder
84
+ , test " rollback full tx" rollbackFullTx
83
85
]
84
86
, testGroup " different configs"
85
87
[ test " genesis config without pool" configNoPools
@@ -127,6 +129,7 @@ unitTests iom knownMigrations =
127
129
, test " failed script fees" failedScriptFees
128
130
, test " failed script in same block" failedScriptSameBlock
129
131
, test " multiple scripts unlocked" multipleScripts
132
+ , test " multiple scripts unlocked rollback" multipleScriptsRollback
130
133
, test " multiple scripts unlocked same block" multipleScriptsSameBlock
131
134
, test " multiple scripts failed" multipleScriptsFailed
132
135
, test " multiple scripts failed same block" multipleScriptsFailedSameBlock
@@ -158,6 +161,7 @@ unitTests iom knownMigrations =
158
161
, test " spend reference script" spendRefScript
159
162
, test " spend reference script same block" spendRefScriptSameBlock
160
163
, test " spend collateral output of invalid tx" spendCollateralOutput
164
+ , test " spend collateral output of invalid tx rollback" spendCollateralOutputRollback
161
165
, test " spend collateral output of invalid tx same block" spendCollateralOutputSameBlock
162
166
, test " reference input to output which is not spent" referenceInputUnspend
163
167
, test " supply and run script which is both reference and in witnesses" supplyScriptsTwoWays
@@ -441,6 +445,50 @@ stakeAddressRollback =
441
445
where
442
446
testLabel = " stakeAddressRollback"
443
447
448
+ rollbackChangeTxOrder :: IOManager -> [(Text , Text )] -> Assertion
449
+ rollbackChangeTxOrder =
450
+ withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
451
+ startDBSync dbSync
452
+ blk0 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
453
+ st <- getBabbageLedgerState interpreter
454
+ let Right tx0 = Babbage. mkPaymentTx (UTxOIndex 0 ) (UTxOIndex 1 ) 10000 500 st
455
+ let Right tx1 = Babbage. mkPaymentTx (UTxOIndex 2 ) (UTxOIndex 3 ) 10000 500 st
456
+ let Right tx2 = Babbage. mkPaymentTx (UTxOIndex 4 ) (UTxOIndex 5 ) 10000 500 st
457
+
458
+ void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \ _st ->
459
+ Right [tx0, tx1]
460
+ assertBlockNoBackoff dbSync 2
461
+ assertTxCount dbSync 13
462
+ rollbackTo interpreter mockServer $ blockPoint blk0
463
+ void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \ _st ->
464
+ Right [tx1, tx0, tx2]
465
+ assertBlockNoBackoff dbSync 2
466
+ assertTxCount dbSync 14
467
+ where
468
+ testLabel = " rollbackChangeTxOrder"
469
+
470
+ rollbackFullTx :: IOManager -> [(Text , Text )] -> Assertion
471
+ rollbackFullTx =
472
+ withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
473
+ startDBSync dbSync
474
+ blk0 <- forgeNextFindLeaderAndSubmit interpreter mockServer []
475
+ void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \ st -> do
476
+ tx0 <- Babbage. mkFullTx 0 100 st
477
+ tx1 <- Babbage. mkFullTx 1 200 st
478
+ pure [tx0, tx1]
479
+ assertBlockNoBackoff dbSync 2
480
+ assertTxCount dbSync 13
481
+ rollbackTo interpreter mockServer $ blockPoint blk0
482
+ void $ withBabbageFindLeaderAndSubmit interpreter mockServer $ \ st -> do
483
+ tx0 <- Babbage. mkFullTx 0 100 st
484
+ tx1 <- Babbage. mkFullTx 1 200 st
485
+ tx2 <- Babbage. mkFullTx 2 200 st
486
+ pure [tx1, tx2, tx0]
487
+ assertBlockNoBackoff dbSync 2
488
+ assertTxCount dbSync 14
489
+ where
490
+ testLabel = " rollbackFullTx"
491
+
444
492
configNoPools :: IOManager -> [(Text , Text )] -> Assertion
445
493
configNoPools =
446
494
withFullConfig " config2" testLabel $ \ _ _ dbSync -> do
@@ -1332,6 +1380,36 @@ multipleScripts =
1332
1380
where
1333
1381
testLabel = " multipleScripts"
1334
1382
1383
+ multipleScriptsRollback :: IOManager -> [(Text , Text )] -> Assertion
1384
+ multipleScriptsRollback =
1385
+ withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
1386
+ startDBSync dbSync
1387
+
1388
+ tx0 <- withBabbageLedgerState interpreter $ Babbage. mkLockByScriptTx (UTxOIndex 0 ) (Babbage. TxOutNoInline <$> [True , False , True ]) 20000 20000
1389
+ let utxo = Babbage. mkUTxOBabbage tx0
1390
+ pair1 = head utxo
1391
+ pair2 = utxo !! 2
1392
+ tx1 <- withBabbageLedgerState interpreter $
1393
+ Babbage. mkUnlockScriptTx [UTxOPair pair1, UTxOPair pair2] (UTxOIndex 1 ) (UTxOIndex 2 ) True 10000 500
1394
+
1395
+ void $ forgeNextAndSubmit interpreter mockServer $ MockBlock [TxBabbage tx0] (NodeId 1 )
1396
+ void $ forgeNextAndSubmit interpreter mockServer $ MockBlock [TxBabbage tx1] (NodeId 1 )
1397
+
1398
+ assertBlockNoBackoff dbSync 2
1399
+ assertAlonzoCounts dbSync (1 ,2 ,1 ,1 ,3 ,2 ,0 ,0 )
1400
+
1401
+ rollbackTo interpreter mockServer genesisPoint
1402
+ void $ forgeNextFindLeaderAndSubmit interpreter mockServer []
1403
+
1404
+ void $ forgeNextAndSubmit interpreter mockServer $ MockBlock [TxBabbage tx0] (NodeId 1 )
1405
+ void $ forgeNextAndSubmit interpreter mockServer $ MockBlock [TxBabbage tx1] (NodeId 1 )
1406
+ assertBlockNoBackoff dbSync 3
1407
+
1408
+ assertAlonzoCounts dbSync (1 ,2 ,1 ,1 ,3 ,2 ,0 ,0 )
1409
+ where
1410
+ testLabel = " multipleScriptsRollback"
1411
+
1412
+
1335
1413
multipleScriptsSameBlock :: IOManager -> [(Text , Text )] -> Assertion
1336
1414
multipleScriptsSameBlock =
1337
1415
withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
@@ -1891,6 +1969,38 @@ spendCollateralOutput =
1891
1969
where
1892
1970
testLabel = " spendCollateralOutput"
1893
1971
1972
+ spendCollateralOutputRollback :: IOManager -> [(Text , Text )] -> Assertion
1973
+ spendCollateralOutputRollback =
1974
+ withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
1975
+ startDBSync dbSync
1976
+ blk0 <- registerAllStakeCreds interpreter mockServer
1977
+ action interpreter mockServer dbSync 0
1978
+ rollbackTo interpreter mockServer (blockPoint blk0)
1979
+ void $ forgeNextFindLeaderAndSubmit interpreter mockServer []
1980
+ action interpreter mockServer dbSync 1
1981
+ where
1982
+ testLabel = " spendCollateralOutputRollback"
1983
+ action interpreter mockServer dbSync n = do
1984
+
1985
+ tx0 <- withBabbageLedgerState interpreter
1986
+ $ Babbage. mkLockByScriptTx (UTxOIndex 0 ) [Babbage. TxOutNoInline False ] 20000 20000
1987
+ void $ forgeNextFindLeaderAndSubmit interpreter mockServer [TxBabbage tx0]
1988
+
1989
+ -- tx fails so its collateral output become actual output.
1990
+ let utxo0 = head (Babbage. mkUTxOBabbage tx0)
1991
+ tx1 <- withBabbageLedgerState interpreter $
1992
+ Babbage. mkUnlockScriptTxBabbage [UTxOInput (fst utxo0)] (UTxOIndex 1 ) (UTxOIndex 2 ) [UTxOPair utxo0] True False 10000 500
1993
+ void $ forgeNextFindLeaderAndSubmit interpreter mockServer [TxBabbage tx1]
1994
+ assertBlockNoBackoff dbSync $ n + 3
1995
+
1996
+ let utxo1 = head (Babbage. mkUTxOCollBabbage tx1)
1997
+ tx2 <- withBabbageLedgerState interpreter $
1998
+ Babbage. mkUnlockScriptTxBabbage [UTxOPair utxo1] (UTxOIndex 3 ) (UTxOIndex 1 ) [UTxOPair utxo1] False True 10000 500
1999
+ void $ forgeNextFindLeaderAndSubmit interpreter mockServer [TxBabbage tx2]
2000
+
2001
+ assertBlockNoBackoff dbSync $ n + 4
2002
+ assertBabbageCounts dbSync (1 ,1 ,1 ,1 ,2 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 )
2003
+
1894
2004
spendCollateralOutputSameBlock :: IOManager -> [(Text , Text )] -> Assertion
1895
2005
spendCollateralOutputSameBlock =
1896
2006
withFullConfig babbageConfig testLabel $ \ interpreter mockServer dbSync -> do
0 commit comments