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

38 lines
799 B
Go
Raw Normal View History

2018-01-30 10:56:36 +00:00
package payload
import (
"bytes"
"testing"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
2018-02-01 18:54:23 +00:00
. "github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
2018-01-30 10:56:36 +00:00
)
func TestInventoryEncodeDecode(t *testing.T) {
hashes := []Uint256{
hash.Sha256([]byte("a")),
hash.Sha256([]byte("b")),
2018-01-30 10:56:36 +00:00
}
inv := NewInventory(BlockType, hashes)
buf := new(bytes.Buffer)
err := inv.EncodeBinary(buf)
assert.Nil(t, err)
2018-01-30 10:56:36 +00:00
invDecode := &Inventory{}
err = invDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, inv, invDecode)
2018-01-30 10:56:36 +00:00
}
func TestEmptyInv(t *testing.T) {
msgInv := NewInventory(TXType, []Uint256{})
buf := new(bytes.Buffer)
err := msgInv.EncodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, []byte{byte(TXType), 0}, buf.Bytes())
assert.Equal(t, 0, len(msgInv.Hashes))
}