2018-01-27 15:00:28 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestVersionEncodeDecode(t *testing.T) {
|
2018-01-31 08:27:08 +00:00
|
|
|
version := NewVersion(13337, 3000, "/NEO:0.0.1/", 0, true)
|
2018-01-27 15:00:28 +00:00
|
|
|
|
|
|
|
buf := new(bytes.Buffer)
|
2018-01-28 15:06:41 +00:00
|
|
|
if err := version.EncodeBinary(buf); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
versionDecoded := &Version{}
|
|
|
|
if err := versionDecoded.DecodeBinary(buf); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-27 15:00:28 +00:00
|
|
|
|
2018-01-28 15:06:41 +00:00
|
|
|
if !reflect.DeepEqual(version, versionDecoded) {
|
|
|
|
t.Fatalf("expected both version payload to be equal: %+v and %+v", version, versionDecoded)
|
|
|
|
}
|
2018-01-27 15:00:28 +00:00
|
|
|
|
2018-01-28 15:06:41 +00:00
|
|
|
if version.Size() != uint32(minVersionSize+len(version.UserAgent)) {
|
2018-01-31 08:27:08 +00:00
|
|
|
t.Fatalf("Expected version size of %d", minVersionSize+len(version.UserAgent))
|
2018-01-27 15:00:28 +00:00
|
|
|
}
|
|
|
|
}
|