2018-01-30 10:56:36 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-03 14:21:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
|
|
. "github.com/nspcc-dev/neo-go/pkg/util"
|
2019-08-29 14:33:53 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-01-30 10:56:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestInventoryEncodeDecode(t *testing.T) {
|
|
|
|
hashes := []Uint256{
|
2019-08-23 15:50:45 +00:00
|
|
|
hash.Sha256([]byte("a")),
|
|
|
|
hash.Sha256([]byte("b")),
|
2018-01-30 10:56:36 +00:00
|
|
|
}
|
|
|
|
inv := NewInventory(BlockType, hashes)
|
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
inv.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2018-01-30 10:56:36 +00:00
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
b := buf.Bytes()
|
|
|
|
r := io.NewBinReaderFromBuf(b)
|
2018-01-30 10:56:36 +00:00
|
|
|
invDecode := &Inventory{}
|
2019-09-16 16:31:49 +00:00
|
|
|
invDecode.DecodeBinary(r)
|
|
|
|
assert.Nil(t, r.Err)
|
2019-08-29 14:33:53 +00:00
|
|
|
assert.Equal(t, inv, invDecode)
|
2018-01-30 10:56:36 +00:00
|
|
|
}
|
2019-08-29 17:27:16 +00:00
|
|
|
|
|
|
|
func TestEmptyInv(t *testing.T) {
|
|
|
|
msgInv := NewInventory(TXType, []Uint256{})
|
|
|
|
|
2019-09-16 09:18:13 +00:00
|
|
|
buf := io.NewBufBinWriter()
|
2019-09-16 16:31:49 +00:00
|
|
|
msgInv.EncodeBinary(buf.BinWriter)
|
|
|
|
assert.Nil(t, buf.Err)
|
2019-08-29 17:27:16 +00:00
|
|
|
assert.Equal(t, []byte{byte(TXType), 0}, buf.Bytes())
|
|
|
|
assert.Equal(t, 0, len(msgInv.Hashes))
|
|
|
|
}
|