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

Function makeChain

protocols/cpc/fetcher/fetcher_test.go:39–66  ·  view source on GitHub ↗

makeChain creates a chain of n blocks starting at and including parent. the returned hash chain is ordered head->parent. In addition, every 3rd block contains a transaction and every 5th an uncle to allow testing correct block reassembly.

(n int, seed byte, parent *types.Block)

Source from the content-addressed store, hash-verified

37// contains a transaction and every 5th an uncle to allow testing correct block
38// reassembly.
39func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common.Hash]*types.Block) {
40
41 config := configs.ChainConfigInfo().Dpor
42 d := dpor.NewFaker(config, testdb)
43
44 blocks, _ := core.GenerateChain(configs.TestChainConfig, parent, d, testdb, testRemoteDB, n, func(i int, block *core.BlockGen) {
45 block.SetCoinbase(common.Address{seed})
46
47 // If the block number is multiple of 3, send a bonus transaction to the miner
48 if parent == genesis && i%3 == 0 {
49 signer := types.MakeSigner(configs.TestChainConfig)
50 tx, err := types.SignTx(types.NewTransaction(block.TxNonce(testAddress), common.Address{seed}, big.NewInt(1000), configs.TxGas, nil, nil), signer, testKey)
51 if err != nil {
52 panic(err)
53 }
54 block.AddTx(tx)
55 }
56 })
57 hashes := make([]common.Hash, n+1)
58 hashes[len(hashes)-1] = parent.Hash()
59 blockm := make(map[common.Hash]*types.Block, n+1)
60 blockm[parent.Hash()] = parent
61 for i, b := range blocks {
62 hashes[len(hashes)-i-2] = b.Hash()
63 blockm[b.Hash()] = b
64 }
65 return hashes, blockm
66}
67
68// fetcherTester is a test simulator for mocking out local block chain.
69type fetcherTester struct {

Calls 6

ChainConfigInfoMethod · 0.80
TxNonceMethod · 0.80
AddTxMethod · 0.80
SignTxMethod · 0.65
HashMethod · 0.65
SetCoinbaseMethod · 0.45

Tested by

no test coverage detected