mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-04 19:19:44 +00:00
9abda40171
Frequently one needs to check if struct serializes/deserializes properly. This commit implements helpers for such cases including: 1. JSON 2. io.Serializable interface
29 lines
686 B
Go
29 lines
686 B
Go
package payload
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
|
. "github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestInventoryEncodeDecode(t *testing.T) {
|
|
hashes := []Uint256{
|
|
hash.Sha256([]byte("a")),
|
|
hash.Sha256([]byte("b")),
|
|
}
|
|
inv := NewInventory(BlockType, hashes)
|
|
|
|
testserdes.EncodeDecodeBinary(t, inv, new(Inventory))
|
|
}
|
|
|
|
func TestEmptyInv(t *testing.T) {
|
|
msgInv := NewInventory(TXType, []Uint256{})
|
|
|
|
data, err := testserdes.EncodeBinary(msgInv)
|
|
assert.Nil(t, err)
|
|
assert.Equal(t, []byte{byte(TXType), 0}, data)
|
|
assert.Equal(t, 0, len(msgInv.Hashes))
|
|
}
|