Skip to content

Commit e3652bd

Browse files
committed
add interface tests and fix behaviour
1 parent ab70beb commit e3652bd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

x/blockdb/database.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (s *Database) Close() error {
303303
defer s.closeMu.Unlock()
304304

305305
if s.closed {
306-
return nil
306+
return database.ErrClosed
307307
}
308308
s.closed = true
309309

@@ -524,6 +524,10 @@ func (s *Database) Get(height BlockHeight) (BlockData, error) {
524524
return nil, fmt.Errorf("checksum mismatch: calculated %d, stored %d", calculatedChecksum, bh.Checksum)
525525
}
526526

527+
if len(decompressed) == 0 {
528+
return nil, nil
529+
}
530+
527531
return decompressed, nil
528532
}
529533

x/blockdb/database_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,25 @@ import (
1818
"github.com/stretchr/testify/require"
1919

2020
"github.com/ava-labs/avalanchego/cache/lru"
21+
"github.com/ava-labs/avalanchego/database"
22+
"github.com/ava-labs/avalanchego/database/heightindexdb/dbtest"
2123
"github.com/ava-labs/avalanchego/utils/compression"
2224
"github.com/ava-labs/avalanchego/utils/logging"
2325
)
2426

27+
func TestInterface(t *testing.T) {
28+
for name, test := range dbtest.Tests {
29+
t.Run(name, func(t *testing.T) {
30+
test(t, func() database.HeightIndex {
31+
tempDir := t.TempDir()
32+
db, err := New(DefaultConfig().WithDir(tempDir), logging.NoLog{})
33+
require.NoError(t, err)
34+
return db
35+
})
36+
})
37+
}
38+
}
39+
2540
func TestNew_Params(t *testing.T) {
2641
tempDir := t.TempDir()
2742
tests := []struct {

0 commit comments

Comments
 (0)