Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
test: additional assertions for nested multisig propose return exit c…
Browse files Browse the repository at this point in the history
…odes (#133)

This adds additional assertions to ensure that the exit code for the receipt of an inner send is as expected.

This also marks a couple of vectors as broken - their inner sends were not returning the correct exit code.

The vectors marked as broken will be fixed in lotus by filecoin-project/lotus#3730

Please see #93 for the backstory!
  • Loading branch information
Alan Shaw authored Sep 11, 2020
1 parent 3380a82 commit be60b92
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
13 changes: 8 additions & 5 deletions gen/builders/asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions gen/suites/nested/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
. "github.com/filecoin-project/test-vectors/gen/builders"
"github.com/filecoin-project/test-vectors/schema"
)

func main() {
Expand Down Expand Up @@ -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{
Expand Down
42 changes: 37 additions & 5 deletions gen/suites/nested/nested.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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.
}
Expand All @@ -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
Expand All @@ -199,6 +219,10 @@ func nestedSends_FailMismatchParams(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
Expand All @@ -217,7 +241,11 @@ func nestedSends_FailInnerAbort(v *MessageVectorBuilder) {
GasReward: big.Zero(),
}
amtSent := abi.NewTokenAmount(1)
stage.sendOk(builtin.RewardActorAddr, amtSent, builtin.MethodsReward.AwardBlockReward, &params, nonce)
result := stage.sendOk(builtin.RewardActorAddr, amtSent, builtin.MethodsReward.AwardBlockReward, &params, 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)
Expand All @@ -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.
Expand Down

0 comments on commit be60b92

Please sign in to comment.