rpcclient: return FaultException in checkResOk if any

FaultException can be non-empty even in Halt state when there were
problems with stack marshaling to JSON.

Signed-off-by: Evgenii Stratonikov <fyfyrchik@runbox.com>
This commit is contained in:
Evgenii Stratonikov 2024-03-14 21:31:32 +03:00
parent 9c83beffbb
commit 1a3a494459
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() {
return fmt.Errorf("invocation failed: %s", r.FaultException)
}
if r.FaultException != "" {
return fmt.Errorf("inconsistent result, HALTed with exception: %s", r.FaultException)
}
return nil
}

View file

@ -1,12 +1,14 @@
package unwrap
import (
"encoding/json"
"errors"
"math"
"math/big"
"testing"
"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/neorpc/result"
"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)
}
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) {
_, err := UTF8String(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.Make([]stackitem.Item{})}}, nil)
require.Error(t, err)