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

Commit

Permalink
Tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ZenGround0 committed Sep 26, 2021
1 parent 529db5f commit e586232
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
24 changes: 18 additions & 6 deletions actors/builtin/miner/miner_commitment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,21 +440,25 @@ func TestPreCommitBatch(t *testing.T) {
name string
batchSize int
balanceSurplus abi.TokenAmount
baseFee abi.TokenAmount
deals []dealSpec
exit exitcode.ExitCode
error string
}{{
name: "one sector",
batchSize: 1,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
}, {
name: "max sectors",
batchSize: 32,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
}, {
name: "one deal",
batchSize: 3,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
deals: []dealSpec{{
size: 32 << 30,
verifiedSize: 0,
Expand All @@ -464,6 +468,7 @@ func TestPreCommitBatch(t *testing.T) {
name: "many deals",
batchSize: 3,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
deals: []dealSpec{{
size: 32 << 30,
verifiedSize: 0,
Expand All @@ -481,17 +486,20 @@ func TestPreCommitBatch(t *testing.T) {
name: "empty batch",
batchSize: 0,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
exit: exitcode.ErrIllegalArgument,
error: "batch empty",
}, {
name: "too many sectors",
batchSize: 257,
balanceSurplus: big.Zero(),
baseFee: big.Zero(),
exit: exitcode.ErrIllegalArgument,
error: "batch of 257 too large",
}, {
name: "insufficient balance",
batchSize: 10,
baseFee: big.Zero(),
balanceSurplus: abi.NewTokenAmount(1).Neg(),
exit: exitcode.ErrInsufficientFunds,
error: "insufficient funds",
Expand Down Expand Up @@ -522,6 +530,7 @@ func TestPreCommitBatch(t *testing.T) {
firstForMiner: true,
}
deposits := make([]big.Int, batchSize)

for i := 0; i < batchSize; i++ {
deals := dealSpec{}
if len(test.deals) > i {
Expand All @@ -539,13 +548,16 @@ func TestPreCommitBatch(t *testing.T) {
}
pwrEstimate := miner.QAPowerForWeight(actor.sectorSize, sectors[i].Expiration-precommitEpoch, dealWeight, verifiedDealWeight)
deposits[i] = miner.PreCommitDepositForPower(actor.epochRewardSmooth, actor.epochQAPowerSmooth, pwrEstimate)

}
netFee := miner.AggregatePreCommitNetworkFee(batchSize, test.baseFee)
totalDeposit := big.Sum(deposits...)
rt.SetBalance(big.Add(totalDeposit, test.balanceSurplus))
totalBalance := big.Add(netFee, totalDeposit)
rt.SetBalance(big.Add(totalBalance, test.balanceSurplus))

if test.exit != exitcode.Ok {
rt.ExpectAbortContainsMessage(test.exit, test.error, func() {
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf)
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, test.baseFee)

// State untouched.
st := getState(rt)
Expand All @@ -555,7 +567,7 @@ func TestPreCommitBatch(t *testing.T) {
})
return
}
precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf)
precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, test.baseFee)

// Check precommits
st := getState(rt)
Expand Down Expand Up @@ -607,7 +619,7 @@ func TestPreCommitBatch(t *testing.T) {
}

rt.ExpectAbortContainsMessage(exitcode.ErrIllegalArgument, "sector expiration", func() {
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true})
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}, big.Zero())
})
})

Expand All @@ -628,7 +640,7 @@ func TestPreCommitBatch(t *testing.T) {
*actor.makePreCommit(100, precommitEpoch-1, sectorExpiration, nil),
}
rt.ExpectAbortContainsMessage(exitcode.ErrIllegalArgument, "duplicate sector number 100", func() {
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true})
actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, preCommitBatchConf{firstForMiner: true}, big.Zero())
})
})
}
Expand Down Expand Up @@ -789,7 +801,7 @@ func TestProveCommit(t *testing.T) {
firstForMiner: true,
}

precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf)
precommits := actor.preCommitSectorBatch(rt, &miner.PreCommitSectorBatchParams{Sectors: sectors}, conf, big.Zero())

rt.SetEpoch(proveCommitEpoch)
noDealPower := miner.QAPowerForWeight(actor.sectorSize, sectorExpiration-proveCommitEpoch, big.Zero(), big.Zero())
Expand Down
9 changes: 6 additions & 3 deletions actors/builtin/miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4892,7 +4892,7 @@ type preCommitBatchConf struct {
firstForMiner bool
}

func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreCommitSectorBatchParams, conf preCommitBatchConf) []*miner.SectorPreCommitOnChainInfo {
func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreCommitSectorBatchParams, conf preCommitBatchConf, baseFee abi.TokenAmount) []*miner.SectorPreCommitOnChainInfo {
rt.SetCaller(h.worker, builtin.AccountActorCodeID)
rt.ExpectValidateCallerAddr(append(h.controlAddrs, h.owner, h.worker)...)
{
Expand Down Expand Up @@ -4933,8 +4933,11 @@ func (h *actorHarness) preCommitSectorBatch(rt *mock.Runtime, params *miner.PreC
rt.ExpectSend(builtin.StorageMarketActorAddr, builtin.MethodsMarket.VerifyDealsForActivation, &vdParams, big.Zero(), &vdReturn, exitcode.Ok)
}
st := getState(rt)
if st.FeeDebt.GreaterThan(big.Zero()) {
rt.ExpectSend(builtin.BurntFundsActorAddr, builtin.MethodSend, nil, st.FeeDebt, nil, exitcode.Ok)
// burn networkFee
if st.FeeDebt.GreaterThan(big.Zero()) || len(params.Sectors) > 1 {
expectedNetworkFee := miner.AggregatePreCommitNetworkFee(len(params.Sectors), baseFee)
expectedBurn := big.Add(expectedNetworkFee, st.FeeDebt)
rt.ExpectSend(builtin.BurntFundsActorAddr, builtin.MethodSend, nil, expectedBurn, nil, exitcode.Ok)
}

if conf.firstForMiner {
Expand Down
14 changes: 10 additions & 4 deletions actors/test/commit_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -879,14 +879,12 @@ func preCommitSectors(t *testing.T, v *vm.VM, count, batchSize int, worker, mAdd
{To: builtin.RewardActorAddr, Method: builtin.MethodsReward.ThisEpochReward},
{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.CurrentTotalPower},
}
invocsFirst := append(invocsCommon, vm.ExpectInvocation{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.EnrollCronEvent})
invocFirst := vm.ExpectInvocation{To: builtin.StoragePowerActorAddr, Method: builtin.MethodsPower.EnrollCronEvent}

sectorIndex := 0
for sectorIndex < count {
msgSectorIndexStart := sectorIndex
invocs := invocsCommon
if expectCronEnrollment && sectorIndex == 0 {
invocs = invocsFirst
}

// Prepare message.
params := miner.PreCommitSectorBatchParams{Sectors: make([]miner0.SectorPreCommitInfo, batchSize)}
Expand All @@ -907,6 +905,14 @@ func preCommitSectors(t *testing.T, v *vm.VM, count, batchSize int, worker, mAdd
// Trim the last, partial batch.
params.Sectors = params.Sectors[:sectorIndex%batchSize]
}

// Finalize invocation expectation list
if len(params.Sectors) > 1 {
invocs = append(invocs, vm.ExpectInvocation{To: builtin.BurntFundsActorAddr, Method: builtin.MethodSend})
}
if expectCronEnrollment && msgSectorIndexStart == 0 {
invocs = append(invocs, invocFirst)
}
vm.ApplyOk(t, v, worker, mAddr, big.Zero(), builtin.MethodsMiner.PreCommitSectorBatch, &params)
vm.ExpectInvocation{
To: mAddr,
Expand Down

0 comments on commit e586232

Please sign in to comment.