neoneo-go/pkg/network/payload/version_test.go

36 lines
915 B
Go
Raw Normal View History

2018-01-27 15:00:28 +00:00
package payload
import (
"testing"
"github.com/CityOfZion/neo-go/pkg/io"
"github.com/stretchr/testify/assert"
2018-01-27 15:00:28 +00:00
)
func TestVersionEncodeDecode(t *testing.T) {
var port uint16 = 3000
var id uint32 = 13337
useragent := "/NEO:0.0.1/"
var height uint32 = 100500
var relay = true
version := NewVersion(id, port, useragent, height, relay)
2018-01-27 15:00:28 +00:00
buf := io.NewBufBinWriter()
err := version.EncodeBinary(buf.BinWriter)
assert.Nil(t, err)
b := buf.Bytes()
assert.Equal(t, int(version.Size()), len(b))
r := io.NewBinReaderFromBuf(b)
2018-01-28 15:06:41 +00:00
versionDecoded := &Version{}
err = versionDecoded.DecodeBinary(r)
assert.Nil(t, err)
assert.Equal(t, versionDecoded.Nonce, id)
assert.Equal(t, versionDecoded.Port, port)
assert.Equal(t, versionDecoded.UserAgent, []byte(useragent))
assert.Equal(t, versionDecoded.StartHeight, height)
assert.Equal(t, versionDecoded.Relay, relay)
assert.Equal(t, version, versionDecoded)
2018-01-27 15:00:28 +00:00
}