2020-01-17 10:17:19 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
2020-01-17 10:17:19 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEncodeDecodeBinary(t *testing.T) {
|
|
|
|
payload := NewPing(uint32(1), uint32(2))
|
|
|
|
assert.NotEqual(t, 0, payload.Timestamp)
|
|
|
|
|
|
|
|
bufBinWriter := io.NewBufBinWriter()
|
|
|
|
payload.EncodeBinary(bufBinWriter.BinWriter)
|
|
|
|
assert.Nil(t, bufBinWriter.Err)
|
|
|
|
|
|
|
|
binReader := io.NewBinReaderFromBuf(bufBinWriter.Bytes())
|
|
|
|
decodedPing := &Ping{}
|
|
|
|
decodedPing.DecodeBinary(binReader)
|
|
|
|
assert.Nil(t, binReader.Err)
|
|
|
|
|
|
|
|
assert.Equal(t, uint32(1), decodedPing.LastBlockIndex)
|
|
|
|
assert.Equal(t, uint32(2), decodedPing.Nonce)
|
|
|
|
}
|