2019-08-14 22:17:27 +00:00
|
|
|
package sectorbuilder_test
|
2019-08-08 01:16:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
func TestSealAndVerify(t *testing.T) {
|
|
|
|
t.Skip("this is slow")
|
|
|
|
dir, err := ioutil.TempDir("", "sbtest")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
addr, err := address.NewFromString("t1tct3nfaw2q543xtybxcyw4deyxmfwkjk43u4t5y")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-08-14 22:17:27 +00:00
|
|
|
sb, err := sectorbuilder.New(§orbuilder.SectorBuilderConfig{
|
2019-08-08 01:16:58 +00:00
|
|
|
SectorSize: 1024,
|
|
|
|
SealedDir: dir,
|
|
|
|
StagedDir: dir,
|
|
|
|
MetadataDir: dir,
|
|
|
|
Miner: addr,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-09-23 11:43:32 +00:00
|
|
|
r := io.LimitReader(rand.New(rand.NewSource(42)), 1016)
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-09-23 11:43:32 +00:00
|
|
|
if _, err := sb.AddPiece("foo", 1016, r); err != nil {
|
2019-08-08 01:16:58 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-08-14 22:17:27 +00:00
|
|
|
store := sector.NewStore(sb)
|
|
|
|
store.Service()
|
|
|
|
ssinfo := <-store.Incoming()
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-08-14 22:17:27 +00:00
|
|
|
ok, err := sectorbuilder.VerifySeal(1024, ssinfo.CommR[:], ssinfo.CommD[:], ssinfo.CommRStar[:], addr, 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")
|
|
|
|
}
|
|
|
|
}
|