Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
vicotor
mybee
Commits
f66a687a
Commit
f66a687a
authored
Jan 24, 2020
by
Petar Radovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial handhsake tests
parent
1971bae2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
77 additions
and
0 deletions
+77
-0
handshake_test.go
pkg/p2p/libp2p/internal/handshake/handshake_test.go
+77
-0
No files found.
pkg/p2p/libp2p/internal/handshake/handshake_test.go
0 → 100644
View file @
f66a687a
package
handshake
import
(
"bytes"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p/protobuf"
"io/ioutil"
"testing"
)
type
StreamMock
struct
{
Buffer
bytes
.
Buffer
}
func
(
s
*
StreamMock
)
Read
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
Buffer
.
Read
(
p
)
}
func
(
s
*
StreamMock
)
Write
(
p
[]
byte
)
(
n
int
,
err
error
)
{
return
s
.
Buffer
.
Write
(
p
)
}
func
(
s
*
StreamMock
)
Close
()
error
{
panic
(
"stream.Close() should not be called"
)
}
func
TestHandshake
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
)
info
:=
Info
{
Address
:
"node1"
,
NetworkID
:
0
,
Light
:
false
,
}
handshakeService
:=
New
(
info
.
Address
,
info
.
NetworkID
,
logger
)
t
.
Run
(
"OK"
,
func
(
t
*
testing
.
T
)
{
stream
:=
&
StreamMock
{}
res
,
err
:=
handshakeService
.
Handshake
(
stream
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
*
res
!=
info
{
t
.
Fatalf
(
"got %+v, expected %+v"
,
res
,
info
)
}
})
}
func
TestHandle
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
)
handshakeService
:=
New
(
"node1"
,
0
,
logger
)
t
.
Run
(
"OK"
,
func
(
t
*
testing
.
T
)
{
stream
:=
&
StreamMock
{}
w
,
_
:=
protobuf
.
NewWriterAndReader
(
stream
)
info
:=
Info
{
Address
:
"node2"
,
NetworkID
:
1
,
Light
:
false
,
}
w
.
WriteMsg
(
&
ShakeHand
{
Address
:
info
.
Address
,
NetworkID
:
info
.
NetworkID
,
Light
:
info
.
Light
,
})
res
,
err
:=
handshakeService
.
Handshake
(
stream
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
*
res
!=
info
{
t
.
Fatalf
(
"got %+v, expected %+v"
,
res
,
info
)
}
})
}
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