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

Function TestSequentialAnnouncements

protocols/cpc/fetcher/fetcher_test.go:265–287  ·  view source on GitHub ↗

Tests that a fetcher accepts block announcements and initiates retrievals for them, successfully importing into the local chain.

(t *testing.T)

Source from the content-addressed store, hash-verified

263// Tests that a fetcher accepts block announcements and initiates retrievals for
264// them, successfully importing into the local chain.
265func TestSequentialAnnouncements(t *testing.T) {
266 // Create a chain of blocks to import
267 targetBlocks := 4 * hashLimit
268 // hashes is in reverse order
269 // hashes[-1] should be the genesis block
270 hashes, blocks := makeChain(targetBlocks, 0, genesis)
271
272 tester := newTester()
273 headerFetcher := tester.makeHeaderFetcher("valid", blocks, -gatherSlack)
274 bodyFetcher := tester.makeBodyFetcher("valid", blocks, 0)
275
276 // Iteratively announce blocks until all are imported
277 imported := make(chan *types.Block)
278 // the hook is run by insert
279 tester.fetcher.importedHook = func(block *types.Block) { imported <- block }
280
281 // go from block 1 to the last block
282 for i := len(hashes) - 2; i >= 0; i-- {
283 tester.fetcher.Notify("valid", hashes[i], uint64(len(hashes)-i-1), time.Now().Add(-arriveTimeout), headerFetcher, bodyFetcher)
284 verifyImportEvent(t, imported, true)
285 }
286 verifyImportDone(t, imported)
287}
288
289// Tests that if blocks are announced by multiple peers (or even the same buggy
290// peer), they will only get downloaded at most once.

Callers

nothing calls this directly

Calls 9

makeChainFunction · 0.85
newTesterFunction · 0.85
verifyImportEventFunction · 0.85
verifyImportDoneFunction · 0.85
makeHeaderFetcherMethod · 0.80
makeBodyFetcherMethod · 0.80
AddMethod · 0.65
NowMethod · 0.65
NotifyMethod · 0.45

Tested by

no test coverage detected