Skip to content

Commit

Permalink
Merge branch 'main' into change_error_to_string
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed Jul 11, 2023
2 parents 6907536 + 1ce71fd commit 7aa2164
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion store/heightsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (hs *heightSub[H]) Pub(headers ...H) {

height := hs.Height()
from, to := uint64(headers[0].Height()), uint64(headers[ln-1].Height())
if height+1 != from {
if height+1 != from && height != 0 { // height != 0 is needed to enable init from any height and not only 1
log.Fatalf("PLEASE FILE A BUG REPORT: headers given to the heightSub are in the wrong order: expected %d, got %d", height+1, from)
return
}
Expand Down
14 changes: 14 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,17 @@ func TestBatch_GetByHeightBeforeInit(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, h)
}

func TestStoreInit(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
t.Cleanup(cancel)

suite := headertest.NewTestSuite(t)
ds := sync.MutexWrap(datastore.NewMapDatastore())
store, err := NewStore[*headertest.DummyHeader](ds)
require.NoError(t, err)

headers := suite.GenDummyHeaders(10)
err = store.Init(ctx, headers[len(headers)-1]) // init should work with any height, not only 1
require.NoError(t, err)
}

0 comments on commit 7aa2164

Please sign in to comment.