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

Commit

Permalink
feat: wip actor abort with different error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Sep 8, 2020
1 parent 62e650a commit 900ddd9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
8 changes: 8 additions & 0 deletions gen/builders/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func MessageReturns(expect cbg.CBORMarshaler) ApplyRetPredicate {
}
}

// PanickedRet represents a non-return value, a placeholder for when an actor panicked while applying a message.
var PanickedRet = vm.ApplyRet{}

// Panicked returns an ApplyRetPredicate that passes if the message response is the PanickedRet.
func Panicked() ApplyRetPredicate {
return MessageReturns(&PanickedRet)
}

// BalanceUpdated returns a ActorPredicate that checks whether the balance
// of the actor has been deducted the gas cost and the outgoing value transfers,
// and has been increased by the offset (or decreased, if the argument is negative).
Expand Down
25 changes: 23 additions & 2 deletions gen/suites/vm_violations/actor_abort.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
. "github.com/filecoin-project/test-vectors/gen/builders"
)

func abort(args chaos.AbortArgs, expectedCode exitcode.ExitCode) func(*MessageVectorBuilder) {
func actorAbort(abortCode exitcode.ExitCode, msg string, expectedCode exitcode.ExitCode) func(*MessageVectorBuilder) {
return func(v *MessageVectorBuilder) {
v.Messages.SetDefaults(GasLimit(1_000_000_000), GasPremium(1), GasFeeCap(200))

Expand All @@ -21,7 +21,7 @@ func abort(args chaos.AbortArgs, expectedCode exitcode.ExitCode) func(*MessageVe
sender.ID,
chaos.Address,
chaos.MethodAbort,
MustSerialize(&args),
MustSerialize(&chaos.AbortArgs{Code: abortCode, Message: msg}),
Value(big.Zero()),
Nonce(0),
)
Expand All @@ -30,3 +30,24 @@ func abort(args chaos.AbortArgs, expectedCode exitcode.ExitCode) func(*MessageVe
v.Assert.LastMessageResultSatisfies(ExitCode(expectedCode))
}
}

func actorPanic(msg string) func(*MessageVectorBuilder) {
return func(v *MessageVectorBuilder) {
v.Messages.SetDefaults(GasLimit(1_000_000_000), GasPremium(1), GasFeeCap(200))

sender := v.Actors.Account(address.SECP256K1, abi.NewTokenAmount(1_000_000_000_000))
v.CommitPreconditions()

v.Messages.Raw(
sender.ID,
chaos.Address,
chaos.MethodAbort,
MustSerialize(&chaos.AbortArgs{NoCode: true, Message: msg}),
Value(big.Zero()),
Nonce(0),
)
v.CommitApplies()

v.Assert.LastMessageResultSatisfies(Panicked())
}
}
21 changes: 15 additions & 6 deletions gen/suites/vm_violations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,25 +232,34 @@ func main() {
g.Group("actor_abort",
&VectorDef{
Metadata: &Metadata{
ID: "no-exit-code",
ID: "custom-exit-code",
Version: "v1",
Desc: "actors can abort with custom exit codes",
},
Selector: map[string]string{"chaos_actor": "true"},
MessageFunc: actorAbort(exitcode.FirstActorSpecificExitCode, "custom exit code abort", exitcode.FirstActorSpecificExitCode),
},
&VectorDef{
Metadata: &Metadata{
ID: "system-exit-code",
Version: "v1",
Desc: "no exit code provided, just panic and let the runtime return the error",
Desc: "actors should not abort with system exit codes",
},
Selector: map[string]string{"chaos_actor": "true"},
Mode: ModeLenientAssertions,
Hints: []string{schema.HintIncorrect, schema.HintNegate},
MessageFunc: abort(chaos.AbortArgs{NoCode: true, Message: "no exit code abort"}, exitcode.FirstActorSpecificExitCode),
MessageFunc: actorAbort(exitcode.SysErrInsufficientFunds, "system exit code abort", exitcode.SysErrorIllegalActor),
},
&VectorDef{
Metadata: &Metadata{
ID: "system-exit-code",
ID: "no-exit-code",
Version: "v1",
Desc: "actors should not return system exit codes",
Desc: "actor failure, a panic with no associated exit code",
},
Selector: map[string]string{"chaos_actor": "true"},
Mode: ModeLenientAssertions,
Hints: []string{schema.HintIncorrect, schema.HintNegate},
MessageFunc: abort(chaos.AbortArgs{Code: exitcode.SysErrInsufficientFunds, Message: "system exit code abort"}, exitcode.SysErrorIllegalActor),
MessageFunc: actorPanic("no exit code abort"),
},
)
}

0 comments on commit 900ddd9

Please sign in to comment.