Fix invoker when UnmarshalCBOR errors
Underlying issue: https://git.io/fjXU6 License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
87a3eba8db
commit
2981c95207
@ -124,7 +124,9 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return []reflect.Value{
|
return []reflect.Value{
|
||||||
reflect.ValueOf(InvokeRet{}),
|
reflect.ValueOf(InvokeRet{}),
|
||||||
reflect.ValueOf(err),
|
// Below is a hack, fixed in Go 1.13
|
||||||
|
// https://git.io/fjXU6
|
||||||
|
reflect.ValueOf(&err).Elem(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return meth.Call([]reflect.Value{
|
return meth.Call([]reflect.Value{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package chain
|
package chain
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -18,10 +19,17 @@ func (b *basicParams) UnmarshalCBOR(in []byte) (int, error) {
|
|||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type badParam struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *badParam) UnmarshalCBOR(in []byte) (int, error) {
|
||||||
|
return -1, errors.New("some error")
|
||||||
|
}
|
||||||
|
|
||||||
func (b basicContract) Exports() []interface{} {
|
func (b basicContract) Exports() []interface{} {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
b.InvokeSomething0,
|
b.InvokeSomething0,
|
||||||
nil,
|
b.BadParam,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
@ -40,6 +48,11 @@ func (basicContract) InvokeSomething0(act *types.Actor, vmctx types.VMContext,
|
|||||||
returnCode: params.b,
|
returnCode: params.b,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
func (basicContract) BadParam(act *types.Actor, vmctx types.VMContext,
|
||||||
|
params *badParam) (InvokeRet, error) {
|
||||||
|
panic("should not execute")
|
||||||
|
}
|
||||||
|
|
||||||
func (basicContract) InvokeSomething10(act *types.Actor, vmctx types.VMContext,
|
func (basicContract) InvokeSomething10(act *types.Actor, vmctx types.VMContext,
|
||||||
params *basicParams) (InvokeRet, error) {
|
params *basicParams) (InvokeRet, error) {
|
||||||
return InvokeRet{
|
return InvokeRet{
|
||||||
@ -58,4 +71,7 @@ func TestInvokerBasic(t *testing.T) {
|
|||||||
ret, err = code[10](nil, &VMContext{}, []byte{2})
|
ret, err = code[10](nil, &VMContext{}, []byte{2})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, byte(12), ret.returnCode, "return code should be 1")
|
assert.Equal(t, byte(12), ret.returnCode, "return code should be 1")
|
||||||
|
|
||||||
|
ret, err = code[1](nil, &VMContext{}, []byte{2})
|
||||||
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user