Skip to content

Commit

Permalink
fix new panics in invoker_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Jul 28, 2021
1 parent 71bf2aa commit 40c476a
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions chain/vm/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand All @@ -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) {
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 40c476a

Please sign in to comment.