@@ -13,6 +13,7 @@ func TestChainstateManager(t *testing.T) {
1313
1414 t .Run ("genesis validation" , suite .TestGenesis )
1515 t .Run ("tip validation" , suite .TestTip )
16+ t .Run ("block undo" , suite .TestBlockUndo )
1617}
1718
1819func (s * ChainstateManagerTestSuite ) TestGenesis (t * testing.T ) {
@@ -67,6 +68,44 @@ func (s *ChainstateManagerTestSuite) TestTip(t *testing.T) {
6768 }
6869}
6970
71+ func (s * ChainstateManagerTestSuite ) TestBlockUndo (t * testing.T ) {
72+ blockIndex , err := s .Manager .GetBlockIndexFromHeight (202 )
73+ if err != nil {
74+ t .Fatalf ("GetBlockIndexFromHeight(202) error = %v" , err )
75+ }
76+ defer blockIndex .Destroy ()
77+
78+ blockUndo , err := s .Manager .ReadBlockUndoFromDisk (blockIndex )
79+ if err != nil {
80+ t .Fatalf ("ReadBlockUndoFromDisk() error = %v" , err )
81+ }
82+ defer blockUndo .Destroy ()
83+
84+ // Test transaction count
85+ txCount := blockUndo .Size ()
86+ if txCount != 20 {
87+ t .Errorf ("Expected 20 transactions, got %d" , txCount )
88+ }
89+
90+ // Verify each transaction is a valid TransactionUndo
91+ for i := uint64 (0 ); i < txCount ; i ++ {
92+ undoSize := blockUndo .GetTransactionUndoSize (i )
93+ if undoSize != 1 {
94+ t .Errorf ("Expected transaction undo size 1, got %d" , undoSize )
95+ }
96+
97+ _ , err := blockUndo .GetUndoOutputByIndex (i , 0 )
98+ if err != nil {
99+ t .Fatalf ("GetUndoOutputByIndex() error = %v" , err )
100+ }
101+
102+ height := blockUndo .GetUndoOutputHeightByIndex (i , 0 )
103+ if height <= 0 {
104+ t .Fatalf ("GetUndoOutputHeightByIndex() height %d, want > 0" , height )
105+ }
106+ }
107+ }
108+
70109type ChainstateManagerTestSuite struct {
71110 Manager * ChainstateManager
72111 ImportedBlocksCount int32
0 commit comments