@@ -5,6 +5,7 @@ package executor
5
5
6
6
import (
7
7
"testing"
8
+ "time"
8
9
9
10
"github.com/stretchr/testify/require"
10
11
@@ -124,7 +125,7 @@ func TestAcceptorVisitAtomicBlock(t *testing.T) {
124
125
// Set [blk]'s state in the map as though it had been verified.
125
126
onAcceptState := state .NewMockDiff (ctrl )
126
127
childID := ids .GenerateTestID ()
127
- atomicRequests := map [ids.ID ]* atomic.Requests { ids . GenerateTestID (): nil }
128
+ atomicRequests := make ( map [ids.ID ]* atomic.Requests )
128
129
acceptor .backend .blkIDToState [blk .ID ()] = & blockState {
129
130
onAcceptState : onAcceptState ,
130
131
atomicRequests : atomicRequests ,
@@ -207,7 +208,7 @@ func TestAcceptorVisitStandardBlock(t *testing.T) {
207
208
// Set [blk]'s state in the map as though it had been verified.
208
209
onAcceptState := state .NewMockDiff (ctrl )
209
210
childID := ids .GenerateTestID ()
210
- atomicRequests := map [ids.ID ]* atomic.Requests { ids . GenerateTestID (): nil }
211
+ atomicRequests := make ( map [ids.ID ]* atomic.Requests )
211
212
calledOnAcceptFunc := false
212
213
acceptor .backend .blkIDToState [blk .ID ()] = & blockState {
213
214
onAcceptState : onAcceptState ,
@@ -280,13 +281,21 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
280
281
parentOnAbortState := state .NewMockDiff (ctrl )
281
282
parentOnCommitState := state .NewMockDiff (ctrl )
282
283
parentStatelessBlk := block .NewMockBlock (ctrl )
284
+ calledOnAcceptFunc := false
285
+ atomicRequests := make (map [ids.ID ]* atomic.Requests )
283
286
parentState := & blockState {
284
- statelessBlock : parentStatelessBlk ,
285
- onAcceptState : parentOnAcceptState ,
286
287
proposalBlockState : proposalBlockState {
287
288
onAbortState : parentOnAbortState ,
288
289
onCommitState : parentOnCommitState ,
289
290
},
291
+ statelessBlock : parentStatelessBlk ,
292
+
293
+ onAcceptState : parentOnAcceptState ,
294
+ onAcceptFunc : func () {
295
+ calledOnAcceptFunc = true
296
+ },
297
+
298
+ atomicRequests : atomicRequests ,
290
299
}
291
300
acceptor .backend .blkIDToState [parentID ] = parentState
292
301
@@ -308,13 +317,21 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
308
317
err = acceptor .ApricotCommitBlock (blk )
309
318
require .ErrorIs (err , errMissingBlockState )
310
319
320
+ parentOnCommitState .EXPECT ().GetTimestamp ().Return (time .Unix (0 , 0 ))
321
+
311
322
// Set [blk]'s state in the map as though it had been verified.
312
323
acceptor .backend .blkIDToState [parentID ] = parentState
313
- onAcceptState := state .NewMockDiff (ctrl )
314
324
acceptor .backend .blkIDToState [blkID ] = & blockState {
315
- onAcceptState : onAcceptState ,
325
+ onAcceptState : parentState .onCommitState ,
326
+ onAcceptFunc : parentState .onAcceptFunc ,
327
+
328
+ inputs : parentState .inputs ,
329
+ timestamp : parentOnCommitState .GetTimestamp (),
330
+ atomicRequests : parentState .atomicRequests ,
316
331
}
317
332
333
+ batch := database .NewMockBatch (ctrl )
334
+
318
335
// Set expected calls on dependencies.
319
336
// Make sure the parent is accepted first.
320
337
gomock .InOrder (
@@ -328,12 +345,15 @@ func TestAcceptorVisitCommitBlock(t *testing.T) {
328
345
s .EXPECT ().SetHeight (blk .Height ()).Times (1 ),
329
346
s .EXPECT ().AddStatelessBlock (blk ).Times (1 ),
330
347
331
- onAcceptState .EXPECT ().Apply (s ).Times (1 ),
332
- s .EXPECT ().Commit ().Return (nil ).Times (1 ),
348
+ parentOnCommitState .EXPECT ().Apply (s ).Times (1 ),
349
+ s .EXPECT ().CommitBatch ().Return (batch , nil ).Times (1 ),
350
+ sharedMemory .EXPECT ().Apply (atomicRequests , batch ).Return (nil ).Times (1 ),
333
351
s .EXPECT ().Checksum ().Return (ids .Empty ).Times (1 ),
352
+ s .EXPECT ().Abort ().Times (1 ),
334
353
)
335
354
336
355
require .NoError (acceptor .ApricotCommitBlock (blk ))
356
+ require .True (calledOnAcceptFunc )
337
357
require .Equal (blk .ID (), acceptor .backend .lastAccepted )
338
358
}
339
359
@@ -371,13 +391,21 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
371
391
parentOnAbortState := state .NewMockDiff (ctrl )
372
392
parentOnCommitState := state .NewMockDiff (ctrl )
373
393
parentStatelessBlk := block .NewMockBlock (ctrl )
394
+ calledOnAcceptFunc := false
395
+ atomicRequests := make (map [ids.ID ]* atomic.Requests )
374
396
parentState := & blockState {
375
- statelessBlock : parentStatelessBlk ,
376
- onAcceptState : parentOnAcceptState ,
377
397
proposalBlockState : proposalBlockState {
378
398
onAbortState : parentOnAbortState ,
379
399
onCommitState : parentOnCommitState ,
380
400
},
401
+ statelessBlock : parentStatelessBlk ,
402
+
403
+ onAcceptState : parentOnAcceptState ,
404
+ onAcceptFunc : func () {
405
+ calledOnAcceptFunc = true
406
+ },
407
+
408
+ atomicRequests : atomicRequests ,
381
409
}
382
410
acceptor .backend .blkIDToState [parentID ] = parentState
383
411
@@ -399,14 +427,21 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
399
427
err = acceptor .ApricotAbortBlock (blk )
400
428
require .ErrorIs (err , errMissingBlockState )
401
429
430
+ parentOnAbortState .EXPECT ().GetTimestamp ().Return (time .Unix (0 , 0 ))
431
+
402
432
// Set [blk]'s state in the map as though it had been verified.
403
433
acceptor .backend .blkIDToState [parentID ] = parentState
404
-
405
- onAcceptState := state .NewMockDiff (ctrl )
406
434
acceptor .backend .blkIDToState [blkID ] = & blockState {
407
- onAcceptState : onAcceptState ,
435
+ onAcceptState : parentState .onAbortState ,
436
+ onAcceptFunc : parentState .onAcceptFunc ,
437
+
438
+ inputs : parentState .inputs ,
439
+ timestamp : parentOnAbortState .GetTimestamp (),
440
+ atomicRequests : parentState .atomicRequests ,
408
441
}
409
442
443
+ batch := database .NewMockBatch (ctrl )
444
+
410
445
// Set expected calls on dependencies.
411
446
// Make sure the parent is accepted first.
412
447
gomock .InOrder (
@@ -420,11 +455,14 @@ func TestAcceptorVisitAbortBlock(t *testing.T) {
420
455
s .EXPECT ().SetHeight (blk .Height ()).Times (1 ),
421
456
s .EXPECT ().AddStatelessBlock (blk ).Times (1 ),
422
457
423
- onAcceptState .EXPECT ().Apply (s ).Times (1 ),
424
- s .EXPECT ().Commit ().Return (nil ).Times (1 ),
458
+ parentOnAbortState .EXPECT ().Apply (s ).Times (1 ),
459
+ s .EXPECT ().CommitBatch ().Return (batch , nil ).Times (1 ),
460
+ sharedMemory .EXPECT ().Apply (atomicRequests , batch ).Return (nil ).Times (1 ),
425
461
s .EXPECT ().Checksum ().Return (ids .Empty ).Times (1 ),
462
+ s .EXPECT ().Abort ().Times (1 ),
426
463
)
427
464
428
465
require .NoError (acceptor .ApricotAbortBlock (blk ))
466
+ require .True (calledOnAcceptFunc )
429
467
require .Equal (blk .ID (), acceptor .backend .lastAccepted )
430
468
}
0 commit comments