@@ -20,11 +20,12 @@ func setupTestData(ctx context.Context, t *testing.T, dbpool *pgxpool.Pool, bloc
20
20
db := database .New (dbpool )
21
21
keyperdb := keyperDB .New (dbpool )
22
22
23
- // Set up batch config
23
+ // Set up batch config with Started flag
24
24
err := keyperdb .InsertBatchConfig (ctx , keyperDB.InsertBatchConfigParams {
25
25
KeyperConfigIndex : 1 ,
26
26
Keypers : []string {},
27
27
Height : 50 ,
28
+ Started : true ,
28
29
})
29
30
assert .NilError (t , err )
30
31
@@ -35,12 +36,6 @@ func setupTestData(ctx context.Context, t *testing.T, dbpool *pgxpool.Pool, bloc
35
36
})
36
37
assert .NilError (t , err )
37
38
38
- // Set up TMSyncMeta
39
- err = keyperdb .TMSetSyncMeta (ctx , keyperDB.TMSetSyncMetaParams {
40
- LastCommittedHeight : 100 ,
41
- })
42
- assert .NilError (t , err )
43
-
44
39
// Set up initial block
45
40
err = db .SetIdentityRegisteredEventSyncedUntil (ctx , database.SetIdentityRegisteredEventSyncedUntilParams {
46
41
BlockHash : []byte {0x01 , 0x02 , 0x03 },
@@ -142,6 +137,7 @@ func TestAPISyncMonitor_ContinuesWhenNoRows(t *testing.T) {
142
137
err := keyperdb .InsertBatchConfig (ctx , keyperDB.InsertBatchConfigParams {
143
138
KeyperConfigIndex : 1 ,
144
139
Keypers : []string {},
140
+ Started : true ,
145
141
})
146
142
assert .NilError (t , err )
147
143
@@ -177,7 +173,7 @@ func TestAPISyncMonitor_ContinuesWhenNoRows(t *testing.T) {
177
173
}
178
174
}
179
175
180
- func TestAPISyncMonitor_ContinuesWhenNoDKGResult (t * testing.T ) {
176
+ func TestAPISyncMonitor_SkipsWhenDKGIsRunning (t * testing.T ) {
181
177
ctx , cancel := context .WithCancel (context .Background ())
182
178
defer cancel ()
183
179
@@ -191,12 +187,7 @@ func TestAPISyncMonitor_ContinuesWhenNoDKGResult(t *testing.T) {
191
187
KeyperConfigIndex : 1 ,
192
188
Keypers : []string {},
193
189
Height : 50 ,
194
- })
195
- assert .NilError (t , err )
196
-
197
- // Set up TMSyncMeta
198
- err = keyperdb .TMSetSyncMeta (ctx , keyperDB.TMSetSyncMetaParams {
199
- LastCommittedHeight : 100 ,
190
+ Started : true ,
200
191
})
201
192
assert .NilError (t , err )
202
193
@@ -241,7 +232,7 @@ func TestAPISyncMonitor_ContinuesWhenNoDKGResult(t *testing.T) {
241
232
assert .Equal (t , initialBlockNumber , syncedData .BlockNumber , "block number should remain unchanged" )
242
233
}
243
234
244
- func TestAPISyncMonitor_ContinuesWhenNoBatchConfig (t * testing.T ) {
235
+ func TestAPISyncMonitor_RunsNormallyWhenNoBatchConfig (t * testing.T ) {
245
236
ctx , cancel := context .WithCancel (context .Background ())
246
237
defer cancel ()
247
238
@@ -279,9 +270,9 @@ func TestAPISyncMonitor_ContinuesWhenNoBatchConfig(t *testing.T) {
279
270
280
271
select {
281
272
case err := <- errCh :
282
- t . Fatalf ( "expected monitor to continue without error, but got: %v" , err )
273
+ assert . ErrorContains ( t , err , shutterservice . ErrBlockNotIncreasing . Error () )
283
274
case <- time .After (1 * time .Second ):
284
- // Test passes if no error is received
275
+ t . Fatalf ( "expected monitor to throw error, but no error returned" )
285
276
}
286
277
287
278
// Verify the block number hasn't changed
@@ -290,7 +281,7 @@ func TestAPISyncMonitor_ContinuesWhenNoBatchConfig(t *testing.T) {
290
281
assert .Equal (t , initialBlockNumber , syncedData .BlockNumber , "block number should remain unchanged" )
291
282
}
292
283
293
- func TestAPISyncMonitor_ContinuesWhenNoTMSyncMeta (t * testing.T ) {
284
+ func TestAPISyncMonitor_RunsNormallyWhenBatchConfigNotStarted (t * testing.T ) {
294
285
ctx , cancel := context .WithCancel (context .Background ())
295
286
defer cancel ()
296
287
@@ -299,22 +290,12 @@ func TestAPISyncMonitor_ContinuesWhenNoTMSyncMeta(t *testing.T) {
299
290
db := database .New (dbpool )
300
291
keyperdb := keyperDB .New (dbpool )
301
292
302
- batchConfigHeight := int64 (50 )
303
- // Set TMSyncData height to be less than batchConfigHeight + DKGStartBlockDelta
304
- // This simulates a scenario where DKG hasn't started yet
305
- tmSyncHeight := int64 (60 )
306
-
307
- // Set up batch config
293
+ // Set up batch config with Started = false
308
294
err := keyperdb .InsertBatchConfig (ctx , keyperDB.InsertBatchConfigParams {
309
295
KeyperConfigIndex : 1 ,
310
296
Keypers : []string {},
311
- Height : batchConfigHeight ,
312
- })
313
- assert .NilError (t , err )
314
-
315
- // Set up TMSyncMeta with lower height
316
- err = keyperdb .TMSetSyncMeta (ctx , keyperDB.TMSetSyncMetaParams {
317
- LastCommittedHeight : tmSyncHeight ,
297
+ Height : 50 ,
298
+ Started : false ,
318
299
})
319
300
assert .NilError (t , err )
320
301
@@ -327,9 +308,8 @@ func TestAPISyncMonitor_ContinuesWhenNoTMSyncMeta(t *testing.T) {
327
308
assert .NilError (t , err )
328
309
329
310
monitor := & shutterservice.SyncMonitor {
330
- DBPool : dbpool ,
331
- CheckInterval : 5 * time .Second ,
332
- DKGStartBlockDelta : 5 ,
311
+ DBPool : dbpool ,
312
+ CheckInterval : 5 * time .Second ,
333
313
}
334
314
335
315
monitorCtx , cancelMonitor := context .WithCancel (ctx )
@@ -349,9 +329,9 @@ func TestAPISyncMonitor_ContinuesWhenNoTMSyncMeta(t *testing.T) {
349
329
350
330
select {
351
331
case err := <- errCh :
352
- t . Fatalf ( "expected monitor to continue without error, but got: %v" , err )
332
+ assert . ErrorContains ( t , err , shutterservice . ErrBlockNotIncreasing . Error () )
353
333
case <- time .After (1 * time .Second ):
354
- // Test passes if no error is received
334
+ t . Fatalf ( "expected monitor to throw error, but no error returned" )
355
335
}
356
336
357
337
// Verify the block number hasn't changed
0 commit comments