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

View file

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

View file

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

View file

@ -2,11 +2,11 @@ package payload
import ( import (
"bytes" "bytes"
"reflect"
"testing" "testing"
"github.com/CityOfZion/neo-go/pkg/crypto/hash" "github.com/CityOfZion/neo-go/pkg/crypto/hash"
. "github.com/CityOfZion/neo-go/pkg/util" . "github.com/CityOfZion/neo-go/pkg/util"
"github.com/stretchr/testify/assert"
) )
func TestInventoryEncodeDecode(t *testing.T) { func TestInventoryEncodeDecode(t *testing.T) {
@ -17,16 +17,11 @@ func TestInventoryEncodeDecode(t *testing.T) {
inv := NewInventory(BlockType, hashes) inv := NewInventory(BlockType, hashes)
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
if err := inv.EncodeBinary(buf); err != nil { err := inv.EncodeBinary(buf)
t.Fatal(err) assert.Nil(t, err)
}
invDecode := &Inventory{} invDecode := &Inventory{}
if err := invDecode.DecodeBinary(buf); err != nil { err = invDecode.DecodeBinary(buf)
t.Fatal(err) assert.Nil(t, err)
} assert.Equal(t, inv, invDecode)
if !reflect.DeepEqual(inv, invDecode) {
t.Fatalf("expected both inventories to be equal %v and %v", inv, invDecode)
}
} }

View file

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