payload: fix tests to use asserts

Like in 483b875f4a.
This commit is contained in:
Roman Khimov 2019-08-29 17:33:53 +03:00
parent c949d2ec53
commit 2e3172f8a5
5 changed files with 34 additions and 59 deletions

View file

@ -17,14 +17,12 @@ func TestEncodeDecodeAddress(t *testing.T) {
buf = new(bytes.Buffer)
)
if err := addr.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := addr.EncodeBinary(buf)
assert.Nil(t, err)
addrDecode := &AddressAndTime{}
if err := addrDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
err = addrDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, addr, addrDecode)
}
@ -38,14 +36,12 @@ func TestEncodeDecodeAddressList(t *testing.T) {
}
buf := new(bytes.Buffer)
if err := addrList.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := addrList.EncodeBinary(buf)
assert.Nil(t, err)
addrListDecode := &AddressList{}
if err := addrListDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
err = addrListDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, addrList, addrListDecode)
}

View file

@ -19,15 +19,12 @@ func TestGetBlockEncodeDecode(t *testing.T) {
p := NewGetBlocks(start, util.Uint256{})
buf := new(bytes.Buffer)
if err := p.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := p.EncodeBinary(buf)
assert.Nil(t, err)
pDecode := &GetBlocks{}
if err := pDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
err = pDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, p, pDecode)
}
@ -43,14 +40,11 @@ func TestGetBlockEncodeDecodeWithHashStop(t *testing.T) {
)
p := NewGetBlocks(start, stop)
buf := new(bytes.Buffer)
if err := p.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := p.EncodeBinary(buf)
assert.Nil(t, err)
pDecode := &GetBlocks{}
if err := pDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
err = pDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, p, pDecode)
}

View file

@ -41,14 +41,12 @@ func TestHeadersEncodeDecode(t *testing.T) {
}}
buf := new(bytes.Buffer)
if err := headers.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := headers.EncodeBinary(buf)
assert.Nil(t, err)
headersDecode := &Headers{}
if err := headersDecode.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
err = headersDecode.DecodeBinary(buf)
assert.Nil(t, err)
for i := 0; i < len(headers.Hdrs); i++ {
assert.Equal(t, headers.Hdrs[i].Version, headersDecode.Hdrs[i].Version)

View file

@ -2,11 +2,11 @@ package payload
import (
"bytes"
"reflect"
"testing"
"github.com/CityOfZion/neo-go/pkg/crypto/hash"
. "github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
)
func TestInventoryEncodeDecode(t *testing.T) {
@ -17,16 +17,11 @@ func TestInventoryEncodeDecode(t *testing.T) {
inv := NewInventory(BlockType, hashes)
buf := new(bytes.Buffer)
if err := inv.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
err := inv.EncodeBinary(buf)
assert.Nil(t, 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)
}
err = invDecode.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, inv, invDecode)
}

View file

@ -2,29 +2,21 @@ package payload
import (
"bytes"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestVersionEncodeDecode(t *testing.T) {
version := NewVersion(13337, 3000, "/NEO:0.0.1/", 0, true)
buf := new(bytes.Buffer)
if err := version.EncodeBinary(buf); err != nil {
t.Fatal(err)
}
if int(version.Size()) != buf.Len() {
t.Fatalf("Expected version size of %d", buf.Len())
}
err := version.EncodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, int(version.Size()), buf.Len())
versionDecoded := &Version{}
if err := versionDecoded.DecodeBinary(buf); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(version, versionDecoded) {
t.Fatalf("expected both version payload to be equal: %+v and %+v", version, versionDecoded)
}
err = versionDecoded.DecodeBinary(buf)
assert.Nil(t, err)
assert.Equal(t, version, versionDecoded)
}