Skip to content

Commit 4606b1a

Browse files
committed
add a test for the padding code
1 parent 9d7f7aa commit 4606b1a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

ffiwrapper/ffiwrapper_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package ffiwrapper
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/filecoin-project/go-state-types/abi"
8+
"github.com/ipfs/go-cid"
9+
)
10+
11+
func TestZeroPadding(t *testing.T) {
12+
psize := abi.PaddedPieceSize(128).Unpadded()
13+
data := make([]byte, psize)
14+
15+
content := []byte("i am the biggest cat, what do you think about that")
16+
copy(data, content)
17+
18+
pcid, err := GeneratePieceCIDFromFile(abi.RegisteredSealProof_StackedDrg32GiBV1_1, bytes.NewReader(data), psize)
19+
if err != nil {
20+
t.Fatal(err)
21+
}
22+
23+
// value calculated using separate tooling
24+
expCid, err := cid.Decode("baga6ea4seaqozp3abki6vgdf7ztbipcycmxfyt2o64cpuyvdkczsjxsg7bqmioi")
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
29+
if pcid != expCid {
30+
t.Fatalf("expected %s, got %s", expCid, pcid)
31+
}
32+
33+
padded, err := ZeroPadPieceCommitment(pcid, psize, psize*4)
34+
if err != nil {
35+
t.Fatal(err)
36+
}
37+
38+
data2 := make([]byte, psize*4)
39+
copy(data2, content)
40+
41+
padExpCid, err := GeneratePieceCIDFromFile(abi.RegisteredSealProof_StackedDrg32GiBV1_1, bytes.NewReader(data2), psize*4)
42+
if err != nil {
43+
t.Fatal(err)
44+
}
45+
46+
if padded != padExpCid {
47+
t.Fatalf("wrong padding, expected %s, got %s", padExpCid, padded)
48+
}
49+
}

0 commit comments

Comments
 (0)