Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
80492be0
Commit
80492be0
authored
Jan 15, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
baf7f580
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
11 deletions
+12
-11
go/neo/neonet/connection_test.go
go/neo/neonet/connection_test.go
+3
-2
go/neo/proto/proto_test.go
go/neo/proto/proto_test.go
+9
-9
No files found.
go/neo/neonet/connection_test.go
View file @
80492be0
...
@@ -132,6 +132,7 @@ func xconnError(err error) error {
...
@@ -132,6 +132,7 @@ func xconnError(err error) error {
// Prepare pktBuf with content.
// Prepare pktBuf with content.
func
_mkpkt
(
enc
proto
.
Encoding
,
connid
uint32
,
msgcode
uint16
,
payload
[]
byte
)
*
pktBuf
{
func
_mkpkt
(
enc
proto
.
Encoding
,
connid
uint32
,
msgcode
uint16
,
payload
[]
byte
)
*
pktBuf
{
// XXX -> enc.PktHeadEncode + enc.MsgEncode
switch
enc
{
switch
enc
{
case
'N'
:
case
'N'
:
pkt
:=
&
pktBuf
{
make
([]
byte
,
proto
.
PktHeaderLenN
+
len
(
payload
))}
pkt
:=
&
pktBuf
{
make
([]
byte
,
proto
.
PktHeaderLenN
+
len
(
payload
))}
...
@@ -185,8 +186,8 @@ func (t *T) xverifyPkt(pkt *pktBuf, connid uint32, msgcode uint16, payload []byt
...
@@ -185,8 +186,8 @@ func (t *T) xverifyPkt(pkt *pktBuf, connid uint32, msgcode uint16, payload []byt
// Verify pktBuf to match expected message.
// Verify pktBuf to match expected message.
func
(
t
*
T
)
xverifyPktMsg
(
pkt
*
pktBuf
,
connid
uint32
,
msg
proto
.
Msg
)
{
func
(
t
*
T
)
xverifyPktMsg
(
pkt
*
pktBuf
,
connid
uint32
,
msg
proto
.
Msg
)
{
data
:=
make
([]
byte
,
t
.
enc
.
NEO
MsgEncodedLen
(
msg
))
data
:=
make
([]
byte
,
t
.
enc
.
MsgEncodedLen
(
msg
))
t
.
enc
.
NEO
MsgEncode
(
msg
,
data
)
t
.
enc
.
MsgEncode
(
msg
,
data
)
t
.
xverifyPkt
(
pkt
,
connid
,
proto
.
MsgCode
(
msg
),
data
)
t
.
xverifyPkt
(
pkt
,
connid
,
proto
.
MsgCode
(
msg
),
data
)
}
}
...
...
go/neo/proto/proto_test.go
View file @
80492be0
...
@@ -92,7 +92,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
...
@@ -92,7 +92,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
// msg.encode() == expected
// msg.encode() == expected
msgCode
:=
msg
.
neoMsgCode
()
msgCode
:=
msg
.
neoMsgCode
()
n
:=
enc
.
NEO
MsgEncodedLen
(
msg
)
n
:=
enc
.
MsgEncodedLen
(
msg
)
msgType
:=
MsgType
(
msgCode
)
msgType
:=
MsgType
(
msgCode
)
if
msgType
!=
typ
{
if
msgType
!=
typ
{
t
.
Errorf
(
"%c/%v: msgCode = %v which corresponds to %v"
,
enc
,
typ
,
msgCode
,
msgType
)
t
.
Errorf
(
"%c/%v: msgCode = %v which corresponds to %v"
,
enc
,
typ
,
msgCode
,
msgType
)
...
@@ -102,7 +102,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
...
@@ -102,7 +102,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
}
}
buf
:=
make
([]
byte
,
n
)
buf
:=
make
([]
byte
,
n
)
enc
.
NEO
MsgEncode
(
msg
,
buf
)
enc
.
MsgEncode
(
msg
,
buf
)
if
string
(
buf
)
!=
encoded
{
if
string
(
buf
)
!=
encoded
{
t
.
Errorf
(
"%c/%v: encode result unexpected:"
,
enc
,
typ
)
t
.
Errorf
(
"%c/%v: encode result unexpected:"
,
enc
,
typ
)
t
.
Errorf
(
"
\t
have: %s"
,
hexpkg
.
EncodeToString
(
buf
))
t
.
Errorf
(
"
\t
have: %s"
,
hexpkg
.
EncodeToString
(
buf
))
...
@@ -132,13 +132,13 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
...
@@ -132,13 +132,13 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
}
}
}()
}()
enc
.
NEO
MsgEncode
(
msg
,
buf
[
:
l
])
enc
.
MsgEncode
(
msg
,
buf
[
:
l
])
}()
}()
}
}
// msg.decode() == expected
// msg.decode() == expected
data
:=
[]
byte
(
encoded
+
"noise"
)
data
:=
[]
byte
(
encoded
+
"noise"
)
n
,
err
:=
enc
.
NEO
MsgDecode
(
msg2
,
data
)
n
,
err
:=
enc
.
MsgDecode
(
msg2
,
data
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%c/%v: decode error %v"
,
enc
,
typ
,
err
)
t
.
Errorf
(
"%c/%v: decode error %v"
,
enc
,
typ
,
err
)
}
}
...
@@ -152,7 +152,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
...
@@ -152,7 +152,7 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
// decode must detect buffer overflow
// decode must detect buffer overflow
for
l
:=
len
(
encoded
)
-
1
;
l
>=
0
;
l
--
{
for
l
:=
len
(
encoded
)
-
1
;
l
>=
0
;
l
--
{
n
,
err
=
enc
.
NEO
MsgDecode
(
msg2
,
data
[
:
l
])
n
,
err
=
enc
.
MsgDecode
(
msg2
,
data
[
:
l
])
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
t
.
Errorf
(
"%c/%v: decode overflow not detected on [:%v]"
,
enc
,
typ
,
l
)
t
.
Errorf
(
"%c/%v: decode overflow not detected on [:%v]"
,
enc
,
typ
,
l
)
}
}
...
@@ -375,14 +375,14 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
...
@@ -375,14 +375,14 @@ func TestMsgMarshalAllOverflowLightly(t *testing.T) {
for
_
,
enc
:=
range
[]
Encoding
{
'N'
,
'M'
}
{
for
_
,
enc
:=
range
[]
Encoding
{
'N'
,
'M'
}
{
// zero-value for a type
// zero-value for a type
msg
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
Msg
)
msg
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
Msg
)
l
:=
enc
.
NEO
MsgEncodedLen
(
msg
)
l
:=
enc
.
MsgEncodedLen
(
msg
)
zerol
:=
make
([]
byte
,
l
)
zerol
:=
make
([]
byte
,
l
)
if
enc
!=
'N'
{
// M-encoding of zero-value is not all zeros
if
enc
!=
'N'
{
// M-encoding of zero-value is not all zeros
enc
.
NEO
MsgEncode
(
msg
,
zerol
)
enc
.
MsgEncode
(
msg
,
zerol
)
}
}
// decoding will turn nil slice & map into empty allocated ones.
// decoding will turn nil slice & map into empty allocated ones.
// we need it so that reflect.DeepEqual works for msg encode/decode comparison
// we need it so that reflect.DeepEqual works for msg encode/decode comparison
n
,
err
:=
enc
.
NEO
MsgDecode
(
msg
,
zerol
)
n
,
err
:=
enc
.
MsgDecode
(
msg
,
zerol
)
if
!
(
n
==
l
&&
err
==
nil
)
{
if
!
(
n
==
l
&&
err
==
nil
)
{
t
.
Errorf
(
"%c/%v: zero-decode unexpected: %v, %v ; want %v, nil"
,
enc
,
typ
,
n
,
err
,
l
)
t
.
Errorf
(
"%c/%v: zero-decode unexpected: %v, %v ; want %v, nil"
,
enc
,
typ
,
n
,
err
,
l
)
}
}
...
@@ -416,7 +416,7 @@ func TestMsgDecodeLenOverflow(t *testing.T) {
...
@@ -416,7 +416,7 @@ func TestMsgDecodeLenOverflow(t *testing.T) {
}
}
}()
}()
n
,
err
:=
enc
.
NEO
MsgDecode
(
tt
.
msg
,
data
)
n
,
err
:=
enc
.
MsgDecode
(
tt
.
msg
,
data
)
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
if
!
(
n
==
0
&&
err
==
ErrDecodeOverflow
)
{
t
.
Errorf
(
"%T: decode %x
\n
have: %d, %v
\n
want: %d, %v"
,
tt
.
msg
,
data
,
t
.
Errorf
(
"%T: decode %x
\n
have: %d, %v
\n
want: %d, %v"
,
tt
.
msg
,
data
,
n
,
err
,
0
,
ErrDecodeOverflow
)
n
,
err
,
0
,
ErrDecodeOverflow
)
...
...
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