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

Function testFork

core/blockchain_test.go:70–96  ·  view source on GitHub ↗

Test fork of length N starting from block i

(t *testing.T, blockchain *BlockChain, i, n int, comparator func(td1, td2 *big.Int))

Source from the content-addressed store, hash-verified

68
69// Test fork of length N starting from block i
70func 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.

Callers 4

TestShorterForkBlocksFunction · 0.85
TestLongerForkBlocksFunction · 0.85
TestEqualForkBlocksFunction · 0.85

Calls 9

newCanonicalFunction · 0.85
fakeDporFunction · 0.85
makeBlockChainFunction · 0.85
FatalMethod · 0.65
StopMethod · 0.65
HashMethod · 0.65
GetBlockByNumberMethod · 0.65
CurrentBlockMethod · 0.65
InsertChainMethod · 0.65

Tested by

no test coverage detected