Commit e14f832e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3d99bbc2
...@@ -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("\twant: %s", hexpkg.EncodeToString([]byte(encoded))) t.Errorf("\twant: %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"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment