2020-04-07 22:26:07 +00:00
|
|
|
package sealing_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-04-07 22:26:07 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
commcid "github.com/filecoin-project/go-fil-commcid"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
|
|
|
|
sealing "github.com/filecoin-project/storage-fsm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type fakeChain struct {
|
|
|
|
h abi.ChainEpoch
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *fakeChain) ChainHead(ctx context.Context) (sealing.TipSetToken, abi.ChainEpoch, error) {
|
|
|
|
return []byte{1, 2, 3}, f.h, nil
|
|
|
|
}
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
func fakePieceCid(t *testing.T) cid.Cid {
|
|
|
|
comm := [32]byte{1, 2, 3}
|
|
|
|
fakePieceCid, err := commcid.ReplicaCommitmentV1ToCID(comm[:])
|
|
|
|
require.NoError(t, err)
|
|
|
|
return fakePieceCid
|
|
|
|
}
|
|
|
|
|
2020-04-07 22:26:07 +00:00
|
|
|
func TestBasicPolicyEmptySector(t *testing.T) {
|
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2020-04-17 20:16:52 +00:00
|
|
|
}, 10, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background())
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
assert.Equal(t, 2879, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasicPolicyMostConstrictiveSchedule(t *testing.T) {
|
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2020-04-17 20:16:52 +00:00
|
|
|
}, 100, 11)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
2020-04-07 22:26:07 +00:00
|
|
|
{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: &sealing.DealInfo{
|
|
|
|
DealID: abi.DealID(42),
|
|
|
|
DealSchedule: sealing.DealSchedule{
|
|
|
|
StartEpoch: abi.ChainEpoch(70),
|
|
|
|
EndEpoch: abi.ChainEpoch(75),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: &sealing.DealInfo{
|
|
|
|
DealID: abi.DealID(43),
|
|
|
|
DealSchedule: sealing.DealSchedule{
|
|
|
|
StartEpoch: abi.ChainEpoch(80),
|
|
|
|
EndEpoch: abi.ChainEpoch(100),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
assert.Equal(t, 2890, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBasicPolicyIgnoresExistingScheduleIfExpired(t *testing.T) {
|
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2020-04-17 20:16:52 +00:00
|
|
|
}, 100, 0)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
2020-04-07 22:26:07 +00:00
|
|
|
{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: &sealing.DealInfo{
|
|
|
|
DealID: abi.DealID(44),
|
|
|
|
DealSchedule: sealing.DealSchedule{
|
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
|
|
|
EndEpoch: abi.ChainEpoch(10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
assert.Equal(t, 2879, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMissingDealIsIgnored(t *testing.T) {
|
|
|
|
policy := sealing.NewBasicPreCommitPolicy(&fakeChain{
|
|
|
|
h: abi.ChainEpoch(55),
|
2020-04-17 20:16:52 +00:00
|
|
|
}, 100, 11)
|
2020-04-07 22:26:07 +00:00
|
|
|
|
2020-04-08 14:52:20 +00:00
|
|
|
pieces := []sealing.Piece{
|
2020-04-07 22:26:07 +00:00
|
|
|
{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: &sealing.DealInfo{
|
|
|
|
DealID: abi.DealID(44),
|
|
|
|
DealSchedule: sealing.DealSchedule{
|
|
|
|
StartEpoch: abi.ChainEpoch(1),
|
|
|
|
EndEpoch: abi.ChainEpoch(10),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Piece: abi.PieceInfo{
|
|
|
|
Size: abi.PaddedPieceSize(1024),
|
2020-08-12 19:05:09 +00:00
|
|
|
PieceCID: fakePieceCid(t),
|
2020-04-07 22:26:07 +00:00
|
|
|
},
|
|
|
|
DealInfo: nil,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
exp, err := policy.Expiration(context.Background(), pieces...)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-08-12 19:05:09 +00:00
|
|
|
assert.Equal(t, 2890, int(exp))
|
2020-04-07 22:26:07 +00:00
|
|
|
}
|