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
07c12f0b
Commit
07c12f0b
authored
Feb 15, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added trie tests, value tests
parent
5883446b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
3 deletions
+103
-3
trie_test.go
ethutil/trie_test.go
+61
-3
value.go
ethutil/value.go
+4
-0
value_test.go
ethutil/value_test.go
+38
-0
No files found.
ethutil/trie_test.go
View file @
07c12f0b
...
...
@@ -6,6 +6,8 @@ import (
"testing"
)
const
LONG_WORD
=
"1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"
type
MemDatabase
struct
{
db
map
[
string
][]
byte
}
...
...
@@ -24,11 +26,15 @@ func (db *MemDatabase) Print() {}
func
(
db
*
MemDatabase
)
Close
()
{}
func
(
db
*
MemDatabase
)
LastKnownTD
()
[]
byte
{
return
nil
}
func
TestTrieSync
(
t
*
testing
.
T
)
{
func
New
()
(
*
MemDatabase
,
*
Trie
)
{
db
,
_
:=
NewMemDatabase
()
trie
:=
NewTrie
(
db
,
""
)
return
db
,
NewTrie
(
db
,
""
)
}
trie
.
Update
(
"dog"
,
"kindofalongsentencewhichshouldbeencodedinitsentirety"
)
func
TestTrieSync
(
t
*
testing
.
T
)
{
db
,
trie
:=
New
()
trie
.
Update
(
"dog"
,
LONG_WORD
)
if
len
(
db
.
db
)
!=
0
{
t
.
Error
(
"Expected no data in database"
)
}
...
...
@@ -38,3 +44,55 @@ func TestTrieSync(t *testing.T) {
t
.
Error
(
"Expected data to be persisted"
)
}
}
func
TestTrieReset
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
trie
.
Update
(
"cat"
,
LONG_WORD
)
if
len
(
trie
.
cache
.
nodes
)
==
0
{
t
.
Error
(
"Expected cached nodes"
)
}
trie
.
cache
.
Undo
()
if
len
(
trie
.
cache
.
nodes
)
!=
0
{
t
.
Error
(
"Expected no nodes after undo"
)
}
}
func
TestTrieGet
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
trie
.
Update
(
"cat"
,
LONG_WORD
)
x
:=
trie
.
Get
(
"cat"
)
if
x
!=
LONG_WORD
{
t
.
Error
(
"expected %s, got %s"
,
LONG_WORD
,
x
)
}
}
func
TestTrieUpdating
(
t
*
testing
.
T
)
{
_
,
trie
:=
New
()
trie
.
Update
(
"cat"
,
LONG_WORD
)
trie
.
Update
(
"cat"
,
LONG_WORD
+
"1"
)
x
:=
trie
.
Get
(
"cat"
)
if
x
!=
LONG_WORD
+
"1"
{
t
.
Error
(
"expected %S, got %s"
,
LONG_WORD
+
"1"
,
x
)
}
}
func
TestTrieCmp
(
t
*
testing
.
T
)
{
_
,
trie1
:=
New
()
_
,
trie2
:=
New
()
trie1
.
Update
(
"doge"
,
LONG_WORD
)
trie2
.
Update
(
"doge"
,
LONG_WORD
)
if
!
trie1
.
Cmp
(
trie2
)
{
t
.
Error
(
"Expected tries to be equal"
)
}
trie1
.
Update
(
"dog"
,
LONG_WORD
)
trie2
.
Update
(
"cat"
,
LONG_WORD
)
if
trie1
.
Cmp
(
trie2
)
{
t
.
Errorf
(
"Expected tries not to be equal %x %x"
,
trie1
.
Root
,
trie2
.
Root
)
}
}
ethutil/value.go
View file @
07c12f0b
...
...
@@ -60,6 +60,10 @@ func (val *Value) Uint() uint64 {
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint64
);
ok
{
return
Val
}
else
if
Val
,
ok
:=
val
.
Val
.
(
int
);
ok
{
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
(
uint
);
ok
{
return
uint64
(
Val
)
}
else
if
Val
,
ok
:=
val
.
Val
.
([]
byte
);
ok
{
return
ReadVarint
(
bytes
.
NewReader
(
Val
))
}
...
...
ethutil/value_test.go
0 → 100644
View file @
07c12f0b
package
ethutil
import
(
"testing"
)
func
TestValueCmp
(
t
*
testing
.
T
)
{
val1
:=
NewValue
(
"hello"
)
val2
:=
NewValue
(
"world"
)
if
val1
.
Cmp
(
val2
)
{
t
.
Error
(
"Expected values not to be equal"
)
}
val3
:=
NewValue
(
"hello"
)
val4
:=
NewValue
(
"hello"
)
if
!
val3
.
Cmp
(
val4
)
{
t
.
Error
(
"Expected values to be equal"
)
}
}
func
TestValueTypes
(
t
*
testing
.
T
)
{
str
:=
NewValue
(
"str"
)
num
:=
NewValue
(
1
)
inter
:=
NewValue
([]
interface
{}{
1
})
if
str
.
Str
()
!=
"str"
{
t
.
Errorf
(
"expected Str to return 'str', got %s"
,
str
.
Str
())
}
if
num
.
Uint
()
!=
1
{
t
.
Errorf
(
"expected Uint to return '1', got %d"
,
num
.
Uint
())
}
exp
:=
[]
interface
{}{
1
}
if
!
NewValue
(
inter
.
Interface
())
.
Cmp
(
NewValue
(
exp
))
{
t
.
Errorf
(
"expected Interface to return '%v', got %v"
,
exp
,
num
.
Interface
())
}
}
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