aboutsummaryrefslogtreecommitdiffstats
path: root/tests/block_test_util.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-04-23 10:38:47 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-04-23 11:32:56 +0800
commit7a223721a57037e11235c2ea0c3c4f56f932c836 (patch)
tree0dec65d1b0034ca4db724aee4fbd8dfad4ce22c5 /tests/block_test_util.go
parent94f2adb80a54c9bddacf146138d8e218a95629c9 (diff)
downloaddexon-7a223721a57037e11235c2ea0c3c4f56f932c836.tar.gz
dexon-7a223721a57037e11235c2ea0c3c4f56f932c836.tar.zst
dexon-7a223721a57037e11235c2ea0c3c4f56f932c836.zip
Add block header validations for block tests
Diffstat (limited to 'tests/block_test_util.go')
-rw-r--r--tests/block_test_util.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index df651d24e..f34c5d200 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -160,7 +160,89 @@ func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) error {
if b.BlockHeader == nil {
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
}