mirror of https://github.com/status-im/op-geth.git
Add block header validations for block tests
This commit is contained in:
parent
94f2adb80a
commit
7a223721a5
|
@ -160,7 +160,89 @@ func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) error {
|
||||||
if b.BlockHeader == nil {
|
if b.BlockHeader == nil {
|
||||||
return fmt.Errorf("Block insertion should have failed")
|
return fmt.Errorf("Block insertion should have failed")
|
||||||
}
|
}
|
||||||
|
err = validateBlockHeader(b.BlockHeader, cb.Header())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Block header validation failed: ", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateBlockHeader(h *btHeader, h2 *types.Header) error {
|
||||||
|
expectedBloom := mustConvertBytes(h.Bloom)
|
||||||
|
if !bytes.Equal(expectedBloom, h2.Bloom.Bytes()) {
|
||||||
|
return fmt.Errorf("Bloom: expected: %v, decoded: %v", expectedBloom, h2.Bloom.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedCoinbase := mustConvertBytes(h.Coinbase)
|
||||||
|
if !bytes.Equal(expectedCoinbase, h2.Coinbase.Bytes()) {
|
||||||
|
return fmt.Errorf("Coinbase: expected: %v, decoded: %v", expectedCoinbase, h2.Coinbase.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedMixHashBytes := mustConvertBytes(h.MixHash)
|
||||||
|
if !bytes.Equal(expectedMixHashBytes, h2.MixDigest.Bytes()) {
|
||||||
|
return fmt.Errorf("MixHash: expected: %v, decoded: %v", expectedMixHashBytes, h2.MixDigest.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedNonce := mustConvertBytes(h.Nonce)
|
||||||
|
if !bytes.Equal(expectedNonce, h2.Nonce[:]) {
|
||||||
|
return fmt.Errorf("Nonce: expected: %v, decoded: %v", expectedNonce, h2.Nonce[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedNumber := mustConvertBigInt(h.Number, 16)
|
||||||
|
if expectedNumber.Cmp(h2.Number) != 0 {
|
||||||
|
return fmt.Errorf("Number: expected: %v, decoded: %v", expectedNumber, h2.Number)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedParentHash := mustConvertBytes(h.ParentHash)
|
||||||
|
if !bytes.Equal(expectedParentHash, h2.ParentHash.Bytes()) {
|
||||||
|
return fmt.Errorf("Parent hash: expected: %v, decoded: %v", expectedParentHash, h2.ParentHash.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedReceiptHash := mustConvertBytes(h.ReceiptTrie)
|
||||||
|
if !bytes.Equal(expectedReceiptHash, h2.ReceiptHash.Bytes()) {
|
||||||
|
return fmt.Errorf("Receipt hash: expected: %v, decoded: %v", expectedReceiptHash, h2.ReceiptHash.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedTxHash := mustConvertBytes(h.TransactionsTrie)
|
||||||
|
if !bytes.Equal(expectedTxHash, h2.TxHash.Bytes()) {
|
||||||
|
return fmt.Errorf("Tx hash: expected: %v, decoded: %v", expectedTxHash, h2.TxHash.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedStateHash := mustConvertBytes(h.StateRoot)
|
||||||
|
if !bytes.Equal(expectedStateHash, h2.Root.Bytes()) {
|
||||||
|
return fmt.Errorf("State hash: expected: %v, decoded: %v", expectedStateHash, h2.Root.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedUncleHash := mustConvertBytes(h.UncleHash)
|
||||||
|
if !bytes.Equal(expectedUncleHash, h2.UncleHash.Bytes()) {
|
||||||
|
return fmt.Errorf("Uncle hash: expected: %v, decoded: %v", expectedUncleHash, h2.UncleHash.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedExtraData := mustConvertBytes(h.ExtraData)
|
||||||
|
if !bytes.Equal(expectedExtraData, h2.Extra) {
|
||||||
|
return fmt.Errorf("Extra data: expected: %v, decoded: %v", expectedExtraData, h2.Extra)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedDifficulty := mustConvertBigInt(h.Difficulty, 16)
|
||||||
|
if expectedDifficulty.Cmp(h2.Difficulty) != 0 {
|
||||||
|
return fmt.Errorf("Difficulty: expected: %v, decoded: %v", expectedDifficulty, h2.Difficulty)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedGasLimit := mustConvertBigInt(h.GasLimit, 16)
|
||||||
|
if expectedGasLimit.Cmp(h2.GasLimit) != 0 {
|
||||||
|
return fmt.Errorf("GasLimit: expected: %v, decoded: %v", expectedGasLimit, h2.GasLimit)
|
||||||
|
}
|
||||||
|
expectedGasUsed := mustConvertBigInt(h.GasUsed, 16)
|
||||||
|
if expectedGasUsed.Cmp(h2.GasUsed) != 0 {
|
||||||
|
return fmt.Errorf("GasUsed: expected: %v, decoded: %v", expectedGasUsed, h2.GasUsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedTimestamp := mustConvertUint(h.Timestamp, 16)
|
||||||
|
if expectedTimestamp != h2.Time {
|
||||||
|
return fmt.Errorf("Timestamp: expected: %v, decoded: %v", expectedTimestamp, h2.Time)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue