Skip to content

Commit 77672f5

Browse files
authored
fix(headertest): correctly initialize Tail (#308)
Previously, TailHeight would stay 1 when the Generator starts from >1 height.
1 parent 1d53f9f commit 77672f5

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

headertest/store.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,14 @@ func NewDummyStore(t *testing.T) *Store[*DummyHeader] {
2727
// NewStore creates a generic mock store supporting different type of Headers based on Generator.
2828
func NewStore[H header.Header[H]](_ *testing.T, gen Generator[H], numHeaders int) *Store[H] {
2929
store := &Store[H]{
30-
Headers: make(map[uint64]H),
31-
HeadHeight: 1,
32-
TailHeight: 1,
30+
Headers: make(map[uint64]H),
3331
}
3432

35-
for i := 0; i < numHeaders; i++ {
36-
header := gen.NextHeader()
37-
store.Headers[header.Height()] = header
38-
39-
if header.Height() > store.HeadHeight {
40-
store.HeadHeight = header.Height()
41-
}
33+
for range numHeaders {
34+
h := gen.NextHeader()
35+
_ = store.Append(context.Background(), h)
4236
}
37+
4338
return store
4439
}
4540

@@ -134,7 +129,7 @@ func (m *Store[H]) Append(_ context.Context, headers ...H) error {
134129
if height > m.HeadHeight {
135130
m.HeadHeight = height
136131
}
137-
if height < m.TailHeight {
132+
if height < m.TailHeight || m.TailHeight == 0 {
138133
m.TailHeight = height
139134
}
140135
}

0 commit comments

Comments
 (0)