-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sealing: numassign: itests/bug fixes
- Loading branch information
Showing
5 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package itests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/filecoin-project/go-bitfield" | ||
rlepluslazy "github.com/filecoin-project/go-bitfield/rle" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
|
||
"github.com/filecoin-project/lotus/itests/kit" | ||
) | ||
|
||
func TestAssignBasic(t *testing.T) { | ||
kit.QuietMiningLogs() | ||
|
||
ctx := context.Background() | ||
blockTime := 1 * time.Millisecond | ||
|
||
_, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs()) | ||
ens.InterconnectAll().BeginMiningMustPost(blockTime) | ||
|
||
nSectors := 2 | ||
|
||
{ | ||
nam, err := miner.SectorNumAssignerMeta(ctx) | ||
require.NoError(t, err) | ||
|
||
// genesis sectors start at 1, so if there are 2, we expect the Next to be 3 | ||
require.Equal(t, abi.SectorNumber(miner.PresealSectors+1), nam.Next) | ||
} | ||
|
||
miner.PledgeSectors(ctx, nSectors, 0, nil) | ||
|
||
sl, err := miner.SectorsListNonGenesis(ctx) | ||
require.NoError(t, err) | ||
|
||
require.Len(t, sl, nSectors) | ||
require.Equal(t, abi.SectorNumber(miner.PresealSectors+1), sl[0]) | ||
require.Equal(t, abi.SectorNumber(miner.PresealSectors+2), sl[1]) | ||
} | ||
|
||
func rangeBitField(from, to uint64) bitfield.BitField { | ||
var runs []rlepluslazy.Run | ||
if from > 0 { | ||
runs = append(runs, rlepluslazy.Run{ | ||
Val: false, | ||
Len: from, | ||
}) | ||
} | ||
runs = append(runs, rlepluslazy.Run{ | ||
Val: true, | ||
Len: to - from + 1, | ||
}) | ||
|
||
r, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{Runs: runs}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return r | ||
} | ||
|
||
func TestAssignReservation(t *testing.T) { | ||
kit.QuietMiningLogs() | ||
|
||
ctx := context.Background() | ||
blockTime := 1 * time.Millisecond | ||
|
||
_, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs()) | ||
ens.InterconnectAll().BeginMiningMustPost(blockTime) | ||
|
||
err := miner.SectorNumReserve(ctx, "test-reservation", rangeBitField(3, 10), false) | ||
require.NoError(t, err) | ||
|
||
// colliding name fails | ||
err = miner.SectorNumReserve(ctx, "test-reservation", rangeBitField(30, 33), false) | ||
require.Error(t, err) | ||
|
||
// colliding range | ||
err = miner.SectorNumReserve(ctx, "test-reservation2", rangeBitField(7, 12), false) | ||
require.Error(t, err) | ||
|
||
// illegal characters in the name | ||
err = miner.SectorNumReserve(ctx, "test/reservation", rangeBitField(99, 100), false) | ||
require.Error(t, err) | ||
|
||
nSectors := 2 | ||
|
||
{ | ||
nam, err := miner.SectorNumAssignerMeta(ctx) | ||
require.NoError(t, err) | ||
|
||
// reservation to 10, so we expect 11 to be first free | ||
require.Equal(t, abi.SectorNumber(11), nam.Next) | ||
} | ||
|
||
miner.PledgeSectors(ctx, nSectors, 0, nil) | ||
|
||
sl, err := miner.SectorsListNonGenesis(ctx) | ||
require.NoError(t, err) | ||
|
||
require.Len(t, sl, nSectors) | ||
require.Equal(t, abi.SectorNumber(11), sl[0]) | ||
require.Equal(t, abi.SectorNumber(12), sl[1]) | ||
|
||
// drop the reservation and see if we use the unused numbers | ||
err = miner.SectorNumFree(ctx, "test-reservation") | ||
require.NoError(t, err) | ||
|
||
{ | ||
nam, err := miner.SectorNumAssignerMeta(ctx) | ||
require.NoError(t, err) | ||
|
||
// first post-genesis sector is 3 | ||
require.Equal(t, abi.SectorNumber(3), nam.Next) | ||
} | ||
|
||
miner.PledgeSectors(ctx, 1, nSectors, nil) | ||
|
||
sl, err = miner.SectorsListNonGenesis(ctx) | ||
require.NoError(t, err) | ||
|
||
require.Len(t, sl, nSectors+1) | ||
require.Equal(t, abi.SectorNumber(3), sl[0]) | ||
require.Equal(t, abi.SectorNumber(11), sl[1]) | ||
require.Equal(t, abi.SectorNumber(12), sl[2]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters