mock: Update interface

This commit is contained in:
Łukasz Magiera 2020-05-26 16:39:25 +02:00
parent 6fe92ff13c
commit 65f04da920
2 changed files with 9 additions and 15 deletions

View File

@ -16,7 +16,6 @@ import (
logging "github.com/ipfs/go-log"
"golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/specs-actors/actors/abi"
@ -418,14 +417,3 @@ func TestSealAndVerify2(t *testing.T) {
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))
}

View File

@ -24,6 +24,7 @@ var log = logging.Logger("sbmock")
type SectorMgr struct {
sectors map[abi.SectorID]*sectorState
pieces map[cid.Cid][]byte
sectorSize abi.SectorSize
nextSectorID abi.SectorNumber
proofType abi.RegisteredProof
@ -41,6 +42,7 @@ func NewMockSectorMgr(ssize abi.SectorSize) *SectorMgr {
return &SectorMgr{
sectors: make(map[abi.SectorID]*sectorState),
pieces: map[cid.Cid][]byte{},
sectorSize: ssize,
nextSectorID: 5,
proofType: rt,
@ -80,13 +82,17 @@ func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorId abi.SectorID, exist
ss.lk.Lock()
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 {
return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
}
log.Warn("Generated Piece CID: ", c)
mgr.pieces[c] = b.Bytes()
ss.pieces = append(ss.pieces, c)
return abi.PieceInfo{
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 {
if len(mgr.sectors[sectorID].pieces) > 1 {
if len(mgr.sectors[sectorID].pieces) > 1 || offset != 0 {
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
}