Merge pull request #3356 from fyfyrchik/fix-checkresok

rpcclient: return FaultException in checkResOk if any
This commit is contained in:
Roman Khimov 2024-03-19 22:32:45 +03:00 committed by GitHub
commit a81dc5c795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -401,6 +401,9 @@ func checkResOK(r *result.Invoke, err error) error {
if r.State != vmstate.Halt.String() { if r.State != vmstate.Halt.String() {
return fmt.Errorf("invocation failed: %s", r.FaultException) return fmt.Errorf("invocation failed: %s", r.FaultException)
} }
if r.FaultException != "" {
return fmt.Errorf("inconsistent result, HALTed with exception: %s", r.FaultException)
}
return nil return nil
} }

View file

@ -1,12 +1,14 @@
package unwrap package unwrap
import ( import (
"encoding/json"
"errors" "errors"
"math" "math"
"math/big" "math/big"
"testing" "testing"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/nspcc-dev/neo-go/pkg/core/state"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/neorpc/result" "github.com/nspcc-dev/neo-go/pkg/neorpc/result"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -190,6 +192,27 @@ func TestBytes(t *testing.T) {
require.Equal(t, []byte{1, 2, 3}, b) require.Equal(t, []byte{1, 2, 3}, b)
} }
func TestItemJSONError(t *testing.T) {
bigValidSlice := stackitem.NewByteArray(make([]byte, stackitem.MaxSize-1))
res := &result.Invoke{
State: "HALT",
GasConsumed: 237626000,
Script: []byte{10},
Stack: []stackitem.Item{bigValidSlice, bigValidSlice},
FaultException: "",
Notifications: []state.NotificationEvent{},
}
data, err := json.Marshal(res)
require.NoError(t, err)
var received result.Invoke
require.NoError(t, json.Unmarshal(data, &received))
_, err = Item(&received, nil)
require.True(t, len(received.FaultException) != 0)
require.Contains(t, err.Error(), received.FaultException)
}
func TestUTF8String(t *testing.T) { func TestUTF8String(t *testing.T) {
_, err := UTF8String(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.Make([]stackitem.Item{})}}, nil) _, err := UTF8String(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.Make([]stackitem.Item{})}}, nil)
require.Error(t, err) require.Error(t, err)