MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestAddBlock

Function TestAddBlock

consensus/vbft/block_pool_test.go:90–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88 return block, nil
89}
90func TestAddBlock(t *testing.T) {
91 blockpool, err := buildTestBlockPool(t)
92 if err != nil {
93 t.Errorf("buildTestBlockPool err:%s", err)
94 }
95 defer cleanTestChainStore()
96
97 lastBlock, _ := blockpool.getSealedBlock(0)
98 if lastBlock == nil {
99 t.Errorf("getblock err")
100 }
101 t.Logf("block height:%d", blockpool.chainStore.GetChainedBlockNum())
102 blk, err := buildTestBlock(t, lastBlock.Block, blockpool.chainStore.db)
103 if err != nil {
104 t.Errorf("buildTestBlock err:%s", err)
105 }
106 err = blockpool.chainStore.AddBlock(blk)
107 if err != nil {
108 t.Errorf("AddBlock err:%s", err)
109 }
110 merkleRoot, err := blockpool.getExecMerkleRoot(blockpool.chainStore.GetChainedBlockNum())
111 if err != nil {
112 t.Errorf("getExecMerkleRoot err:%s", err)
113 }
114 t.Logf("block height:%d,merkleRoot:%s", blockpool.chainStore.GetChainedBlockNum(), merkleRoot.ToHexString())
115 err = blockpool.submitBlock(blockpool.chainStore.GetChainedBlockNum())
116 if err != nil {
117 t.Errorf("submitBlock err:%s", err)
118 }
119}

Callers

nothing calls this directly

Calls 10

buildTestBlockPoolFunction · 0.85
cleanTestChainStoreFunction · 0.85
buildTestBlockFunction · 0.85
ErrorfMethod · 0.80
getSealedBlockMethod · 0.80
GetChainedBlockNumMethod · 0.80
AddBlockMethod · 0.65
getExecMerkleRootMethod · 0.45
ToHexStringMethod · 0.45
submitBlockMethod · 0.45

Tested by

no test coverage detected