neoneo-go/pkg/network/payload/inventory_test.go
Roman Khimov ec7e17ffa6 pkg: make use of the new crypto/hash package
Simplifies a lot of code and removes some duplication. Unfortunately I had to
move test_util random functions in same commit to avoid cycle
dependencies. One of these random functions was also used in core/transaction
testing, to simplify things I've just dropped it there and used a static
string (which is nice to have for a test anyway).

There is still sha256 left in wallet (but it needs to pass Hash structure into
the signing function).
2019-08-26 13:32:19 +03:00

32 lines
636 B
Go

package payload
import (
"bytes"
"reflect"
"testing"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
. "github.com/CityOfZion/neo-go/pkg/util"
)
func TestInventoryEncodeDecode(t *testing.T) {
hashes := []Uint256{
hash.Sha256([]byte("a")),
hash.Sha256([]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)
}
}