This is a regression test (i.e. as weird as it is, don't delete it ever), which tests that under weird reorg conditions the blockchain and its internal header- chain return the same latest block/header. https://github.com/ethereum/go-ethereum/pull/15941
(t *testing.T)
| 758 | // |
| 759 | // https://github.com/ethereum/go-ethereum/pull/15941 |
| 760 | func TestBlockchainHeaderchainReorgConsistency(t *testing.T) { |
| 761 | t.Skip("=== Diff TestBlockchainHeaderchainReorgConsistency failed to insert into chain: extra-data 32 byte vanity prefix missing") |
| 762 | // Generate a canonical chain to act as the main dataset |
| 763 | |
| 764 | db := database.NewMemDatabase() |
| 765 | engine := fakeDpor(db) |
| 766 | remoteDB := database.NewIpfsDbWithAdapter(database.NewFakeIpfsAdapter()) |
| 767 | genesis := new(Genesis).MustCommit(db) |
| 768 | blocks, _ := GenerateChain(configs.TestChainConfig, genesis, engine, db, remoteDB, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) |
| 769 | |
| 770 | // Generate a bunch of fork blocks, each side forking from the canonical chain |
| 771 | forks := make([]*types.Block, len(blocks)) |
| 772 | for i := 0; i < len(forks); i++ { |
| 773 | parent := genesis |
| 774 | if i > 0 { |
| 775 | parent = blocks[i-1] |
| 776 | } |
| 777 | fork, _ := GenerateChain(configs.TestChainConfig, parent, engine, db, remoteDB, 1, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{2}) }) |
| 778 | forks[i] = fork[0] |
| 779 | } |
| 780 | // Import the canonical and fork chain side by side, verifying the current block |
| 781 | // and current header consistency |
| 782 | diskdb := database.NewMemDatabase() |
| 783 | new(Genesis).MustCommit(diskdb) |
| 784 | |
| 785 | chain, err := NewBlockChain(diskdb, nil, configs.TestChainConfig, engine, vm.Config{}, remoteDB, nil) |
| 786 | if err != nil { |
| 787 | t.Fatalf("failed to create tester chain: %v", err) |
| 788 | } |
| 789 | for i := 0; i < len(blocks); i++ { |
| 790 | if _, err := chain.InsertChain(blocks[i : i+1]); err != nil { |
| 791 | t.Fatalf("block %d: failed to insert into chain: %v", i, err) |
| 792 | } |
| 793 | if chain.CurrentBlock().Hash() != chain.CurrentHeader().Hash() { |
| 794 | t.Errorf("block %d: current block/header mismatch: block #%d [%x…], header #%d [%x…]", i, chain.CurrentBlock().Number(), chain.CurrentBlock().Hash().Bytes()[:4], chain.CurrentHeader().Number, chain.CurrentHeader().Hash().Bytes()[:4]) |
| 795 | } |
| 796 | if _, err := chain.InsertChain(forks[i : i+1]); err != nil { |
| 797 | t.Fatalf(" fork %d: failed to insert into chain: %v", i, err) |
| 798 | } |
| 799 | if chain.CurrentBlock().Hash() != chain.CurrentHeader().Hash() { |
| 800 | t.Errorf(" fork %d: current block/header mismatch: block #%d [%x…], header #%d [%x…]", i, chain.CurrentBlock().Number(), chain.CurrentBlock().Hash().Bytes()[:4], chain.CurrentHeader().Number, chain.CurrentHeader().Hash().Bytes()[:4]) |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | // Tests that importing small side forks doesn't leave junk in the trie database |
| 806 | // cache (which would eventually cause memory issues). |
nothing calls this directly
no test coverage detected