mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-24 09:25:21 +00:00
32 lines
605 B
Go
32 lines
605 B
Go
package payload
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha256"
|
|
"reflect"
|
|
"testing"
|
|
|
|
. "github.com/anthdm/neo-go/pkg/util"
|
|
)
|
|
|
|
func TestInventoryEncodeDecode(t *testing.T) {
|
|
hashes := []Uint256{
|
|
sha256.Sum256([]byte("a")),
|
|
sha256.Sum256([]byte("b")),
|
|
}
|
|
inv := NewInventory(BlockType, hashes)
|
|
|
|
buf := new(bytes.Buffer)
|
|
if err := inv.EncodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
invDecode := &Inventory{}
|
|
if err := invDecode.DecodeBinary(buf); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(inv, invDecode) {
|
|
t.Fatalf("expected both inventories to be equal %v and %v", inv, invDecode)
|
|
}
|
|
}
|