(t *testing.T, first, second []int64, td int64)
| 322 | } |
| 323 | |
| 324 | func testReorg(t *testing.T, first, second []int64, td int64) { |
| 325 | // Create a pristine chain and database |
| 326 | db := database.NewMemDatabase() |
| 327 | blockchain, err := newCanonical(fakeDpor(db), 0, db) |
| 328 | if err != nil { |
| 329 | t.Fatalf("failed to create pristine chain: %v", err) |
| 330 | } |
| 331 | defer blockchain.Stop() |
| 332 | |
| 333 | remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 334 | // Insert an easy and a difficult chain afterwards |
| 335 | easyBlocks, _ := GenerateChain(configs.TestChainConfig, blockchain.CurrentBlock(), fakeDpor(db), db, remoteDB, len(first), func(i int, b *BlockGen) { |
| 336 | b.OffsetTime(first[i]) |
| 337 | }) |
| 338 | diffBlocks, _ := GenerateChain(configs.TestChainConfig, blockchain.CurrentBlock(), fakeDpor(db), db, remoteDB, len(second), func(i int, b *BlockGen) { |
| 339 | b.OffsetTime(second[i]) |
| 340 | }) |
| 341 | if _, err := blockchain.InsertChain(easyBlocks); err != nil { |
| 342 | t.Fatalf("failed to insert easy chain: %v", err) |
| 343 | } |
| 344 | if _, err := blockchain.InsertChain(diffBlocks); err != nil { |
| 345 | t.Fatalf("failed to insert difficult chain: %v", err) |
| 346 | } |
| 347 | // Check that the chain is valid number and link wise |
| 348 | prev := blockchain.CurrentBlock() |
| 349 | for block := blockchain.GetBlockByNumber(blockchain.CurrentBlock().NumberU64() - 1); block.NumberU64() != 0; prev, block = block, blockchain.GetBlockByNumber(block.NumberU64()-1) { |
| 350 | if prev.ParentHash() != block.Hash() { |
| 351 | t.Errorf("parent block hash mismatch: have %x, want %x", prev.ParentHash(), block.Hash()) |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | // Tests that the insertion functions detect banned hashes. |
| 357 |
no test coverage detected