diff --git a/internal/confirmations/confirmed_block_listener_test.go b/internal/confirmations/confirmed_block_listener_test.go index 8faadf6..b92bc35 100644 --- a/internal/confirmations/confirmed_block_listener_test.go +++ b/internal/confirmations/confirmed_block_listener_test.go @@ -333,7 +333,7 @@ func TestCBLDispatcherFallsBehindHead(t *testing.T) { id := fftypes.NewUUID() - blocks := testBlockArray(100) + blocks := testBlockArray(30) mbiHash := mca.On("BlockInfoByHash", mock.Anything, mock.Anything) mbiHash.Run(func(args mock.Arguments) { mockBlockHashReturn(mbiHash, args, blocks) }) @@ -353,15 +353,18 @@ func TestCBLDispatcherFallsBehindHead(t *testing.T) { }) } + // The dispatches should have been added, until it got too far ahead + // and then set to nil. + for cbl.newHeadToAdd != nil { + time.Sleep(1 * time.Millisecond) + } + + // For N-5 (e.g. 15 blocks for a 20 block list) check that we get a dispatch saying that each block 0-14 has been confirmed for i := 0; i < len(blocks)-bcm.requiredConfirmations; i++ { - // The dispatches should have been added, until it got too far ahead - // and then set to nil. - for cbl.newHeadToAdd != nil { - time.Sleep(1 * time.Millisecond) - } + // We should get an event-stream dispatch for blocks N-5 (e.g. 0-15 for a 20 block list) b := <-esDispatch - assert.Equal(t, b.BlockEvent.BlockNumber.Uint64(), blocks[i].BlockNumber.Uint64()) - assert.Equal(t, b.BlockEvent.BlockInfo, blocks[i].BlockInfo) + assert.Equal(t, blocks[i].BlockNumber.Uint64(), b.BlockEvent.BlockNumber.Uint64()) + assert.Equal(t, blocks[i].BlockInfo, b.BlockEvent.BlockInfo) } time.Sleep(1 * time.Millisecond)