port to v2 imports

This commit is contained in:
Steven Allen
2020-10-21 12:16:23 -07:00
parent 8cad245f80
commit 4e730b5ec8
79 changed files with 724 additions and 657 deletions
+25 -24
View File
@@ -6,9 +6,10 @@ import (
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/exitcode"
"github.com/filecoin-project/go-state-types/rt"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/ipfs/go-cid"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
runtime2 "github.com/filecoin-project/specs-actors/v2/actors/runtime"
)
//go:generate go run ./gen
@@ -55,7 +56,7 @@ const (
const (
_ = 0 // skip zero iota value; first usage of iota gets 1.
MethodCallerValidation = builtin.MethodConstructor + iota
MethodCallerValidation = builtin2.MethodConstructor + iota
MethodCreateActor
MethodResolveAddress
// MethodDeleteActor is the identifier for the method that deletes this actor.
@@ -76,15 +77,15 @@ const (
// Exports defines the methods this actor exposes publicly.
func (a Actor) Exports() []interface{} {
return []interface{}{
builtin.MethodConstructor: a.Constructor,
MethodCallerValidation: a.CallerValidation,
MethodCreateActor: a.CreateActor,
MethodResolveAddress: a.ResolveAddress,
MethodDeleteActor: a.DeleteActor,
MethodSend: a.Send,
MethodMutateState: a.MutateState,
MethodAbortWith: a.AbortWith,
MethodInspectRuntime: a.InspectRuntime,
builtin2.MethodConstructor: a.Constructor,
MethodCallerValidation: a.CallerValidation,
MethodCreateActor: a.CreateActor,
MethodResolveAddress: a.ResolveAddress,
MethodDeleteActor: a.DeleteActor,
MethodSend: a.Send,
MethodMutateState: a.MutateState,
MethodAbortWith: a.AbortWith,
MethodInspectRuntime: a.InspectRuntime,
}
}
@@ -104,19 +105,19 @@ type SendArgs struct {
// SendReturn is the return values for the Send method.
type SendReturn struct {
Return runtime.CBORBytes
Return builtin2.CBORBytes
Code exitcode.ExitCode
}
// Send requests for this actor to send a message to an actor with the
// passed parameters.
func (a Actor) Send(rt runtime.Runtime, args *SendArgs) *SendReturn {
func (a Actor) Send(rt runtime2.Runtime, args *SendArgs) *SendReturn {
rt.ValidateImmediateCallerAcceptAny()
var out runtime.CBORBytes
var out builtin2.CBORBytes
code := rt.Send(
args.To,
args.Method,
runtime.CBORBytes(args.Params),
builtin2.CBORBytes(args.Params),
args.Value,
&out,
)
@@ -127,7 +128,7 @@ func (a Actor) Send(rt runtime.Runtime, args *SendArgs) *SendReturn {
}
// Constructor will panic because the Chaos actor is a singleton.
func (a Actor) Constructor(_ runtime.Runtime, _ *abi.EmptyValue) *abi.EmptyValue {
func (a Actor) Constructor(_ runtime2.Runtime, _ *abi.EmptyValue) *abi.EmptyValue {
panic("constructor should not be called; the Chaos actor is a singleton actor")
}
@@ -144,7 +145,7 @@ type CallerValidationArgs struct {
// CallerValidationBranchTwice validates twice.
// CallerValidationBranchIsAddress validates caller against CallerValidationArgs.Addrs.
// CallerValidationBranchIsType validates caller against CallerValidationArgs.Types.
func (a Actor) CallerValidation(rt runtime.Runtime, args *CallerValidationArgs) *abi.EmptyValue {
func (a Actor) CallerValidation(rt runtime2.Runtime, args *CallerValidationArgs) *abi.EmptyValue {
switch args.Branch {
case CallerValidationBranchNone:
case CallerValidationBranchTwice:
@@ -174,7 +175,7 @@ type CreateActorArgs struct {
}
// CreateActor creates an actor with the supplied CID and Address.
func (a Actor) CreateActor(rt runtime.Runtime, args *CreateActorArgs) *abi.EmptyValue {
func (a Actor) CreateActor(rt runtime2.Runtime, args *CreateActorArgs) *abi.EmptyValue {
rt.ValidateImmediateCallerAcceptAny()
var (
@@ -199,7 +200,7 @@ type ResolveAddressResponse struct {
Success bool
}
func (a Actor) ResolveAddress(rt runtime.Runtime, args *address.Address) *ResolveAddressResponse {
func (a Actor) ResolveAddress(rt runtime2.Runtime, args *address.Address) *ResolveAddressResponse {
rt.ValidateImmediateCallerAcceptAny()
resolvedAddr, ok := rt.ResolveAddress(*args)
@@ -212,7 +213,7 @@ func (a Actor) ResolveAddress(rt runtime.Runtime, args *address.Address) *Resolv
// DeleteActor deletes the executing actor from the state tree, transferring any
// balance to beneficiary.
func (a Actor) DeleteActor(rt runtime.Runtime, beneficiary *address.Address) *abi.EmptyValue {
func (a Actor) DeleteActor(rt runtime2.Runtime, beneficiary *address.Address) *abi.EmptyValue {
rt.ValidateImmediateCallerAcceptAny()
rt.DeleteActor(*beneficiary)
return nil
@@ -226,7 +227,7 @@ type MutateStateArgs struct {
}
// MutateState attempts to mutate a state value in the actor.
func (a Actor) MutateState(rt runtime.Runtime, args *MutateStateArgs) *abi.EmptyValue {
func (a Actor) MutateState(rt runtime2.Runtime, args *MutateStateArgs) *abi.EmptyValue {
rt.ValidateImmediateCallerAcceptAny()
var st State
switch args.Branch {
@@ -257,7 +258,7 @@ type AbortWithArgs struct {
}
// AbortWith simply causes a panic with the passed exit code.
func (a Actor) AbortWith(rt runtime.Runtime, args *AbortWithArgs) *abi.EmptyValue {
func (a Actor) AbortWith(rt runtime2.Runtime, args *AbortWithArgs) *abi.EmptyValue {
if args.Uncontrolled { // uncontrolled abort: directly panic
panic(args.Message)
} else {
@@ -277,7 +278,7 @@ type InspectRuntimeReturn struct {
}
// InspectRuntime returns a copy of the serializable values available in the Runtime.
func (a Actor) InspectRuntime(rt runtime.Runtime, _ *abi.EmptyValue) *InspectRuntimeReturn {
func (a Actor) InspectRuntime(rt runtime2.Runtime, _ *abi.EmptyValue) *InspectRuntimeReturn {
rt.ValidateImmediateCallerAcceptAny()
var st State
rt.StateReadonly(&st)
+45 -45
View File
@@ -7,15 +7,16 @@ import (
"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/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/support/mock"
atesting "github.com/filecoin-project/specs-actors/support/testing"
"github.com/ipfs/go-cid"
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
mock2 "github.com/filecoin-project/specs-actors/v2/support/mock"
atesting2 "github.com/filecoin-project/specs-actors/v2/support/testing"
)
func TestSingleton(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -28,8 +29,8 @@ func TestSingleton(t *testing.T) {
}
func TestCallerValidationNone(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -39,19 +40,19 @@ func TestCallerValidationNone(t *testing.T) {
}
func TestCallerValidationIs(t *testing.T) {
caller := atesting.NewIDAddr(t, 100)
receiver := atesting.NewIDAddr(t, 101)
builder := mock.NewBuilder(context.Background(), receiver)
caller := atesting2.NewIDAddr(t, 100)
receiver := atesting2.NewIDAddr(t, 101)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
rt.SetCaller(caller, builtin.AccountActorCodeID)
rt.SetCaller(caller, builtin2.AccountActorCodeID)
var a Actor
caddrs := []address.Address{atesting.NewIDAddr(t, 101)}
caddrs := []address.Address{atesting2.NewIDAddr(t, 101)}
rt.ExpectValidateCallerAddr(caddrs...)
// FIXME: https://github.com/filecoin-project/specs-actors/pull/1155
rt.ExpectAbort(exitcode.ErrForbidden, func() {
// fixed in: https://github.com/filecoin-project/specs-actors/pull/1155
rt.ExpectAbort(exitcode.SysErrForbidden, func() {
rt.Call(a.CallerValidation, &CallerValidationArgs{
Branch: CallerValidationBranchIsAddress,
Addrs: caddrs,
@@ -68,35 +69,34 @@ func TestCallerValidationIs(t *testing.T) {
}
func TestCallerValidationType(t *testing.T) {
caller := atesting.NewIDAddr(t, 100)
receiver := atesting.NewIDAddr(t, 101)
builder := mock.NewBuilder(context.Background(), receiver)
caller := atesting2.NewIDAddr(t, 100)
receiver := atesting2.NewIDAddr(t, 101)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
rt.SetCaller(caller, builtin.AccountActorCodeID)
rt.SetCaller(caller, builtin2.AccountActorCodeID)
var a Actor
rt.ExpectValidateCallerType(builtin.CronActorCodeID)
// FIXME: https://github.com/filecoin-project/specs-actors/pull/1155
rt.ExpectAbort(exitcode.ErrForbidden, func() {
rt.ExpectValidateCallerType(builtin2.CronActorCodeID)
rt.ExpectAbort(exitcode.SysErrForbidden, func() {
rt.Call(a.CallerValidation, &CallerValidationArgs{
Branch: CallerValidationBranchIsType,
Types: []cid.Cid{builtin.CronActorCodeID},
Types: []cid.Cid{builtin2.CronActorCodeID},
})
})
rt.Verify()
rt.ExpectValidateCallerType(builtin.AccountActorCodeID)
rt.ExpectValidateCallerType(builtin2.AccountActorCodeID)
rt.Call(a.CallerValidation, &CallerValidationArgs{
Branch: CallerValidationBranchIsType,
Types: []cid.Cid{builtin.AccountActorCodeID},
Types: []cid.Cid{builtin2.AccountActorCodeID},
})
rt.Verify()
}
func TestCallerValidationInvalidBranch(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -108,9 +108,9 @@ func TestCallerValidationInvalidBranch(t *testing.T) {
}
func TestDeleteActor(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
beneficiary := atesting.NewIDAddr(t, 101)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
beneficiary := atesting2.NewIDAddr(t, 101)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -122,8 +122,8 @@ func TestDeleteActor(t *testing.T) {
}
func TestMutateStateInTransaction(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -148,8 +148,8 @@ func TestMutateStateInTransaction(t *testing.T) {
}
func TestMutateStateAfterTransaction(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -175,8 +175,8 @@ func TestMutateStateAfterTransaction(t *testing.T) {
}
func TestMutateStateReadonly(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -201,8 +201,8 @@ func TestMutateStateReadonly(t *testing.T) {
}
func TestMutateStateInvalidBranch(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -215,8 +215,8 @@ func TestMutateStateInvalidBranch(t *testing.T) {
}
func TestAbortWith(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -233,8 +233,8 @@ func TestAbortWith(t *testing.T) {
}
func TestAbortWithUncontrolled(t *testing.T) {
receiver := atesting.NewIDAddr(t, 100)
builder := mock.NewBuilder(context.Background(), receiver)
receiver := atesting2.NewIDAddr(t, 100)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
var a Actor
@@ -250,12 +250,12 @@ func TestAbortWithUncontrolled(t *testing.T) {
}
func TestInspectRuntime(t *testing.T) {
caller := atesting.NewIDAddr(t, 100)
receiver := atesting.NewIDAddr(t, 101)
builder := mock.NewBuilder(context.Background(), receiver)
caller := atesting2.NewIDAddr(t, 100)
receiver := atesting2.NewIDAddr(t, 101)
builder := mock2.NewBuilder(context.Background(), receiver)
rt := builder.Build(t)
rt.SetCaller(caller, builtin.AccountActorCodeID)
rt.SetCaller(caller, builtin2.AccountActorCodeID)
rt.StateCreate(&State{})
var a Actor
+2 -2
View File
@@ -587,7 +587,7 @@ func (t *SendReturn) MarshalCBOR(w io.Writer) error {
scratch := make([]byte, 9)
// t.Return (runtime.CBORBytes) (slice)
// t.Return (builtin.CBORBytes) (slice)
if len(t.Return) > cbg.ByteArrayMaxLen {
return xerrors.Errorf("Byte array in field t.Return was too long")
}
@@ -631,7 +631,7 @@ func (t *SendReturn) UnmarshalCBOR(r io.Reader) error {
return fmt.Errorf("cbor input had wrong number of fields")
}
// t.Return (runtime.CBORBytes) (slice)
// t.Return (builtin.CBORBytes) (slice)
maj, extra, err = cbg.CborReadHeaderBuf(br, scratch)
if err != nil {