diff --git a/sync/sync_test.go b/sync/sync_test.go index b9acb2d..94bf5d3 100644 --- a/sync/sync_test.go +++ b/sync/sync_test.go @@ -303,7 +303,7 @@ func TestSync_InvalidSyncTarget(t *testing.T) { head := suite.Head() // create a local store which is initialised at genesis height - localStore := newTestStore(t, ctx, head) + localStore := newTestStore(t, ctx, head, store.WithWriteBatchSize(10)) // create a peer which is already on height 100 remoteStore := headertest.NewStore(t, suite, 100) @@ -347,7 +347,14 @@ func TestSync_InvalidSyncTarget(t *testing.T) { // ensure syncer could only sync up to one header below the bad sync target h, err := localStore.Head(ctx) require.NoError(t, err) - require.Equal(t, maliciousHeader.Height()-1, h.Height()) + + // we need to wait for a flush + assert.Eventually(t, func() bool { + h, err = localStore.Head(ctx) + require.NoError(t, err) + + return maliciousHeader.Height()-1 == h.Height() + }, time.Second, 100*time.Millisecond) // manually change bad sync target to a good header in remote peer // store so it can re-serve it to syncer once it re-requests the height @@ -400,7 +407,7 @@ func (d *delayedGetter[H]) GetRangeByHeight(ctx context.Context, from H, to uint } // newTestStore creates initialized and started in memory header Store which is useful for testing. -func newTestStore(tb testing.TB, ctx context.Context, head *headertest.DummyHeader) header.Store[*headertest.DummyHeader] { +func newTestStore(tb testing.TB, ctx context.Context, head *headertest.DummyHeader, opts ...store.Option) header.Store[*headertest.DummyHeader] { ds := sync.MutexWrap(datastore.NewMapDatastore()) - return store.NewTestStore(tb, ctx, ds, head) + return store.NewTestStore(tb, ctx, ds, head, opts...) }