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
25bc8811
Commit
25bc8811
authored
May 03, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eth/downloader: added additional tests
parent
c6ad3aec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
4 deletions
+73
-4
downloader_test.go
eth/downloader/downloader_test.go
+11
-4
queue_test.go
eth/downloader/queue_test.go
+62
-0
No files found.
eth/downloader/downloader_test.go
View file @
25bc8811
...
...
@@ -23,12 +23,19 @@ func createHashes(start, amount int) (hashes []common.Hash) {
return
}
func
createBlock
(
i
int
,
prevHash
,
hash
common
.
Hash
)
*
types
.
Block
{
header
:=
&
types
.
Header
{
Number
:
big
.
NewInt
(
int64
(
i
))}
block
:=
types
.
NewBlockWithHeader
(
header
)
block
.
HeaderHash
=
hash
block
.
ParentHeaderHash
=
knownHash
return
block
}
func
createBlocksFromHashes
(
hashes
[]
common
.
Hash
)
map
[
common
.
Hash
]
*
types
.
Block
{
blocks
:=
make
(
map
[
common
.
Hash
]
*
types
.
Block
)
for
i
,
hash
:=
range
hashes
{
header
:=
&
types
.
Header
{
Number
:
big
.
NewInt
(
int64
(
len
(
hashes
)
-
i
))}
blocks
[
hash
]
=
types
.
NewBlockWithHeader
(
header
)
blocks
[
hash
]
.
HeaderHash
=
hash
blocks
[
hash
]
=
createBlock
(
len
(
hashes
)
-
i
,
knownHash
,
hash
)
}
return
blocks
...
...
@@ -162,7 +169,7 @@ func TestTaking(t *testing.T) {
t
.
Error
(
"download error"
,
err
)
}
bs1
:=
tester
.
downloader
.
TakeBlocks
(
1000
)
bs1
:=
tester
.
downloader
.
TakeBlocks
()
if
len
(
bs1
)
!=
1000
{
t
.
Error
(
"expected to take 1000, got"
,
len
(
bs1
))
}
...
...
eth/downloader/queue_test.go
0 → 100644
View file @
25bc8811
package
downloader
import
(
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"gopkg.in/fatih/set.v0"
)
func
createHashSet
(
hashes
[]
common
.
Hash
)
*
set
.
Set
{
hset
:=
set
.
New
()
for
_
,
hash
:=
range
hashes
{
hset
.
Add
(
hash
)
}
return
hset
}
func
createBlocksFromHashSet
(
hashes
*
set
.
Set
)
[]
*
types
.
Block
{
blocks
:=
make
([]
*
types
.
Block
,
hashes
.
Size
())
var
i
int
hashes
.
Each
(
func
(
v
interface
{})
bool
{
blocks
[
i
]
=
createBlock
(
i
,
common
.
Hash
{},
v
.
(
common
.
Hash
))
i
++
return
true
})
return
blocks
}
func
TestChunking
(
t
*
testing
.
T
)
{
queue
:=
newqueue
()
peer1
:=
newPeer
(
"peer1"
,
common
.
Hash
{},
nil
,
nil
)
peer2
:=
newPeer
(
"peer2"
,
common
.
Hash
{},
nil
,
nil
)
// 99 + 1 (1 == known genesis hash)
hashes
:=
createHashes
(
0
,
99
)
hashSet
:=
createHashSet
(
hashes
)
queue
.
put
(
hashSet
)
chunk1
:=
queue
.
get
(
peer1
,
99
)
if
chunk1
==
nil
{
t
.
Errorf
(
"chunk1 is nil"
)
t
.
FailNow
()
}
chunk2
:=
queue
.
get
(
peer2
,
99
)
if
chunk2
==
nil
{
t
.
Errorf
(
"chunk2 is nil"
)
t
.
FailNow
()
}
if
chunk1
.
hashes
.
Size
()
!=
99
{
t
.
Error
(
"expected chunk1 hashes to be 99, got"
,
chunk1
.
hashes
.
Size
())
}
if
chunk2
.
hashes
.
Size
()
!=
1
{
t
.
Error
(
"expected chunk1 hashes to be 1, got"
,
chunk2
.
hashes
.
Size
())
}
}
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