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

Commit

Permalink
Power actor CreateMiner passes on value received to new actor (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
anorth authored Apr 28, 2020
1 parent 0c2ed5e commit 7aee101
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions actors/builtin/power/power_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type CreateMinerParams struct {

type CreateMinerReturn struct {
IDAddress addr.Address // The canonical ID-based address for the actor.
RobustAddress addr.Address // A mre expensive but re-org-safe address for the newly created actor.
RobustAddress addr.Address // A more expensive but re-org-safe address for the newly created actor.
}

func (a Actor) CreateMiner(rt Runtime, params *CreateMinerParams) *CreateMinerReturn {
Expand All @@ -115,7 +115,7 @@ func (a Actor) CreateMiner(rt Runtime, params *CreateMinerParams) *CreateMinerRe
CodeCID: builtin.StorageMinerActorCodeID,
ConstructorParams: ctorParamBuf.Bytes(),
},
abi.NewTokenAmount(0),
rt.Message().ValueReceived(), // Pass on any value to the new actor.
)
builtin.RequireSuccess(rt, code, "failed to init new actor")
var addresses initact.ExecReturn
Expand Down
14 changes: 8 additions & 6 deletions actors/builtin/power/power_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
tutil "github.com/filecoin-project/specs-actors/support/testing"
)

const sectorSize = abi.SectorSize(2048)

func TestExports(t *testing.T) {
mock.CheckActorExports(t, power.Actor{})
}
Expand All @@ -44,9 +46,7 @@ func TestConstruction(t *testing.T) {
rt := builder.Build(t)
actor.constructAndVerify(rt)

actor.createMiner(rt, owner, owner, miner, actr, "miner", abi.SectorSize(int64(32)))

rt.Verify()
actor.createMiner(rt, owner, owner, miner, actr, "miner", sectorSize, abi.NewTokenAmount(10))

var st power.State
rt.GetState(&st)
Expand Down Expand Up @@ -193,7 +193,8 @@ func (h *spActorHarness) constructAndVerify(rt *mock.Runtime) {
verifyEmptyMap(h.t, rt, st.CronEventQueue)
}

func (h *spActorHarness) createMiner(rt *mock.Runtime, owner, worker, miner, robust addr.Address, peer peer.ID, sectorSize abi.SectorSize) {
func (h *spActorHarness) createMiner(rt *mock.Runtime, owner, worker, miner, robust addr.Address, peer peer.ID,
sectorSize abi.SectorSize, value abi.TokenAmount) {
createMinerParams := &power.CreateMinerParams{
Owner: owner,
Worker: worker,
Expand All @@ -203,7 +204,8 @@ func (h *spActorHarness) createMiner(rt *mock.Runtime, owner, worker, miner, rob

// owner send CreateMiner to Actor
rt.SetCaller(owner, builtin.AccountActorCodeID)
rt.SetReceived(abi.NewTokenAmount(1))
rt.SetReceived(value)
rt.SetBalance(value)
rt.ExpectValidateCallerType(builtin.AccountActorCodeID, builtin.MultisigActorCodeID)

createMinerRet := &power.CreateMinerReturn{
Expand All @@ -215,7 +217,7 @@ func (h *spActorHarness) createMiner(rt *mock.Runtime, owner, worker, miner, rob
CodeCID: builtin.StorageMinerActorCodeID,
ConstructorParams: initCreateMinerBytes(h.t, owner, worker, peer, sectorSize),
}
rt.ExpectSend(builtin.InitActorAddr, builtin.MethodsInit.Exec, msgParams, big.Zero(), createMinerRet, 0)
rt.ExpectSend(builtin.InitActorAddr, builtin.MethodsInit.Exec, msgParams, value, createMinerRet, 0)
rt.Call(h.Actor.CreateMiner, createMinerParams)
rt.Verify()
}
Expand Down

0 comments on commit 7aee101

Please sign in to comment.