5
5
"testing"
6
6
"time"
7
7
8
+ "github.com/ipfs/go-datastore"
9
+ "github.com/ipfs/go-datastore/sync"
8
10
"github.com/stretchr/testify/assert"
9
11
"github.com/stretchr/testify/require"
10
12
@@ -21,15 +23,15 @@ func TestSyncSimpleRequestingHead(t *testing.T) {
21
23
suite := headertest .NewTestSuite (t )
22
24
head := suite .Head ()
23
25
24
- remoteStore := store . NewTestStore ( ctx , t , head )
26
+ remoteStore := newTestStore ( t , ctx , head )
25
27
err := remoteStore .Append (ctx , suite .GenDummyHeaders (100 )... )
26
28
require .NoError (t , err )
27
29
28
30
_ , err = remoteStore .GetByHeight (ctx , 100 )
29
31
require .NoError (t , err )
30
32
31
- localStore := store . NewTestStore ( ctx , t , head )
32
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
33
+ localStore := newTestStore ( t , ctx , head )
34
+ syncer , err := NewSyncer (
33
35
local .NewExchange (remoteStore ),
34
36
localStore ,
35
37
headertest .NewDummySubscriber (),
@@ -67,9 +69,9 @@ func TestDoSyncFullRangeFromExternalPeer(t *testing.T) {
67
69
suite := headertest .NewTestSuite (t )
68
70
head := suite .Head ()
69
71
70
- remoteStore := store . NewTestStore ( ctx , t , head )
71
- localStore := store . NewTestStore ( ctx , t , head )
72
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
72
+ remoteStore := newTestStore ( t , ctx , head )
73
+ localStore := newTestStore ( t , ctx , head )
74
+ syncer , err := NewSyncer (
73
75
local .NewExchange (remoteStore ),
74
76
localStore ,
75
77
headertest .NewDummySubscriber (),
@@ -106,9 +108,9 @@ func TestSyncCatchUp(t *testing.T) {
106
108
suite := headertest .NewTestSuite (t )
107
109
head := suite .Head ()
108
110
109
- remoteStore := store . NewTestStore ( ctx , t , head )
110
- localStore := store . NewTestStore ( ctx , t , head )
111
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
111
+ remoteStore := newTestStore ( t , ctx , head )
112
+ localStore := newTestStore ( t , ctx , head )
113
+ syncer , err := NewSyncer (
112
114
local .NewExchange (remoteStore ),
113
115
localStore ,
114
116
headertest .NewDummySubscriber (),
@@ -157,9 +159,9 @@ func TestSyncPendingRangesWithMisses(t *testing.T) {
157
159
suite := headertest .NewTestSuite (t )
158
160
head := suite .Head ()
159
161
160
- remoteStore := store . NewTestStore ( ctx , t , head )
161
- localStore := store . NewTestStore ( ctx , t , head )
162
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
162
+ remoteStore := newTestStore ( t , ctx , head )
163
+ localStore := newTestStore ( t , ctx , head )
164
+ syncer , err := NewSyncer (
163
165
local .NewExchange (remoteStore ),
164
166
localStore ,
165
167
headertest .NewDummySubscriber (),
@@ -224,9 +226,9 @@ func TestSyncer_FindHeadersReturnsCorrectRange(t *testing.T) {
224
226
suite := headertest .NewTestSuite (t )
225
227
head := suite .Head ()
226
228
227
- remoteStore := store . NewTestStore ( ctx , t , head )
228
- localStore := store . NewTestStore ( ctx , t , head )
229
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
229
+ remoteStore := newTestStore ( t , ctx , head )
230
+ localStore := newTestStore ( t , ctx , head )
231
+ syncer , err := NewSyncer (
230
232
local .NewExchange (remoteStore ),
231
233
localStore ,
232
234
headertest .NewDummySubscriber (),
@@ -260,9 +262,9 @@ func TestSyncerIncomingDuplicate(t *testing.T) {
260
262
suite := headertest .NewTestSuite (t )
261
263
head := suite .Head ()
262
264
263
- remoteStore := store . NewTestStore ( ctx , t , head )
264
- localStore := store . NewTestStore ( ctx , t , head )
265
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
265
+ remoteStore := newTestStore ( t , ctx , head )
266
+ localStore := newTestStore ( t , ctx , head )
267
+ syncer , err := NewSyncer (
266
268
& delayedGetter [* headertest.DummyHeader ]{Getter : local .NewExchange (remoteStore )},
267
269
localStore ,
268
270
headertest .NewDummySubscriber (),
@@ -301,12 +303,12 @@ func TestSync_InvalidSyncTarget(t *testing.T) {
301
303
head := suite .Head ()
302
304
303
305
// create a local store which is initialised at genesis height
304
- localStore := store . NewTestStore ( ctx , t , head )
306
+ localStore := newTestStore ( t , ctx , head )
305
307
// create a peer which is already on height 100
306
- remoteStore := headertest .NewStore [ * headertest. DummyHeader ] (t , suite , 100 )
308
+ remoteStore := headertest .NewStore (t , suite , 100 )
307
309
308
- syncer , err := NewSyncer [ * headertest. DummyHeader ] (
309
- local.NewExchange [ * headertest. DummyHeader ] (remoteStore ),
310
+ syncer , err := NewSyncer (
311
+ local .NewExchange (remoteStore ),
310
312
localStore ,
311
313
headertest .NewDummySubscriber (),
312
314
WithBlockTime (time .Nanosecond ),
@@ -396,3 +398,9 @@ func (d *delayedGetter[H]) GetRangeByHeight(ctx context.Context, from H, to uint
396
398
return nil , ctx .Err ()
397
399
}
398
400
}
401
+
402
+ // newTestStore creates initialized and started in memory header Store which is useful for testing.
403
+ func newTestStore (tb testing.TB , ctx context.Context , head * headertest.DummyHeader ) header.Store [* headertest.DummyHeader ] {
404
+ ds := sync .MutexWrap (datastore .NewMapDatastore ())
405
+ return store .NewTestStore (tb , ctx , ds , head )
406
+ }
0 commit comments