2019-08-14 22:17:27 +00:00
|
|
|
package sectorbuilder_test
|
2019-08-08 01:16:58 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"math/rand"
|
|
|
|
"testing"
|
|
|
|
|
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/lib/sectorbuilder"
|
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-11-05 17:09:42 +00:00
|
|
|
t.Skip("this is slow")
|
|
|
|
//os.Setenv("BELLMAN_NO_GPU", "1")
|
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
build.SectorSizes = []uint64{sectorSize}
|
|
|
|
|
2019-10-22 06:43:14 +00:00
|
|
|
if err := build.GetParams(true); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-11-05 16:38:54 +00:00
|
|
|
sb, cleanup, err := sectorbuilder.TempSectorbuilder(sectorSize)
|
2019-08-08 01:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-11-05 03:42:13 +00:00
|
|
|
defer cleanup()
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-10-27 11:58:15 +00:00
|
|
|
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))
|
2019-10-31 16:55:35 +00:00
|
|
|
sid, err := sb.AddPiece("foo", dlen, r)
|
2019-10-27 11:58:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-31 16:55:35 +00:00
|
|
|
ticket := 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},
|
|
|
|
}
|
|
|
|
|
|
|
|
pco, err := sb.SealPreCommit(sid, ticket)
|
|
|
|
if err != nil {
|
2019-08-08 01:16:58 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-10-31 16:55:35 +00:00
|
|
|
seed := sectorbuilder.SealSeed{
|
|
|
|
BlockHeight: 15,
|
2019-11-04 16:47:08 +00:00
|
|
|
TicketBytes: [32]byte{0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 45, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9},
|
2019-10-31 16:55:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sco, err := sb.SealCommit(sid, seed)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-08-08 01:16:58 +00:00
|
|
|
|
2019-11-05 17:53:19 +00:00
|
|
|
ok, err := sectorbuilder.VerifySeal(sectorSize, pco.CommR[:], pco.CommD[:], sb.Miner, ticket.TicketBytes[:], seed.TicketBytes[:], sid, sco.Proof)
|
2019-08-08 01:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("proof failed to validate")
|
|
|
|
}
|
|
|
|
}
|