Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
abe08d7b
Commit
abe08d7b
authored
Apr 23, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #794 from Gustav-Simonsson/block_tests_more_validations
Add block header validations for block tests
parents
94f2adb8
7a223721
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
block_test_util.go
tests/block_test_util.go
+82
-0
No files found.
tests/block_test_util.go
View file @
abe08d7b
...
...
@@ -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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment