From 65f04da920f9139a802825469dfd0373b2a3bf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 26 May 2020 16:39:25 +0200 Subject: [PATCH] mock: Update interface --- ffiwrapper/sealer_test.go | 12 ------------ mock/mock.go | 12 +++++++++--- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/ffiwrapper/sealer_test.go b/ffiwrapper/sealer_test.go index c39d0ade0..73eaa2652 100644 --- a/ffiwrapper/sealer_test.go +++ b/ffiwrapper/sealer_test.go @@ -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)) -} diff --git a/mock/mock.go b/mock/mock.go index 403a1cbf6..53777434c 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -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 }