Skip to content

Commit 4461ccf

Browse files
committed
add tests for basic write values
1 parent 49c88a7 commit 4461ccf

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

x/blockdb/readblock_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestHasBlock(t *testing.T) {
263263
{
264264
name: "db_closed",
265265
dbClosed: true,
266-
wantErr: ErrDatabaseClosed,
266+
wantErr: database.ErrClosed,
267267
},
268268
}
269269

@@ -276,14 +276,14 @@ func TestHasBlock(t *testing.T) {
276276
if i == gapHeight {
277277
continue
278278
}
279-
require.NoError(t, store.WriteBlock(i, randomBlock(t)))
279+
require.NoError(t, store.Put(i, randomBlock(t)))
280280
}
281281

282282
if tc.dbClosed {
283283
require.NoError(t, store.Close())
284284
}
285285

286-
has, err := store.HasBlock(tc.height)
286+
has, err := store.Has(tc.height)
287287
if tc.wantErr != nil {
288288
require.ErrorIs(t, err, tc.wantErr)
289289
} else {

x/blockdb/writeblock_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,41 @@ import (
2020
)
2121

2222
func TestWriteBlock_Basic(t *testing.T) {
23+
tests := []struct {
24+
name string
25+
block []byte
26+
want []byte
27+
}{
28+
{
29+
name: "normal write",
30+
block: []byte("hello"),
31+
want: []byte("hello"),
32+
},
33+
{
34+
name: "empty block",
35+
block: []byte{},
36+
want: []byte{},
37+
},
38+
{
39+
name: "nil block",
40+
block: nil,
41+
want: []byte{},
42+
},
43+
}
44+
for _, tt := range tests {
45+
t.Run(tt.name, func(t *testing.T) {
46+
db, cleanup := newTestDatabase(t, DefaultConfig())
47+
defer cleanup()
48+
require.NoError(t, db.Put(0, tt.block))
49+
50+
got, err := db.Get(0)
51+
require.NoError(t, err)
52+
require.Equal(t, tt.want, got)
53+
})
54+
}
55+
}
56+
57+
func TestWriteBlock_MaxHeight(t *testing.T) {
2358
customConfig := DefaultConfig().WithMinimumHeight(10)
2459

2560
tests := []struct {

0 commit comments

Comments
 (0)