From 1e909e70b6476882523ce5295f974333916b95a7 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Tue, 8 Sep 2020 13:24:36 +0100 Subject: [PATCH] feat: wip actor abort with different error codes --- gen/builders/predicates.go | 8 ++++++++ gen/suites/vm_violations/actor_abort.go | 25 +++++++++++++++++++++++-- gen/suites/vm_violations/main.go | 21 +++++++++++++++------ 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/gen/builders/predicates.go b/gen/builders/predicates.go index a1a98316..0f578b20 100644 --- a/gen/builders/predicates.go +++ b/gen/builders/predicates.go @@ -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). diff --git a/gen/suites/vm_violations/actor_abort.go b/gen/suites/vm_violations/actor_abort.go index 6621aa73..ff35498d 100644 --- a/gen/suites/vm_violations/actor_abort.go +++ b/gen/suites/vm_violations/actor_abort.go @@ -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)) @@ -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), ) @@ -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()) + } +} diff --git a/gen/suites/vm_violations/main.go b/gen/suites/vm_violations/main.go index 908b1409..bcb1af39 100644 --- a/gen/suites/vm_violations/main.go +++ b/gen/suites/vm_violations/main.go @@ -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"), }, ) }