MCPcopy Create free account
hub / github.com/CPChain/chain / TestQueueGapFill

Function TestQueueGapFill

protocols/cpc/fetcher/fetcher_test.go:428–451  ·  view source on GitHub ↗

Tests that direct block enqueues (due to block propagation vs. hash announce) are correctly schedule, filling and import queue gaps.

(t *testing.T)

Source from the content-addressed store, hash-verified

426// Tests that direct block enqueues (due to block propagation vs. hash announce)
427// are correctly schedule, filling and import queue gaps.
428func TestQueueGapFill(t *testing.T) {
429 // Create a chain of blocks to import, and choose one to not announce at all
430 targetBlocks := maxQueueDist
431 hashes, blocks := makeChain(targetBlocks, 0, genesis)
432 skip := targetBlocks / 2
433
434 tester := newTester()
435 headerFetcher := tester.makeHeaderFetcher("valid", blocks, -gatherSlack)
436 bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0)
437
438 // Iteratively announce blocks, skipping one entry
439 imported := make(chan *types.Block, len(hashes)-1)
440 tester.fetcher.importedHook = func(block *types.Block) { imported <- block }
441
442 for i := len(hashes) - 1; i >= 0; i-- {
443 if i != skip {
444 tester.fetcher.Notify("valid", hashes[i], uint64(len(hashes)-i-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher)
445 time.Sleep(time.Millisecond)
446 }
447 }
448 // Fill the missing block directly as if propagated
449 tester.fetcher.Enqueue("valid", blocks[hashes[skip]])
450 verifyImportCount(t, imported, len(hashes)-1)
451}
452
453// Tests that blocks arriving from various sources (multiple propagations, hash
454// announces, etc) do not get scheduled for import multiple times.

Callers

nothing calls this directly

Calls 10

makeChainFunction · 0.85
newTesterFunction · 0.85
verifyImportCountFunction · 0.85
makeHeaderFetcherMethod · 0.80
makeBodyFetcherMethod · 0.80
SleepMethod · 0.80
EnqueueMethod · 0.80
AddMethod · 0.65
NowMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected