forked from TrueCloudLab/neoneo-go
Merge pull request #3356 from fyfyrchik/fix-checkresok
rpcclient: return FaultException in checkResOk if any
This commit is contained in:
commit
a81dc5c795
2 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue