mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 03:47:18 +00:00
commit
dffd87c6c8
4 changed files with 12 additions and 10 deletions
|
@ -55,7 +55,7 @@ type (
|
||||||
Error *Error `json:"error,omitempty"`
|
Error *Error `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Raw represents a standard raw JSON-RPC 2.0
|
// Response represents a standard raw JSON-RPC 2.0
|
||||||
// response: http://www.jsonrpc.org/specification#response_object.
|
// response: http://www.jsonrpc.org/specification#response_object.
|
||||||
Response struct {
|
Response struct {
|
||||||
HeaderAndError
|
HeaderAndError
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
. "github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInventoryEncodeDecode(t *testing.T) {
|
func TestInventoryEncodeDecode(t *testing.T) {
|
||||||
hashes := []Uint256{
|
hashes := []util.Uint256{
|
||||||
hash.Sha256([]byte("a")),
|
hash.Sha256([]byte("a")),
|
||||||
hash.Sha256([]byte("b")),
|
hash.Sha256([]byte("b")),
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func TestInventoryEncodeDecode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyInv(t *testing.T) {
|
func TestEmptyInv(t *testing.T) {
|
||||||
msgInv := NewInventory(TXType, []Uint256{})
|
msgInv := NewInventory(TXType, []util.Uint256{})
|
||||||
|
|
||||||
data, err := testserdes.EncodeBinary(msgInv)
|
data, err := testserdes.EncodeBinary(msgInv)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
@ -34,7 +34,7 @@ func ExampleInvoker() {
|
||||||
res, _ := inv.Call(neo.Hash, "transfer", acc, util.Uint160{1, 2, 3}, 1, nil)
|
res, _ := inv.Call(neo.Hash, "transfer", acc, util.Uint160{1, 2, 3}, 1, nil)
|
||||||
if res.State == vmstate.Halt.String() {
|
if res.State == vmstate.Halt.String() {
|
||||||
panic("NEO is broken!") // inv has no signers and transfer requires a witness to be performed.
|
panic("NEO is broken!") // inv has no signers and transfer requires a witness to be performed.
|
||||||
} else {
|
} else { // nolint:revive // superfluous-else: if block ends with call to panic function, so drop this else and outdent its block (revive)
|
||||||
println("ok") // this actually should fail
|
println("ok") // this actually should fail
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,13 +184,15 @@ func FromJSON(data []byte, maxCount int, bestIntPrecision bool) (Item, error) {
|
||||||
bestIntPrecision: bestIntPrecision,
|
bestIntPrecision: bestIntPrecision,
|
||||||
}
|
}
|
||||||
d.UseNumber()
|
d.UseNumber()
|
||||||
if item, err := d.decode(); err != nil {
|
item, err := d.decode()
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if _, err := d.Token(); !errors.Is(err, gio.EOF) {
|
|
||||||
return nil, fmt.Errorf("%w: unexpected items", ErrInvalidValue)
|
|
||||||
} else {
|
|
||||||
return item, nil
|
|
||||||
}
|
}
|
||||||
|
_, err = d.Token()
|
||||||
|
if !errors.Is(err, gio.EOF) {
|
||||||
|
return nil, fmt.Errorf("%w: unexpected items", ErrInvalidValue)
|
||||||
|
}
|
||||||
|
return item, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *decoder) decode() (Item, error) {
|
func (d *decoder) decode() (Item, error) {
|
||||||
|
|
Loading…
Reference in a new issue