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

Commit

Permalink
test: wip actor abort
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Sep 4, 2020
1 parent bce53df commit a14d0cf
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 0 deletions.
22 changes: 22 additions & 0 deletions chaos/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const (
// MethodMutateState is the identifier for the method that attempts to mutate
// a state value in the actor.
MethodMutateState
// MethodAbort is the identifier for the method that panics optionally with
// a passed exit code.
MethodAbort
)

// Exports defines the methods this actor exposes publicly.
Expand All @@ -73,6 +76,7 @@ func (a Actor) Exports() []interface{} {
MethodDeleteActor: a.DeleteActor,
MethodSend: a.Send,
MethodMutateState: a.MutateState,
MethodAbort: a.Abort,
}
}

Expand Down Expand Up @@ -233,3 +237,21 @@ func (a Actor) MutateState(rt runtime.Runtime, args *MutateStateArgs) *adt.Empty
}
return nil
}

// AbortArgs are the arguments to the abort method, specifying the exit code to
// (optionally) abort with and the message.
type AbortArgs struct {
Code exitcode.ExitCode
NoCode bool
Message string
}

// Abort simply causes a panic or abort with the passed exit code.
func (a Actor) Abort(rt runtime.Runtime, args *AbortArgs) *adt.EmptyValue {
if args.NoCode { // no code, just plain old panic
panic(args.Message)
} else {
rt.Abortf(args.Code, args.Message)
}
return nil
}
116 changes: 116 additions & 0 deletions chaos/cbor_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chaos/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func main() {
chaos.SendArgs{},
chaos.SendReturn{},
chaos.MutateStateArgs{},
chaos.AbortArgs{},
); err != nil {
panic(err)
}
Expand Down
32 changes: 32 additions & 0 deletions gen/suites/vm_violations/actor_abort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/filecoin-project/test-vectors/chaos"

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

func abort(args chaos.AbortArgs, expectedCode exitcode.ExitCode) 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(&args),
Value(big.Zero()),
Nonce(0),
)
v.CommitApplies()

v.Assert.LastMessageResultSatisfies(ExitCode(expectedCode))
}
}
25 changes: 25 additions & 0 deletions gen/suites/vm_violations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,29 @@ func main() {
MessageFunc: mutateState(valPfx+"after-transaction", chaos.MutateAfterTransaction, exitcode.SysErrorIllegalActor),
},
)

g.Group("actor_abort",
&VectorDef{
Metadata: &Metadata{
ID: "no-exit-code",
Version: "v1",
Desc: "no exit code provided, just panic and let the runtime return the error",
},
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),
},
&VectorDef{
Metadata: &Metadata{
ID: "system-exit-code",
Version: "v1",
Desc: "actors should not return system exit codes",
},
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),
},
)
}

0 comments on commit a14d0cf

Please sign in to comment.