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

Method insertBlocks

tests/block_test_util.go:163–196  ·  view source on GitHub ↗

* See https://github.com/ethereum/tests/wiki/Blockchain-Tests-II Whether a block is valid or not is a bit subtle, it's defined by presence of blockHeader, transactions and uncleHeaders fields. If they are missing, the block is invalid and we must verify that we do not accept it. Since

(blockchain *core.BlockChain)

Source from the content-addressed store, hash-verified

161 post state.
162*/
163func (t *BlockTest) insertBlocks(blockchain *core.BlockChain) ([]btBlock, error) {
164 validBlocks := make([]btBlock, 0)
165 // insert the test blocks, which will execute all transactions
166 for _, b := range t.json.Blocks {
167 cb, err := b.decode()
168 if err != nil {
169 if b.BlockHeader == nil {
170 continue // OK - block is supposed to be invalid, continue with next block
171 } else {
172 return nil, fmt.Errorf("Block RLP decoding failed when expected to succeed: %v", err)
173 }
174 }
175 // RLP decoding worked, try to insert into chain:
176 blocks := types.Blocks{cb}
177 i, err := blockchain.InsertChain(blocks)
178 if err != nil {
179 if b.BlockHeader == nil {
180 continue // OK - block is supposed to be invalid, continue with next block
181 } else {
182 return nil, fmt.Errorf("Block #%v insertion into chain failed: %v", blocks[i].Number(), err)
183 }
184 }
185 if b.BlockHeader == nil {
186 return nil, fmt.Errorf("Block insertion should have failed")
187 }
188
189 // validate RLP decoding by checking all values against test file JSON
190 if err = validateHeader(b.BlockHeader, cb.Header()); err != nil {
191 return nil, fmt.Errorf("Deserialised block header validation failed: %v", err)
192 }
193 validBlocks = append(validBlocks, b)
194 }
195 return validBlocks, nil
196}
197
198func validateHeader(h *btHeader, h2 *types.Header) error {
199 if h.Bloom != h2.LogsBloom {

Callers 1

RunMethod · 0.95

Calls 5

validateHeaderFunction · 0.85
decodeMethod · 0.80
HeaderMethod · 0.80
InsertChainMethod · 0.65
NumberMethod · 0.45

Tested by

no test coverage detected