mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
core: do not rewrite binreader error for bad Conflicts attr
We should keep the original BinReader error untouched in case if it is exists.
This commit is contained in:
parent
b00eb51c55
commit
8548786444
2 changed files with 26 additions and 8 deletions
|
@ -7,6 +7,8 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/random"
|
"github.com/nspcc-dev/neo-go/internal/random"
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ func TestAttribute_EncodeBinary(t *testing.T) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
t.Run("Conflicts", func(t *testing.T) {
|
t.Run("Conflicts", func(t *testing.T) {
|
||||||
|
t.Run("positive", func(t *testing.T) {
|
||||||
attr := &Attribute{
|
attr := &Attribute{
|
||||||
Type: ConflictsT,
|
Type: ConflictsT,
|
||||||
Value: &Conflicts{
|
Value: &Conflicts{
|
||||||
|
@ -69,6 +72,17 @@ func TestAttribute_EncodeBinary(t *testing.T) {
|
||||||
}
|
}
|
||||||
testserdes.EncodeDecodeBinary(t, attr, new(Attribute))
|
testserdes.EncodeDecodeBinary(t, attr, new(Attribute))
|
||||||
})
|
})
|
||||||
|
t.Run("negative: too long", func(t *testing.T) {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
bw.WriteVarBytes(make([]byte, util.Uint256Size+1))
|
||||||
|
require.Error(t, testserdes.DecodeBinary(bw.Bytes(), new(Conflicts)))
|
||||||
|
})
|
||||||
|
t.Run("negative: bad uint256", func(t *testing.T) {
|
||||||
|
bw := io.NewBufBinWriter()
|
||||||
|
bw.WriteVarBytes(make([]byte, util.Uint256Size-1))
|
||||||
|
require.Error(t, testserdes.DecodeBinary(bw.Bytes(), new(Conflicts)))
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAttribute_MarshalJSON(t *testing.T) {
|
func TestAttribute_MarshalJSON(t *testing.T) {
|
||||||
|
|
|
@ -12,7 +12,11 @@ type Conflicts struct {
|
||||||
|
|
||||||
// DecodeBinary implements io.Serializable interface.
|
// DecodeBinary implements io.Serializable interface.
|
||||||
func (c *Conflicts) DecodeBinary(br *io.BinReader) {
|
func (c *Conflicts) DecodeBinary(br *io.BinReader) {
|
||||||
hash, err := util.Uint256DecodeBytesBE(br.ReadVarBytes(util.Uint256Size))
|
bytes := br.ReadVarBytes(util.Uint256Size)
|
||||||
|
if br.Err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hash, err := util.Uint256DecodeBytesBE(bytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
br.Err = err
|
br.Err = err
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue