diff --git a/pkg/rpcclient/unwrap/unwrap.go b/pkg/rpcclient/unwrap/unwrap.go index f4c2243082..9ca61b5711 100644 --- a/pkg/rpcclient/unwrap/unwrap.go +++ b/pkg/rpcclient/unwrap/unwrap.go @@ -374,3 +374,15 @@ func Item(r *result.Invoke, err error) (stackitem.Item, error) { } return r.Stack[0], nil } + +// Nothing expects zero stack items and a successful invocation (HALT state). +func Nothing(r *result.Invoke, err error) error { + err = checkResOK(r, err) + if err != nil { + return err + } + if len(r.Stack) != 0 { + return errors.New("result stack is not empty") + } + return nil +} diff --git a/pkg/rpcclient/unwrap/unwrap_test.go b/pkg/rpcclient/unwrap/unwrap_test.go index 9ec9f3cc05..cab22c23b0 100644 --- a/pkg/rpcclient/unwrap/unwrap_test.go +++ b/pkg/rpcclient/unwrap/unwrap_test.go @@ -123,6 +123,24 @@ func TestBool(t *testing.T) { require.True(t, b) } +func TestNothing(t *testing.T) { + // Error on input. + err := Nothing(&result.Invoke{State: "HALT", Stack: []stackitem.Item{}}, errors.New("some")) + require.Error(t, err) + + // Nonempty stack. + err = Nothing(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.Make(42)}}, nil) + require.Error(t, err) + + // FAULT state. + err = Nothing(&result.Invoke{State: "FAULT", Stack: []stackitem.Item{}}, nil) + require.Error(t, err) + + // Positive. + err = Nothing(&result.Invoke{State: "HALT", Stack: []stackitem.Item{}}, nil) + require.NoError(t, err) +} + func TestInt64(t *testing.T) { _, err := Int64(&result.Invoke{State: "HALT", Stack: []stackitem.Item{stackitem.Make("0x03c564ed28ba3d50beb1a52dcb751b929e1d747281566bd510363470be186bc0")}}, nil) require.Error(t, err)