@@ -15,6 +15,7 @@ import Data.Either (isRight)
1515import Data.FingerTree (Measured (.. ))
1616import Data.Foldable (fold , toList )
1717import Data.List (nub , sort )
18+ import qualified Data.Map as Map
1819import qualified Data.Set as Set
1920import qualified Generators as Gen
2021import Hedgehog (Property , annotateShow , assert , failure , forAll , property , (===) )
@@ -24,7 +25,8 @@ import qualified Plutus.ChainIndex.Emulator.DiskState as DiskState
2425import Plutus.ChainIndex.Tx (citxTxId , txOutsWithRef )
2526import Plutus.ChainIndex.TxIdState (increaseDepth , transactionStatus )
2627import qualified Plutus.ChainIndex.TxIdState as TxIdState
27- import Plutus.ChainIndex.Types (BlockNumber (.. ), Depth (.. ), Tip (.. ), TxStatus (.. ),
28+ import Plutus.ChainIndex.Types (BlockNumber (.. ), Depth (.. ), Tip (.. ), TxConfirmedState (.. ),
29+ TxIdState (.. ), TxStatus (.. ), TxStatusFailure (.. ),
2830 TxValidity (.. ), tipAsPoint )
2931import Plutus.ChainIndex.UtxoState (InsertUtxoSuccess (.. ), RollbackResult (.. ), TxUtxoBalance (.. ))
3032import qualified Plutus.ChainIndex.UtxoState as UtxoState
@@ -97,13 +99,37 @@ rollbackTxIdState = property $ do
9799 Right s4 = UtxoState. insert (UtxoState. UtxoState (TxIdState. fromTx (BlockNumber 2 ) txB) tipB) f3
98100 f4 = newIndex s4
99101
100- status2 = transactionStatus (BlockNumber 1 ) (getState f2) (txB ^. citxTxId)
101- status3 = transactionStatus (BlockNumber 2 ) (getState f3) (txB ^. citxTxId)
102- status4 = transactionStatus (BlockNumber 3 ) (getState f4) (txB ^. citxTxId)
103-
104- status2 === (Right $ TentativelyConfirmed (Depth 0 ) TxValid )
105- status3 === (Right $ Unknown )
106- status4 === (Right $ TentativelyConfirmed (Depth 1 ) TxValid )
102+ let confirmed tx txIdState = (timesConfirmed <$> ( Map. lookup (tx ^. citxTxId) $ txnsConfirmed $ getState txIdState))
103+ deleted tx txIdState = (Map. lookup (tx ^. citxTxId) $ txnsDeleted $ getState txIdState)
104+ status bn tx txIdState = transactionStatus (BlockNumber bn) (getState txIdState) (tx ^. citxTxId)
105+
106+ isInvalidRollback (Left (InvalidRollbackAttempt _ _ _)) = True
107+ isInvalidRollback _ = False
108+
109+ -- It's inserted at f2, and is confirmed once and not deleted, resulting
110+ -- in a tentatively-confirmed status.
111+ confirmed txB f2 === Just 1
112+ deleted txB f2 === Nothing
113+ status 1 txB f2 === (Right $ TentativelyConfirmed (Depth 0 ) TxValid )
114+
115+ -- At f3, it's deleted once, and confirmed once, resulting in an unknown
116+ -- status.
117+ confirmed txB f3 === Just 1
118+ deleted txB f3 === Just 1
119+ status 2 txB f3 === (Right $ Unknown )
120+
121+ -- If we check the status far into the future, this should be an error, as
122+ -- we're trying to rollback something that is committed.
123+ isInvalidRollback (status 100 txB f3) === True
124+
125+ -- At f4, it's confirmed twice, and deleted once, resulting in a
126+ -- tentatively-confirmed status again.
127+ confirmed txB f4 === Just 2
128+ deleted txB f4 === Just 1
129+ status 3 txB f4 === (Right $ TentativelyConfirmed (Depth 1 ) TxValid )
130+
131+ -- Much later, it should be committed.
132+ status 100 txB f4 === Right (Committed TxValid )
107133
108134transactionDepthIncreases :: Property
109135transactionDepthIncreases = property $ do
0 commit comments