Test fork of length N starting from block i
(t *testing.T, blockchain *BlockChain, i, n int, comparator func(td1, td2 *big.Int))
| 68 | |
| 69 | // Test fork of length N starting from block i |
| 70 | func testFork(t *testing.T, blockchain *BlockChain, i, n int, comparator func(td1, td2 *big.Int)) { |
| 71 | // Copy old chain up to #i into a new db |
| 72 | db := database.NewMemDatabase() |
| 73 | blockchain2, err := newCanonical(fakeDpor(db), i, db) |
| 74 | |
| 75 | if err != nil { |
| 76 | t.Fatal("could not make new canonical in testFork", err) |
| 77 | } |
| 78 | defer blockchain2.Stop() |
| 79 | |
| 80 | // Assert the chains have the same header/block at #i |
| 81 | var hash1, hash2 common.Hash |
| 82 | hash1 = blockchain.GetBlockByNumber(uint64(i)).Hash() |
| 83 | hash2 = blockchain2.GetBlockByNumber(uint64(i)).Hash() |
| 84 | |
| 85 | if hash1 != hash2 { |
| 86 | t.Errorf("chain content mismatch at %d: have hash %v, want hash %v", i, hash2, hash1) |
| 87 | } |
| 88 | // Extend the newly created chain |
| 89 | var ( |
| 90 | blockChainB []*types.Block |
| 91 | ) |
| 92 | blockChainB = makeBlockChain(blockchain2.CurrentBlock(), n, fakeDpor(db), db, forkSeed) |
| 93 | if _, err := blockchain2.InsertChain(blockChainB); err != nil { |
| 94 | t.Fatalf("failed to insert forking chain: %v", err) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | // testBlockChainImport tries to process a chain of blocks, writing them into |
| 99 | // the database if successful. |
no test coverage detected