Tests that a fetcher accepts block announcements and initiates retrievals for them, successfully importing into the local chain.
(t *testing.T)
| 263 | // Tests that a fetcher accepts block announcements and initiates retrievals for |
| 264 | // them, successfully importing into the local chain. |
| 265 | func 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. |
nothing calls this directly
no test coverage detected