neoneo-go/pkg/network/payload/version_test.go
Roman Khimov c949d2ec53 payload: fix Size() calculation for version
UserAgent is variable-length-encoded. Fix associated test.
2019-08-29 21:23:57 +03:00

30 lines
615 B
Go

package payload
import (
"bytes"
"reflect"
"testing"
)
func TestVersionEncodeDecode(t *testing.T) {
version := NewVersion(13337, 3000, "/NEO:0.0.1/", 0, true)
buf := new(bytes.Buffer)
if err := version.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
if int(version.Size()) != buf.Len() {
t.Fatalf("Expected version size of %d", buf.Len())
}
versionDecoded := &Version{}
if err := versionDecoded.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(version, versionDecoded) {
t.Fatalf("expected both version payload to be equal: %+v and %+v", version, versionDecoded)
}
}