Fix TestSealAndVerify

This commit is contained in:
Łukasz Magiera 2019-10-27 12:58:15 +01:00
parent 53cbe3446d
commit 02b67ea6b2
2 changed files with 36 additions and 20 deletions

View File

@ -1,7 +1,6 @@
package sectorbuilder
import (
"encoding/binary"
"io"
"os"
"sort"
@ -46,7 +45,7 @@ type SectorBuilderConfig struct {
func New(cfg *SectorBuilderConfig) (*SectorBuilder, error) {
proverId := addressToProverID(cfg.Miner)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 1, 1, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
sbp, err := sectorbuilder.InitSectorBuilder(cfg.SectorSize, 2, 1, 0, cfg.MetadataDir, proverId, cfg.SealedDir, cfg.StagedDir, 16)
if err != nil {
return nil, err
}
@ -62,12 +61,6 @@ func addressToProverID(a address.Address) [32]byte {
return proverId
}
func sectorIDtoBytes(sid uint64) [31]byte {
var out [31]byte
binary.LittleEndian.PutUint64(out[:], sid)
return out
}
func (sb *SectorBuilder) Destroy() {
sectorbuilder.DestroySectorBuilder(sb.handle)
}

View File

@ -1,9 +1,11 @@
package sectorbuilder_test
import (
"context"
"io"
"io/ioutil"
"math/rand"
"path/filepath"
"testing"
"github.com/ipfs/go-datastore"
@ -14,8 +16,12 @@ import (
"github.com/filecoin-project/lotus/storage/sector"
)
const sectorSize = 1024
func TestSealAndVerify(t *testing.T) {
//t.Skip("this is slow")
t.Skip("this is slow")
build.SectorSizes = []uint64{sectorSize}
if err := build.GetParams(true); err != nil {
t.Fatal(err)
}
@ -25,34 +31,51 @@ func TestSealAndVerify(t *testing.T) {
t.Fatal(err)
}
addr, err := address.NewFromString("t1tct3nfaw2q543xtybxcyw4deyxmfwkjk43u4t5y")
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
if err != nil {
t.Fatal(err)
}
metadata := filepath.Join(dir, "meta")
sealed := filepath.Join(dir, "sealed")
staging := filepath.Join(dir, "staging")
sb, err := sectorbuilder.New(&sectorbuilder.SectorBuilderConfig{
SectorSize: 1024,
SealedDir: dir,
StagedDir: dir,
MetadataDir: dir,
SectorSize: sectorSize,
SealedDir: sealed,
StagedDir: staging,
MetadataDir: metadata,
Miner: addr,
})
if err != nil {
t.Fatal(err)
}
r := io.LimitReader(rand.New(rand.NewSource(42)), 1016)
// TODO: Consider fixing
store := sector.NewStore(sb, datastore.NewMapDatastore(), func(ctx context.Context) (*sectorbuilder.SealTicket, error) {
return &sectorbuilder.SealTicket{
BlockHeight: 5,
TicketBytes: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2},
}, nil
})
if _, err := sb.AddPiece("foo", 1016, r); err != nil {
store.Service()
dlen := sectorbuilder.UserBytesForSectorSize(sectorSize)
r := io.LimitReader(rand.New(rand.NewSource(42)), int64(dlen))
sid, err := store.AddPiece("foo", dlen, r)
if err != nil {
t.Fatal(err)
}
if err := store.SealSector(context.TODO(), sid); err != nil {
t.Fatal(err)
}
// TODO: Consider fixing
store := sector.NewStore(sb, datastore.NewMapDatastore(), nil)
store.Service()
ssinfo := <-store.Incoming()
ok, err := sectorbuilder.VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], addr, ssinfo.Ticket.TicketBytes[:], ssinfo.SectorID, ssinfo.Proof)
ok, err := sectorbuilder.VerifySeal(sectorSize, ssinfo.CommR[:], ssinfo.CommD[:], addr, ssinfo.Ticket.TicketBytes[:], ssinfo.SectorID, ssinfo.Proof)
if err != nil {
t.Fatal(err)
}