Merge pull request #27 from filecoin-project/fix/invoker-decode-error
Fix invoker when UnmarshalCBOR errors
This commit is contained in:
commit
60a767da7d
@ -124,7 +124,9 @@ func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
||||
if err != nil {
|
||||
return []reflect.Value{
|
||||
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{
|
||||
|
@ -1,6 +1,7 @@
|
||||
package chain
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -18,10 +19,17 @@ func (b *basicParams) UnmarshalCBOR(in []byte) (int, error) {
|
||||
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{} {
|
||||
return []interface{}{
|
||||
b.InvokeSomething0,
|
||||
nil,
|
||||
b.BadParam,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
@ -40,6 +48,11 @@ func (basicContract) InvokeSomething0(act *types.Actor, vmctx types.VMContext,
|
||||
returnCode: params.b,
|
||||
}, 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,
|
||||
params *basicParams) (InvokeRet, error) {
|
||||
return InvokeRet{
|
||||
@ -58,4 +71,7 @@ func TestInvokerBasic(t *testing.T) {
|
||||
ret, err = code[10](nil, &VMContext{}, []byte{2})
|
||||
assert.NoError(t, err)
|
||||
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