2019-08-14 22:17:27 +00:00
|
|
|
package sectorbuilder_test
|
2019-08-08 01:16:58 +00:00
|
|
|
|
|
|
|
import (
|
2019-10-27 11:58:15 +00:00
|
|
|
"context"
|
2019-08-08 01:16:58 +00:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"math/rand"
|
2019-10-27 11:58:15 +00:00
|
|
|
"path/filepath"
|
2019-08-08 01:16:58 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-10-24 14:24:31 +00:00
|
|
|
"github.com/ipfs/go-datastore"
|
|
|
|
|
2019-10-22 06:43:14 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/address"
|
|
|
|
"github.com/filecoin-project/lotus/lib/sectorbuilder"
|
|
|
|
"github.com/filecoin-project/lotus/storage/sector"
|
2019-08-08 01:16:58 +00:00
|
|
|
)
|
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
const sectorSize = 1024
|
|
|
|
|
2019-08-08 01:16:58 +00:00
|
|
|
func TestSealAndVerify(t *testing.T) {
|
2019-10-27 11:58:15 +00:00
|
|
|
t.Skip("this is slow")
|
|
|
|
build.SectorSizes = []uint64{sectorSize}
|
|
|
|
|
2019-10-22 06:43:14 +00:00
|
|
|
if err := build.GetParams(true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-08-08 01:16:58 +00:00
|
|
|
dir, err := ioutil.TempDir("", "sbtest")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
addr, err := address.NewFromString("t3vfxagwiegrywptkbmyohqqbfzd7xzbryjydmxso4hfhgsnv6apddyihltsbiikjf3lm7x2myiaxhuc77capq")
|
2019-08-08 01:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
metadata := filepath.Join(dir, "meta")
|
|
|
|
sealed := filepath.Join(dir, "sealed")
|
|
|
|
staging := filepath.Join(dir, "staging")
|
|
|
|
|
2019-08-14 22:17:27 +00:00
|
|
|
sb, err := sectorbuilder.New(§orbuilder.SectorBuilderConfig{
|
2019-10-27 11:58:15 +00:00
|
|
|
SectorSize: sectorSize,
|
|
|
|
SealedDir: sealed,
|
|
|
|
StagedDir: staging,
|
|
|
|
MetadataDir: metadata,
|
2019-08-08 01:16:58 +00:00
|
|
|
Miner: addr,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
// TODO: Consider fixing
|
|
|
|
store := sector.NewStore(sb, datastore.NewMapDatastore(), func(ctx context.Context) (*sectorbuilder.SealTicket, error) {
|
|
|
|
return §orbuilder.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
|
|
|
|
})
|
|
|
|
|
|
|
|
store.Service()
|
|
|
|
|
|
|
|
dlen := sectorbuilder.UserBytesForSectorSize(sectorSize)
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
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 {
|
2019-08-08 01:16:58 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-08-14 22:17:27 +00:00
|
|
|
ssinfo := <-store.Incoming()
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
ok, err := sectorbuilder.VerifySeal(sectorSize, ssinfo.CommR[:], ssinfo.CommD[:], addr, ssinfo.Ticket.TicketBytes[:], ssinfo.SectorID, ssinfo.Proof)
|
2019-08-08 01:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("proof failed to validate")
|
|
|
|
}
|
|
|
|
}
|