diff --git a/gen/builders/asserter.go b/gen/builders/asserter.go index d02ea050..2d3f1d1b 100644 --- a/gen/builders/asserter.go +++ b/gen/builders/asserter.go @@ -4,12 +4,10 @@ import ( "fmt" "os" - "github.com/filecoin-project/lotus/chain/state" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-address" - + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/lotus/chain/state" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" ) @@ -98,6 +96,11 @@ func (a *Asserter) HeadEq(addr address.Address, expected cid.Cid) { a.Equal(expected, actor.Head, "expected actor %s head: %v, got: %v", addr, expected, actor.Head) } +// ExitCodeEq verifies two exit codes are the same (and prints system codes nicely). +func (a *Asserter) ExitCodeEq(actual exitcode.ExitCode, expected exitcode.ExitCode) { + a.Equal(expected, actual, "expected exit code: %s, got: %s", expected, actual) +} + // ActorExists verifies that the actor exists in the state tree. func (a *Asserter) ActorExists(addr address.Address) { st := a.suppliers.stateTracker() diff --git a/gen/suites/nested/main.go b/gen/suites/nested/main.go index a29b512b..859f6d84 100644 --- a/gen/suites/nested/main.go +++ b/gen/suites/nested/main.go @@ -2,6 +2,7 @@ package main import ( . "github.com/filecoin-project/test-vectors/gen/builders" + "github.com/filecoin-project/test-vectors/schema" ) func main() { @@ -85,16 +86,22 @@ func main() { ID: "fail-missing-params", Version: "v1", Desc: "", + Comment: "nested message exit code should be ErrSerialization see https://github.com/filecoin-project/test-vectors/issues/93#issuecomment-689593946", }, MessageFunc: nestedSends_FailMissingParams, + Mode: ModeLenientAssertions, + Hints: []string{schema.HintIncorrect, schema.HintNegate}, }, &VectorDef{ Metadata: &Metadata{ ID: "fail-mismatch-params", Version: "v1", Desc: "", + Comment: "nested message exit code should be ErrSerialization see https://github.com/filecoin-project/test-vectors/issues/93#issuecomment-689593946", }, MessageFunc: nestedSends_FailMismatchParams, + Mode: ModeLenientAssertions, + Hints: []string{schema.HintIncorrect, schema.HintNegate}, }, &VectorDef{ Metadata: &Metadata{ diff --git a/gen/suites/nested/nested.go b/gen/suites/nested/nested.go index 48304a43..5738eae4 100644 --- a/gen/suites/nested/nested.go +++ b/gen/suites/nested/nested.go @@ -123,7 +123,11 @@ func nestedSends_FailNonexistentIDAddress(v *MessageVectorBuilder) { newAddr := MustNewIDAddr(1234) amtSent := abi.NewTokenAmount(1) - stage.sendOk(newAddr, amtSent, builtin.MethodSend, nil, nonce) + result := stage.sendOk(newAddr, amtSent, builtin.MethodSend, nil, nonce) + + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.SysErrInvalidReceiver) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.ActorMissing(newAddr) @@ -136,7 +140,11 @@ func nestedSends_FailNonexistentActorAddress(v *MessageVectorBuilder) { newAddr := MustNewActorAddr("1234") amtSent := abi.NewTokenAmount(1) - stage.sendOk(newAddr, amtSent, builtin.MethodSend, nil, nonce) + result := stage.sendOk(newAddr, amtSent, builtin.MethodSend, nil, nonce) + + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.SysErrInvalidReceiver) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.ActorMissing(newAddr) @@ -149,7 +157,11 @@ func nestedSends_FailInvalidMethodNumNewActor(v *MessageVectorBuilder) { newAddr := v.Wallet.NewSECP256k1Account() amtSent := abi.NewTokenAmount(1) - stage.sendOk(newAddr, amtSent, abi.MethodNum(99), nil, nonce) + result := stage.sendOk(newAddr, amtSent, abi.MethodNum(99), nil, nonce) + + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.SysErrInvalidMethod) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.ActorMissing(newAddr) @@ -164,6 +176,10 @@ func nestedSends_FailInvalidMethodNumForActor(v *MessageVectorBuilder) { amtSent := abi.NewTokenAmount(1) result := stage.sendOk(stage.creator, amtSent, abi.MethodNum(99), nil, nonce) + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.SysErrInvalidMethod) + v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.BalanceEq(stage.creator, big.Sub(balanceBefore, CalculateSenderDeduction(result))) // Pay gas, don't receive funds. } @@ -178,6 +194,10 @@ func nestedSends_FailMissingParams(v *MessageVectorBuilder) { amtSent := abi.NewTokenAmount(1) result := stage.sendOk(stage.msAddr, amtSent, builtin.MethodsMultisig.AddSigner, params, nonce) + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.ErrSerialization) + v.Assert.BalanceEq(stage.creator, big.Sub(balanceBefore, CalculateSenderDeduction(result))) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.Equal(1, len(stage.state().Signers)) // No new signers @@ -199,6 +219,10 @@ func nestedSends_FailMismatchParams(v *MessageVectorBuilder) { amtSent := abi.NewTokenAmount(1) result := stage.sendOk(stage.msAddr, amtSent, builtin.MethodsMultisig.AddSigner, ¶ms, nonce) + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.ErrSerialization) + v.Assert.BalanceEq(stage.creator, big.Sub(balanceBefore, CalculateSenderDeduction(result))) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.Equal(1, len(stage.state().Signers)) // No new signers @@ -217,7 +241,11 @@ func nestedSends_FailInnerAbort(v *MessageVectorBuilder) { GasReward: big.Zero(), } amtSent := abi.NewTokenAmount(1) - stage.sendOk(builtin.RewardActorAddr, amtSent, builtin.MethodsReward.AwardBlockReward, ¶ms, nonce) + result := stage.sendOk(builtin.RewardActorAddr, amtSent, builtin.MethodsReward.AwardBlockReward, ¶ms, nonce) + + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.SysErrForbidden) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.HeadEq(builtin.RewardActorAddr, prevHead) @@ -240,7 +268,11 @@ func nestedSends_FailAbortedExec(v *MessageVectorBuilder) { } amtSent := abi.NewTokenAmount(1) - stage.sendOk(builtin.InitActorAddr, amtSent, builtin.MethodsInit.Exec, &execParams, nonce) + result := stage.sendOk(builtin.InitActorAddr, amtSent, builtin.MethodsInit.Exec, &execParams, nonce) + + var ret multisig.ProposeReturn + MustDeserialize(result.Result.Return, &ret) + v.Assert.ExitCodeEq(ret.Code, exitcode.ErrForbidden) v.Assert.BalanceEq(stage.msAddr, multisigBalance) // No change. v.Assert.HeadEq(builtin.InitActorAddr, prevHead) // Init state unchanged.