From 40c476a2d4da1c8a57dabd5806d1b945a43ce15d Mon Sep 17 00:00:00 2001 From: ZenGround0 Date: Wed, 28 Jul 2021 15:19:32 -0400 Subject: [PATCH] fix new panics in invoker_test.go --- chain/vm/invoker_test.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/chain/vm/invoker_test.go b/chain/vm/invoker_test.go index 6822e2371f5..8499f001a59 100644 --- a/chain/vm/invoker_test.go +++ b/chain/vm/invoker_test.go @@ -6,6 +6,8 @@ import ( "io" "testing" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" cbor "github.com/ipfs/go-ipld-cbor" @@ -80,6 +82,30 @@ func (basicContract) InvokeSomething10(rt runtime2.Runtime, params *basicParams) return nil } +type basicRtMessage struct{} + +var _ runtime2.Message = (*basicRtMessage)(nil) + +func (*basicRtMessage) Caller() address.Address { + a, err := address.NewIDAddress(0) + if err != nil { + panic(err) + } + return a +} + +func (*basicRtMessage) Receiver() address.Address { + a, err := address.NewIDAddress(1) + if err != nil { + panic(err) + } + return a +} + +func (*basicRtMessage) ValueReceived() abi.TokenAmount { + return big.NewInt(0) +} + func TestInvokerBasic(t *testing.T) { inv := ActorRegistry{} code, err := inv.transform(basicContract{}) @@ -89,7 +115,7 @@ func TestInvokerBasic(t *testing.T) { bParam, err := actors.SerializeParams(&basicParams{B: 1}) assert.NoError(t, err) - _, aerr := code[0](&Runtime{}, bParam) + _, aerr := code[0](&Runtime{Message: &basicRtMessage{}}, bParam) assert.Equal(t, exitcode.ExitCode(1), aerrors.RetCode(aerr), "return code should be 1") if aerrors.IsFatal(aerr) { @@ -101,7 +127,7 @@ func TestInvokerBasic(t *testing.T) { bParam, err := actors.SerializeParams(&basicParams{B: 2}) assert.NoError(t, err) - _, aerr := code[10](&Runtime{}, bParam) + _, aerr := code[10](&Runtime{Message: &basicRtMessage{}}, bParam) assert.Equal(t, exitcode.ExitCode(12), aerrors.RetCode(aerr), "return code should be 12") if aerrors.IsFatal(aerr) { t.Fatal("err should not be fatal") @@ -113,6 +139,7 @@ func TestInvokerBasic(t *testing.T) { vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version { return network.Version0 }}, + Message: &basicRtMessage{}, }, []byte{99}) if aerrors.IsFatal(aerr) { t.Fatal("err should not be fatal") @@ -125,6 +152,7 @@ func TestInvokerBasic(t *testing.T) { vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version { return network.Version7 }}, + Message: &basicRtMessage{}, }, []byte{99}) if aerrors.IsFatal(aerr) { t.Fatal("err should not be fatal")