Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
5f5910c6
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,发现更多精彩内容 >>
提交
5f5910c6
编写于
7月 01, 2014
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Regression test for trie
上级
ed276cd7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
16 deletion
+54
-16
ethutil/trie_test.go
ethutil/trie_test.go
+54
-16
未找到文件。
ethutil/trie_test.go
浏览文件 @
5f5910c6
...
...
@@ -6,9 +6,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
"net/http"
"reflect"
"testing"
"time"
)
const
LONG_WORD
=
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
...
...
@@ -211,7 +213,7 @@ func CreateTest(name string, data []byte) (Test, error) {
return
t
,
nil
}
func
CreateTests
(
uri
string
,
cb
func
(
Test
))
{
func
CreateTests
(
uri
string
,
cb
func
(
Test
))
map
[
string
]
Test
{
resp
,
err
:=
http
.
Get
(
uri
)
if
err
!=
nil
{
panic
(
err
)
...
...
@@ -226,14 +228,20 @@ func CreateTests(uri string, cb func(Test)) {
panic
(
err
)
}
tests
:=
make
(
map
[
string
]
Test
)
for
name
,
testData
:=
range
objmap
{
test
,
err
:=
CreateTest
(
name
,
*
testData
)
if
err
!=
nil
{
panic
(
err
)
}
cb
(
test
)
if
cb
!=
nil
{
cb
(
test
)
}
tests
[
name
]
=
test
}
return
tests
}
func
TestRemote
(
t
*
testing
.
T
)
{
...
...
@@ -271,22 +279,52 @@ func TestTrieReplay(t *testing.T) {
})
}
func
TestIt
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
func
RandomData
()
[][]
string
{
data
:=
[][]
string
{
{
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1"
,
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
},
{
"0x0000000000000000000000000000000000000000000000000000000000000045"
,
"0x22b224a1420a802ab51d326e29fa98e34c4f24ea"
},
{
"0x0000000000000000000000000000000000000000000000000000000000000046"
,
"0x67706c2076330000000000000000000000000000000000000000000000000000"
},
{
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6"
,
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
},
{
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2"
,
"0x4655474156000000000000000000000000000000000000000000000000000000"
},
{
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
,
"0x697c7b8c961b56f675d570498424ac8de1a918f6"
},
{
"0x4655474156000000000000000000000000000000000000000000000000000000"
,
"0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"
},
{
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
,
"0xec4f34c97e43fbb2816cfd95e388353c7181dab1"
},
}
var
c
[][]
string
for
len
(
data
)
!=
0
{
e
:=
rand
.
Intn
(
len
(
data
))
c
=
append
(
c
,
data
[
e
])
copy
(
data
[
e
:
],
data
[
e
+
1
:
])
data
[
len
(
data
)
-
1
]
=
nil
data
=
data
[
:
len
(
data
)
-
1
]
}
return
c
}
const
MaxTest
=
1000
// This test insert data in random order and seeks to find indifferences between the different tries
func
TestRegression
(
t
*
testing
.
T
)
{
rand
.
Seed
(
time
.
Now
()
.
Unix
())
roots
:=
make
(
map
[
string
]
int
)
for
i
:=
0
;
i
<
MaxTest
;
i
++
{
_
,
trie
:=
New
()
data
:=
RandomData
()
for
_
,
test
:=
range
data
{
trie
.
Update
(
test
[
0
],
test
[
1
])
}
test
:=
map
[
string
]
string
{
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1"
:
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
,
"0x0000000000000000000000000000000000000000000000000000000000000045"
:
"0x22b224a1420a802ab51d326e29fa98e34c4f24ea"
,
"0x0000000000000000000000000000000000000000000000000000000000000046"
:
"0x67706c2076330000000000000000000000000000000000000000000000000000"
,
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6"
:
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
,
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2"
:
"0x4655474156000000000000000000000000000000000000000000000000000000"
,
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
:
"0x697c7b8c961b56f675d570498424ac8de1a918f6"
,
"0x4655474156000000000000000000000000000000000000000000000000000000"
:
"0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"
,
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
:
"0xec4f34c97e43fbb2816cfd95e388353c7181dab1"
,
roots
[
string
(
trie
.
Root
.
([]
byte
))]
+=
1
}
for
k
,
v
:=
range
test
{
trie
.
Update
(
k
,
v
)
if
len
(
roots
)
>
1
{
for
root
,
num
:=
range
roots
{
t
.
Errorf
(
"%x => %d
\n
"
,
root
,
num
)
}
}
fmt
.
Printf
(
"root : %x
\n
"
,
trie
.
Root
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录