lotus/lib/zerocomm/zerocomm_test.go

107 lines
2.5 KiB
Go
Raw Normal View History

2020-02-22 14:03:32 +00:00
package zerocomm
import (
"bytes"
"fmt"
2020-02-27 00:54:39 +00:00
"io"
2020-02-22 14:03:32 +00:00
"testing"
2020-02-27 00:54:39 +00:00
commcid "github.com/filecoin-project/go-fil-commcid"
2020-02-22 14:03:32 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2020-02-26 22:54:34 +00:00
abi "github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
2020-02-27 00:54:39 +00:00
"github.com/filecoin-project/lotus/lib/nullreader"
2020-02-22 14:03:32 +00:00
)
func TestComms(t *testing.T) {
2020-02-27 00:54:39 +00:00
t.Skip("don't have enough ram") // no, but seriously, currently this needs like 3tb of /tmp
2020-02-26 22:54:34 +00:00
var expPieceComms [levels - skip]cid.Cid
2020-02-22 14:03:32 +00:00
{
2020-02-26 22:54:34 +00:00
l2, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 127)), 127)
2020-02-22 14:03:32 +00:00
if err != nil {
2020-02-27 00:54:39 +00:00
t.Fatal(err)
2020-02-22 14:03:32 +00:00
}
expPieceComms[0] = l2
}
for i := 1; i < levels-2; i++ {
var err error
2020-02-27 00:54:39 +00:00
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)
2020-02-22 14:03:32 +00:00
if err != nil {
2020-02-27 00:54:39 +00:00
t.Fatal(err)
2020-02-22 14:03:32 +00:00
}
}
for i, comm := range expPieceComms {
2020-02-27 00:54:39 +00:00
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][:]) {
2020-02-22 14:03:32 +00:00
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 TestForSise(t *testing.T) {
2020-02-27 00:54:39 +00:00
exp, err := sectorbuilder.GeneratePieceCIDFromFile(abi.RegisteredProof_StackedDRG2KiBPoSt, bytes.NewReader(make([]byte, 1016)), 1016)
2020-02-22 14:03:32 +00:00
if err != nil {
return
}
actual := ForSize(1016)
2020-02-27 00:54:39 +00:00
if !exp.Equals(actual) {
2020-02-22 14:03:32 +00:00
t.Errorf("zero commitment didn't match")
}
}