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/testserdes"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -61,13 +63,25 @@ func TestAttribute_EncodeBinary(t *testing.T) {
|
|||
})
|
||||
})
|
||||
t.Run("Conflicts", func(t *testing.T) {
|
||||
attr := &Attribute{
|
||||
Type: ConflictsT,
|
||||
Value: &Conflicts{
|
||||
Hash: random.Uint256(),
|
||||
},
|
||||
}
|
||||
testserdes.EncodeDecodeBinary(t, attr, new(Attribute))
|
||||
t.Run("positive", func(t *testing.T) {
|
||||
attr := &Attribute{
|
||||
Type: ConflictsT,
|
||||
Value: &Conflicts{
|
||||
Hash: random.Uint256(),
|
||||
},
|
||||
}
|
||||
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)))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,11 @@ type Conflicts struct {
|
|||
|
||||
// DecodeBinary implements io.Serializable interface.
|
||||
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 {
|
||||
br.Err = err
|
||||
return
|
||||
|
|
Loading…
Reference in a new issue