diff --git a/db/bbolt.go b/db/bbolt.go index 9fd7555..36ebd42 100644 --- a/db/bbolt.go +++ b/db/bbolt.go @@ -217,6 +217,7 @@ func (bb *BBoltHandler) GetLatestBlock() (*types.Block, error) { func (bb *BBoltHandler) DeleteDB() error { absPath, err := filepath.Abs(bb.db.Path()) + bb.logger.Info("Deleting DB", zap.String("path", absPath)) if err != nil { bb.logger.Error("Error getting db absolute path", zap.Error(err)) return fmt.Errorf("failed to get db absolute path: %w", err) diff --git a/db/bbolt_test.go b/db/bbolt_test.go index 6587116..3bfadb7 100644 --- a/db/bbolt_test.go +++ b/db/bbolt_test.go @@ -37,8 +37,11 @@ func setupDB(t *testing.T) (*BBoltHandler, func()) { // Cleanup function to close DB and remove temp file cleanup := func() { + err := db.DeleteDB() + if err != nil { + t.Fatalf("Failed to delete DB: %v", err) + } db.Close() - db.DeleteDB() } return db, cleanup diff --git a/finalitygadget/finalitygadget.go b/finalitygadget/finalitygadget.go index f885d53..b191509 100644 --- a/finalitygadget/finalitygadget.go +++ b/finalitygadget/finalitygadget.go @@ -33,13 +33,12 @@ type FinalityGadget struct { cwClient cwclient.ICosmWasmClient l2Client ethl2client.IEthL2Client - db db.IDatabaseHandler - mutex sync.Mutex + db db.IDatabaseHandler + logger *zap.Logger + mutex sync.Mutex pollInterval time.Duration currHeight uint64 - - logger *zap.Logger } ////////////////////////////// diff --git a/finalitygadget/finalitygadget_test.go b/finalitygadget/finalitygadget_test.go index cede930..40b1c49 100644 --- a/finalitygadget/finalitygadget_test.go +++ b/finalitygadget/finalitygadget_test.go @@ -428,16 +428,12 @@ func TestGetBlockByHashForNonExistentBlock(t *testing.T) { } func TestGetBlockStatusByHeight(t *testing.T) { - block := &types.Block{ - BlockHeight: 1, - BlockHash: "0x123", - BlockTimestamp: 1000, - } + blockHeight := uint64(1) // mock db and finality gadget ctl := gomock.NewController(t) mockDbHandler := mocks.NewMockIDatabaseHandler(ctl) - mockDbHandler.EXPECT().GetBlockStatusByHeight(block.BlockHeight).Return(true, nil).Times(1) + mockDbHandler.EXPECT().GetBlockStatusByHeight(blockHeight).Return(true, nil).Times(1) mockFinalityGadget := &FinalityGadget{ db: mockDbHandler,