Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
e14f832e
Commit
e14f832e
authored
Jan 20, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
3d99bbc2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
2 deletions
+30
-2
t/neo/proto_test.go
t/neo/proto_test.go
+30
-2
No files found.
t/neo/proto_test.go
View file @
e14f832e
...
@@ -17,7 +17,10 @@ package neo
...
@@ -17,7 +17,10 @@ package neo
import
(
import
(
hexpkg
"encoding/hex"
hexpkg
"encoding/hex"
"encoding/binary"
"encoding/binary"
"fmt"
"reflect"
"reflect"
"runtime"
"strings"
"testing"
"testing"
"unsafe"
"unsafe"
)
)
...
@@ -65,6 +68,7 @@ type NEOCodec interface {
...
@@ -65,6 +68,7 @@ type NEOCodec interface {
NEODecoder
NEODecoder
}
}
// test marshalling for one packet type
// test marshalling for one packet type
func
testPktMarshal
(
t
*
testing
.
T
,
pkt
NEOCodec
,
encoded
string
)
{
func
testPktMarshal
(
t
*
testing
.
T
,
pkt
NEOCodec
,
encoded
string
)
{
typ
:=
reflect
.
TypeOf
(
pkt
)
.
Elem
()
// type of *pkt
typ
:=
reflect
.
TypeOf
(
pkt
)
.
Elem
()
// type of *pkt
...
@@ -90,8 +94,32 @@ func testPktMarshal(t *testing.T, pkt NEOCodec, encoded string) {
...
@@ -90,8 +94,32 @@ func testPktMarshal(t *testing.T, pkt NEOCodec, encoded string) {
t
.
Errorf
(
"
\t
want: %s"
,
hexpkg
.
EncodeToString
([]
byte
(
encoded
)))
t
.
Errorf
(
"
\t
want: %s"
,
hexpkg
.
EncodeToString
([]
byte
(
encoded
)))
}
}
// TODO encode - check == encoded
// encode must panic if passed a smaller buffer
// TODO encode(smaller buf) -> panic
for
l
:=
len
(
buf
)
-
1
;
l
>=
0
;
l
--
{
func
()
{
defer
func
()
{
subj
:=
fmt
.
Sprintf
(
"%v: encode(buf[:encodedLen-%v])"
,
typ
,
len
(
encoded
)
-
l
)
e
:=
recover
()
if
e
==
nil
{
t
.
Errorf
(
"%s did not panic"
,
subj
)
return
}
err
,
ok
:=
e
.
(
runtime
.
Error
)
if
!
ok
{
t
.
Errorf
(
"%s panic(%#v) ; want runtime.Error"
,
subj
,
e
)
}
estr
:=
err
.
Error
()
if
!
(
strings
.
Contains
(
estr
,
"slice bounds out of range"
)
||
strings
.
Contains
(
estr
,
"index out of range"
))
{
t
.
Errorf
(
"%s unexpected runtime panic: %v"
,
subj
,
estr
)
}
}()
pkt
.
NEOEncode
(
buf
[
:
l
])
}()
}
// check decoding
// check decoding
data
:=
encoded
+
"noise"
data
:=
encoded
+
"noise"
...
...
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