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
5f5910c6
Commit
5f5910c6
authored
Jul 01, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Regression test for trie
parent
ed276cd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
16 deletions
+54
-16
trie_test.go
ethutil/trie_test.go
+54
-16
No files found.
ethutil/trie_test.go
View file @
5f5910c6
...
@@ -6,9 +6,11 @@ import (
...
@@ -6,9 +6,11 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"math/rand"
"net/http"
"net/http"
"reflect"
"reflect"
"testing"
"testing"
"time"
)
)
const
LONG_WORD
=
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
const
LONG_WORD
=
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
...
@@ -211,7 +213,7 @@ func CreateTest(name string, data []byte) (Test, error) {
...
@@ -211,7 +213,7 @@ func CreateTest(name string, data []byte) (Test, error) {
return
t
,
nil
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
)
resp
,
err
:=
http
.
Get
(
uri
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
@@ -226,14 +228,20 @@ func CreateTests(uri string, cb func(Test)) {
...
@@ -226,14 +228,20 @@ func CreateTests(uri string, cb func(Test)) {
panic
(
err
)
panic
(
err
)
}
}
tests
:=
make
(
map
[
string
]
Test
)
for
name
,
testData
:=
range
objmap
{
for
name
,
testData
:=
range
objmap
{
test
,
err
:=
CreateTest
(
name
,
*
testData
)
test
,
err
:=
CreateTest
(
name
,
*
testData
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
}
}
cb
(
test
)
if
cb
!=
nil
{
cb
(
test
)
}
tests
[
name
]
=
test
}
}
return
tests
}
}
func
TestRemote
(
t
*
testing
.
T
)
{
func
TestRemote
(
t
*
testing
.
T
)
{
...
@@ -271,22 +279,52 @@ func TestTrieReplay(t *testing.T) {
...
@@ -271,22 +279,52 @@ func TestTrieReplay(t *testing.T) {
})
})
}
}
func
TestIt
(
t
*
testing
.
T
)
{
func
RandomData
()
[][]
string
{
_
,
trie
:=
New
()
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
{
roots
[
string
(
trie
.
Root
.
([]
byte
))]
+=
1
"0x000000000000000000000000ec4f34c97e43fbb2816cfd95e388353c7181dab1"
:
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
,
"0x0000000000000000000000000000000000000000000000000000000000000045"
:
"0x22b224a1420a802ab51d326e29fa98e34c4f24ea"
,
"0x0000000000000000000000000000000000000000000000000000000000000046"
:
"0x67706c2076330000000000000000000000000000000000000000000000000000"
,
"0x000000000000000000000000697c7b8c961b56f675d570498424ac8de1a918f6"
:
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
,
"0x0000000000000000000000007ef9e639e2733cb34e4dfc576d4b23f72db776b2"
:
"0x4655474156000000000000000000000000000000000000000000000000000000"
,
"0x6f6f6f6820736f2067726561742c207265616c6c6c793f000000000000000000"
:
"0x697c7b8c961b56f675d570498424ac8de1a918f6"
,
"0x4655474156000000000000000000000000000000000000000000000000000000"
:
"0x7ef9e639e2733cb34e4dfc576d4b23f72db776b2"
,
"0x4e616d6552656700000000000000000000000000000000000000000000000000"
:
"0xec4f34c97e43fbb2816cfd95e388353c7181dab1"
,
}
}
for
k
,
v
:=
range
test
{
if
len
(
roots
)
>
1
{
trie
.
Update
(
k
,
v
)
for
root
,
num
:=
range
roots
{
t
.
Errorf
(
"%x => %d
\n
"
,
root
,
num
)
}
}
}
fmt
.
Printf
(
"root : %x
\n
"
,
trie
.
Root
)
}
}
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