Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
5f49a659
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,发现更多精彩内容 >>
提交
5f49a659
编写于
3月 31, 2014
作者:
M
Maran
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More blockchain testing
上级
6253d109
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
51 addition
and
9 deletion
+51
-9
ethchain/block_chain.go
ethchain/block_chain.go
+11
-2
ethchain/block_chain_test.go
ethchain/block_chain_test.go
+29
-6
ethutil/rlp_test.go
ethutil/rlp_test.go
+10
-0
ethutil/trie_test.go
ethutil/trie_test.go
+1
-1
未找到文件。
ethchain/block_chain.go
浏览文件 @
5f49a659
...
...
@@ -126,6 +126,7 @@ func (bc *BlockChain) FindCanonicalChain(blocks []*Block, commonBlockHash []byte
log
.
Println
(
"[CHAIN] We have found the common parent block, breaking"
)
break
}
log
.
Println
(
"Checking incoming blocks:"
)
chainDifficulty
.
Add
(
chainDifficulty
,
bc
.
CalculateBlockTD
(
block
))
}
...
...
@@ -139,13 +140,20 @@ func (bc *BlockChain) FindCanonicalChain(blocks []*Block, commonBlockHash []byte
log
.
Println
(
"[CHAIN] We have found the common parent block, breaking"
)
break
}
log
.
Println
(
"CHECKING BLOGK:"
,
i
)
anOtherBlock
:=
bc
.
GetBlock
(
block
.
PrevHash
)
if
anOtherBlock
==
nil
{
// We do not want to count the genesis block for difficulty since that's not being sent
log
.
Println
(
"[CHAIN] At genesis block, breaking"
)
break
}
log
.
Printf
(
"CHECKING OUR OWN BLOCKS: %x"
,
block
.
Hash
())
log
.
Printf
(
"%x"
,
bc
.
GenesisBlock
()
.
Hash
())
curChainDifficulty
.
Add
(
curChainDifficulty
,
bc
.
CalculateBlockTD
(
block
))
}
log
.
Println
(
"[CHAIN] Current chain difficulty:"
,
curChainDifficulty
)
if
chainDifficulty
.
Cmp
(
curChainDifficulty
)
==
1
{
log
.
Print
ln
(
"[CHAIN] The incoming Chain beat our asses, resetting"
)
log
.
Print
f
(
"[CHAIN] The incoming Chain beat our asses, resetting to block: %x"
,
commonBlockHash
)
bc
.
ResetTillBlockHash
(
commonBlockHash
)
return
false
}
else
{
...
...
@@ -165,6 +173,7 @@ func (bc *BlockChain) ResetTillBlockHash(hash []byte) error {
// END TODO
bc
.
Ethereum
.
StateManager
()
.
PrepareDefault
(
returnTo
)
err
:=
ethutil
.
Config
.
Db
.
Delete
(
lastBlock
.
Hash
())
if
err
!=
nil
{
return
err
...
...
ethchain/block_chain_test.go
浏览文件 @
5f49a659
...
...
@@ -78,15 +78,38 @@ func (tm *TestManager) CreateChain2() error {
return
err
}
func
TestBlockChainReorg
(
t
*
testing
.
T
)
{
func
TestNegativeBlockChainReorg
(
t
*
testing
.
T
)
{
// We are resetting the database between creation so we need to cache our information
testManager2
:=
NewTestManager
()
testManager2
.
CreateChain2
()
tm2Blocks
:=
testManager2
.
Blocks
testManager
:=
NewTestManager
()
testManager
.
CreateChain1
()
oldState
:=
testManager
.
BlockChain
()
.
CurrentBlock
.
State
()
if
testManager
.
BlockChain
()
.
FindCanonicalChain
(
tm2Blocks
,
testManager
.
BlockChain
()
.
GenesisBlock
()
.
Hash
())
!=
true
{
t
.
Error
(
"I expected TestManager to have the longest chain, but it was TestManager2 instead."
)
}
if
testManager
.
BlockChain
()
.
CurrentBlock
.
State
()
!=
oldState
{
t
.
Error
(
"I expected the top state to be the same as it was as before the reorg"
)
}
}
func
TestPositiveBlockChainReorg
(
t
*
testing
.
T
)
{
testManager
:=
NewTestManager
()
testManager
.
CreateChain1
()
tm1Blocks
:=
testManager
.
Blocks
testManager2
:=
NewTestManager
()
testManager2
.
CreateChain2
()
oldState
:=
testManager2
.
BlockChain
()
.
CurrentBlock
.
State
()
// This fails because we keep resetting the DB
block
:=
testManager
.
BlockChain
()
.
GetBlock
(
testManager
.
BlockChain
()
.
CurrentBlock
.
PrevHash
)
fmt
.
Println
(
block
)
//testManager.BlockChain().FindCanonicalChain(testManager2.Blocks, testManager.BlockChain().GenesisBlock().Hash())
if
testManager2
.
BlockChain
()
.
FindCanonicalChain
(
tm1Blocks
,
testManager
.
BlockChain
()
.
GenesisBlock
()
.
Hash
())
==
true
{
t
.
Error
(
"I expected TestManager to have the longest chain, but it was TestManager2 instead."
)
}
if
testManager2
.
BlockChain
()
.
CurrentBlock
.
State
()
==
oldState
{
t
.
Error
(
"I expected the top state to have been modified but it was not"
)
}
}
ethutil/rlp_test.go
浏览文件 @
5f49a659
...
...
@@ -2,6 +2,7 @@ package ethutil
import
(
"bytes"
"fmt"
"math/big"
"reflect"
"testing"
...
...
@@ -55,6 +56,15 @@ func TestValue(t *testing.T) {
}
}
func
TestEncodeDecodeMaran
(
t
*
testing
.
T
)
{
b
:=
NewValue
([]
interface
{}{
"dog"
,
15
,
[]
interface
{}{
"cat"
,
"cat"
,
[]
interface
{}{}},
1024
,
"tachikoma"
})
a
:=
b
.
Encode
()
fmt
.
Println
(
"voor maran"
,
a
)
f
,
i
:=
Decode
(
a
,
0
)
fmt
.
Println
(
"voor maran 2"
,
f
)
fmt
.
Println
(
i
)
}
func
TestEncode
(
t
*
testing
.
T
)
{
strRes
:=
"
\x83
dog"
bytes
:=
Encode
(
"dog"
)
...
...
ethutil/trie_test.go
浏览文件 @
5f49a659
package
ethutil
import
(
"fmt"
_
"fmt"
"reflect"
"testing"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录