Skip to content

Commit

Permalink
Merge pull request #3356 from fyfyrchik/fix-checkresok
Browse files Browse the repository at this point in the history
rpcclient: return FaultException in checkResOk if any
  • Loading branch information
roman-khimov committed Mar 19, 2024
2 parents da4e80e + 1a3a494 commit a81dc5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/rpcclient/unwrap/unwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 23 additions & 0 deletions pkg/rpcclient/unwrap/unwrap_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a81dc5c

Please sign in to comment.