github.com/sunriselayer/sunrise-da@v0.13.1-sr3/das/checkpoint_test.go (about) 1 package das 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/ipfs/go-datastore" 9 "github.com/ipfs/go-datastore/sync" 10 "github.com/stretchr/testify/assert" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestCheckpointStore(t *testing.T) { 15 ds := newCheckpointStore(sync.MutexWrap(datastore.NewMapDatastore())) 16 failed := make(map[uint64]int) 17 failed[2] = 1 18 failed[3] = 2 19 cp := checkpoint{ 20 SampleFrom: 1, 21 NetworkHead: 6, 22 Failed: failed, 23 Workers: []workerCheckpoint{ 24 { 25 From: 1, 26 To: 2, 27 JobType: retryJob, 28 }, 29 { 30 From: 5, 31 To: 10, 32 JobType: recentJob, 33 }, 34 }, 35 } 36 ctx, cancel := context.WithTimeout(context.Background(), time.Minute) 37 defer t.Cleanup(cancel) 38 assert.NoError(t, ds.store(ctx, cp)) 39 got, err := ds.load(ctx) 40 require.NoError(t, err) 41 assert.Equal(t, cp, got) 42 }