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
a085dd80
Commit
a085dd80
authored
Jan 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X start of decode tests
parent
3d4bc65f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
t/neo/proto.go
t/neo/proto.go
+1
-1
t/neo/proto_test.go
t/neo/proto_test.go
+41
-0
No files found.
t/neo/proto.go
View file @
a085dd80
...
...
@@ -101,7 +101,7 @@ type NEOEncoder interface {
// NEODecoder is interface for unmarshalling objects from wire format in NEO
type
NEODecoder
interface
{
NEODecode
(
data
[]
byte
)
(
nread
int
)
NEODecode
(
data
[]
byte
)
(
nread
int
,
err
error
)
}
type
Address
struct
{
...
...
t/neo/proto_test.go
View file @
a085dd80
...
...
@@ -15,6 +15,7 @@
package
neo
import
(
"reflect"
"testing"
"unsafe"
)
...
...
@@ -25,3 +26,43 @@ func TestPktHeader(t *testing.T) {
t
.
Fatalf
(
"sizeof(PktHead) = %v ; want 10"
,
unsafe
.
Sizeof
(
PktHead
{}))
}
}
// test encoding/decoding of packets
func
TestPktMarshal
(
t
*
testing
.
T
)
{
var
testv
=
[]
struct
{
pkt
NEODecoder
//interface {NEOEncoder; NEODecoder}
encoded
string
// []byte
}
{
{
&
Ping
{},
""
},
{
&
Error
{
Code
:
0x01020304
,
Message
:
"hello"
},
"
\x01\x02\x03\x04\x05
hello"
},
}
for
_
,
tt
:=
range
testv
{
// TODO check encoding
// check decoding
data
:=
tt
.
encoded
+
"noise"
typ
:=
reflect
.
TypeOf
(
tt
.
pkt
)
.
Elem
()
// type of *pkt
pkt2
:=
reflect
.
New
(
typ
)
.
Interface
()
.
(
NEODecoder
)
n
,
err
:=
pkt2
.
NEODecode
([]
byte
(
data
))
// XXX
if
err
!=
nil
{
t
.
Errorf
(
"%v: decode error %v"
,
typ
,
err
)
}
if
n
!=
len
(
tt
.
encoded
)
{
t
.
Errorf
(
"%v: nread = %v ; want %v"
,
typ
,
n
,
len
(
tt
.
encoded
))
}
}
/*
// empty
pkt := Ping{}
n, err := pkt.NEODecode([]byte{})
if !(n==0 && err==nil) { t.Fatal("zzz") }
// uint32 + string
pkt := Error{}
n, err := pkt.NEODecode([]byte{"\x01\x02\x03\x04\x05helloworld"})
n == 10 && err == nil
pkt.Code == 0x01020304
pkt.Message == "hello"
*/
}
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