zerocomm: 'Fix' the test
This commit is contained in:
parent
767392332e
commit
2aeab13aae
10
lib/nullreader/reader.go
Normal file
10
lib/nullreader/reader.go
Normal file
@ -0,0 +1,10 @@
|
||||
package nullreader
|
||||
|
||||
type Reader struct{}
|
||||
|
||||
func (Reader) Read(out []byte) (int, error) {
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
return len(out), nil
|
||||
}
|
@ -3,44 +3,87 @@ package zerocomm
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
abi "github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/lib/nullreader"
|
||||
)
|
||||
|
||||
func TestComms(t *testing.T) {
|
||||
t.Skip("don't have enough ram") // no, but seriously, currently this needs like 3tb of /tmp
|
||||
|
||||
var expPieceComms [levels - skip]cid.Cid
|
||||
|
||||
{
|
||||
l2, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 127)), 127)
|
||||
if err != nil {
|
||||
return
|
||||
t.Fatal(err)
|
||||
}
|
||||
expPieceComms[0] = l2
|
||||
}
|
||||
|
||||
for i := 1; i < levels-2; i++ {
|
||||
var err error
|
||||
sectorbuilder.GenerateUnsealedCID()
|
||||
expPieceComms[i], err = sectorbuilder.GenerateDataCommitment(128<<i, []sectorbuilder.PublicPieceInfo{
|
||||
{
|
||||
Size: 127 << (i - 1),
|
||||
CommP: expPieceComms[i-1],
|
||||
},
|
||||
{
|
||||
Size: 127 << (i - 1),
|
||||
CommP: expPieceComms[i-1],
|
||||
},
|
||||
})
|
||||
sz := abi.UnpaddedPieceSize(127 << i)
|
||||
fmt.Println(i, sz)
|
||||
r := io.LimitReader(&nullreader.Reader{}, int64(sz))
|
||||
|
||||
expPieceComms[i], err = sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, r, sz)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i, comm := range expPieceComms {
|
||||
if string(comm[:]) != string(pieceComms[i][:]) {
|
||||
c, err := commcid.CIDToPieceCommitmentV1(comm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(c) != string(pieceComms[i][:]) {
|
||||
t.Errorf("zero commitment %d didn't match", i)
|
||||
}
|
||||
}
|
||||
|
||||
for _, comm := range expPieceComms { // Could do codegen, but this is good enough
|
||||
fmt.Printf("%#v,\n", comm)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommsSmall(t *testing.T) {
|
||||
var expPieceComms [8]cid.Cid
|
||||
lvls := len(expPieceComms) + skip
|
||||
|
||||
{
|
||||
l2, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 127)), 127)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
expPieceComms[0] = l2
|
||||
}
|
||||
|
||||
for i := 1; i < lvls-2; i++ {
|
||||
var err error
|
||||
sz := abi.UnpaddedPieceSize(127 << i)
|
||||
fmt.Println(i, sz)
|
||||
r := io.LimitReader(&nullreader.Reader{}, int64(sz))
|
||||
|
||||
expPieceComms[i], err = sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, r, sz)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
for i, comm := range expPieceComms {
|
||||
c, err := commcid.CIDToPieceCommitmentV1(comm)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(c) != string(pieceComms[i][:]) {
|
||||
t.Errorf("zero commitment %d didn't match", i)
|
||||
}
|
||||
}
|
||||
@ -51,13 +94,13 @@ func TestComms(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestForSise(t *testing.T) {
|
||||
exp, err := sectorbuilder.GeneratePieceCommitment(bytes.NewReader(make([]byte, 1016)), 1016)
|
||||
exp, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 1016)), 1016)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
actual := ForSize(1016)
|
||||
if string(exp[:]) != string(actual[:]) {
|
||||
if !exp.Equals(actual) {
|
||||
t.Errorf("zero commitment didn't match")
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,12 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
|
||||
"github.com/filecoin-project/lotus/lib/nullreader"
|
||||
)
|
||||
|
||||
type nullReader struct{}
|
||||
|
||||
func (nullReader) Read(out []byte) (int, error) {
|
||||
for i := range out {
|
||||
out[i] = 0
|
||||
}
|
||||
return len(out), nil
|
||||
}
|
||||
|
||||
func (m *Sealing) pledgeReader(size abi.UnpaddedPieceSize) io.Reader {
|
||||
return io.LimitReader(&nullReader{}, int64(size))
|
||||
return io.LimitReader(&nullreader.Reader{}, int64(size))
|
||||
}
|
||||
|
||||
func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]Piece, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user