2018-01-30 10:56:36 +00:00
|
|
|
package payload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2019-08-23 15:50:45 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
|
2018-02-01 18:54:23 +00:00
|
|
|
. "github.com/CityOfZion/neo-go/pkg/util"
|
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)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|