mock: Update interface
This commit is contained in:
parent
6fe92ff13c
commit
65f04da920
@ -16,7 +16,6 @@ import (
|
|||||||
logging "github.com/ipfs/go-log"
|
logging "github.com/ipfs/go-log"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
|
|
||||||
@ -418,14 +417,3 @@ func TestSealAndVerify2(t *testing.T) {
|
|||||||
|
|
||||||
post(t, sb, s1, s2)
|
post(t, sb, s1, s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestScribbles(t *testing.T) {
|
|
||||||
rf, w, _ := toReadableFile(bytes.NewReader(bytes.Repeat([]byte{0xff, 0}, 127)), 254)
|
|
||||||
defer w()
|
|
||||||
|
|
||||||
tf, _ := ioutil.TempFile("/tmp/", "scrb-")
|
|
||||||
|
|
||||||
fmt.Println(tf.Name())
|
|
||||||
|
|
||||||
fmt.Println(ffi.WriteWithAlignment(abi.RegisteredProof_StackedDRG2KiBSeal, rf, 254, tf, nil))
|
|
||||||
}
|
|
||||||
|
12
mock/mock.go
12
mock/mock.go
@ -24,6 +24,7 @@ var log = logging.Logger("sbmock")
|
|||||||
|
|
||||||
type SectorMgr struct {
|
type SectorMgr struct {
|
||||||
sectors map[abi.SectorID]*sectorState
|
sectors map[abi.SectorID]*sectorState
|
||||||
|
pieces map[cid.Cid][]byte
|
||||||
sectorSize abi.SectorSize
|
sectorSize abi.SectorSize
|
||||||
nextSectorID abi.SectorNumber
|
nextSectorID abi.SectorNumber
|
||||||
proofType abi.RegisteredProof
|
proofType abi.RegisteredProof
|
||||||
@ -41,6 +42,7 @@ func NewMockSectorMgr(ssize abi.SectorSize) *SectorMgr {
|
|||||||
|
|
||||||
return &SectorMgr{
|
return &SectorMgr{
|
||||||
sectors: make(map[abi.SectorID]*sectorState),
|
sectors: make(map[abi.SectorID]*sectorState),
|
||||||
|
pieces: map[cid.Cid][]byte{},
|
||||||
sectorSize: ssize,
|
sectorSize: ssize,
|
||||||
nextSectorID: 5,
|
nextSectorID: 5,
|
||||||
proofType: rt,
|
proofType: rt,
|
||||||
@ -80,13 +82,17 @@ func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorId abi.SectorID, exist
|
|||||||
ss.lk.Lock()
|
ss.lk.Lock()
|
||||||
defer ss.lk.Unlock()
|
defer ss.lk.Unlock()
|
||||||
|
|
||||||
c, err := ffiwrapper.GeneratePieceCIDFromFile(mgr.proofType, r, size)
|
var b bytes.Buffer
|
||||||
|
tr := io.TeeReader(r, &b)
|
||||||
|
|
||||||
|
c, err := ffiwrapper.GeneratePieceCIDFromFile(mgr.proofType, tr, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
|
return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warn("Generated Piece CID: ", c)
|
log.Warn("Generated Piece CID: ", c)
|
||||||
|
|
||||||
|
mgr.pieces[c] = b.Bytes()
|
||||||
ss.pieces = append(ss.pieces, c)
|
ss.pieces = append(ss.pieces, c)
|
||||||
return abi.PieceInfo{
|
return abi.PieceInfo{
|
||||||
Size: size.Padded(),
|
Size: size.Padded(),
|
||||||
@ -269,11 +275,11 @@ func generateFakePoSt(sectorInfo []abi.SectorInfo) []abi.PoStProof {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *SectorMgr) ReadPiece(ctx context.Context, w io.Writer, sectorID abi.SectorID, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, c cid.Cid) error {
|
func (mgr *SectorMgr) ReadPiece(ctx context.Context, w io.Writer, sectorID abi.SectorID, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, c cid.Cid) error {
|
||||||
if len(mgr.sectors[sectorID].pieces) > 1 {
|
if len(mgr.sectors[sectorID].pieces) > 1 || offset != 0 {
|
||||||
panic("implme")
|
panic("implme")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := io.CopyN(w, bytes.NewReader(mgr.sectors[sectorID].pieces[0].Bytes()[offset:]), int64(size))
|
_, err := io.CopyN(w, bytes.NewReader(mgr.pieces[mgr.sectors[sectorID].pieces[0]]), int64(size))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user