Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
abe08d7b
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
abe08d7b
编写于
4月 23, 2015
作者:
J
Jeffrey Wilcke
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #794 from Gustav-Simonsson/block_tests_more_validations
Add block header validations for block tests
上级
94f2adb8
7a223721
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
82 addition
and
0 deletion
+82
-0
tests/block_test_util.go
tests/block_test_util.go
+82
-0
未找到文件。
tests/block_test_util.go
浏览文件 @
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
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录