forked from filecoin-project/filecoin-ffi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proofs_test.go
161 lines (128 loc) · 5.44 KB
/
proofs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package ffi
import (
"bytes"
"crypto/rand"
"io"
"math/big"
"os"
"testing"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-state-types/abi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/filecoin-ffi/cgo"
)
func TestRegisteredSealProofFunctions(t *testing.T) {
WorkflowRegisteredSealProofFunctions(newTestingTeeHelper(t))
}
func TestRegisteredPoStProofFunctions(t *testing.T) {
WorkflowRegisteredPoStProofFunctions(newTestingTeeHelper(t))
}
func TestProofsLifecycle(t *testing.T) {
WorkflowProofsLifecycle(newTestingTeeHelper(t))
}
func TestGetGPUDevicesDoesNotProduceAnError(t *testing.T) {
WorkflowGetGPUDevicesDoesNotProduceAnError(newTestingTeeHelper(t))
}
func TestGenerateWinningPoStSectorChallenge(t *testing.T) {
WorkflowGenerateWinningPoStSectorChallenge(newTestingTeeHelper(t))
}
func TestGenerateWinningPoStSectorChallengeEdgeCase(t *testing.T) {
WorkflowGenerateWinningPoStSectorChallengeEdgeCase(newTestingTeeHelper(t))
}
func TestJsonMarshalSymmetry(t *testing.T) {
for i := 0; i < 100; i++ {
xs := make([]publicSectorInfo, 10)
for j := 0; j < 10; j++ {
var x publicSectorInfo
var commR [32]byte
_, err := io.ReadFull(rand.Reader, commR[:])
require.NoError(t, err)
// commR is defined as 32 long above, error can be safely ignored
x.SealedCID, _ = commcid.ReplicaCommitmentV1ToCID(commR[:])
n, err := rand.Int(rand.Reader, big.NewInt(500))
require.NoError(t, err)
x.SectorNum = abi.SectorNumber(n.Uint64())
xs[j] = x
}
toSerialize := newSortedPublicSectorInfo(xs...)
serialized, err := toSerialize.MarshalJSON()
require.NoError(t, err)
var fromSerialized SortedPublicSectorInfo
err = fromSerialized.UnmarshalJSON(serialized)
require.NoError(t, err)
require.Equal(t, toSerialize, fromSerialized)
}
}
func TestDoesNotExhaustFileDescriptors(t *testing.T) {
m := 500 // loops
n := uint64(508) // quantity of piece bytes
for i := 0; i < m; i++ {
// create a temporary file over which we'll compute CommP
file, err := os.CreateTemp("", "")
if err != nil {
panic(err)
}
// create a slice of random bytes (represents our piece)
b := make([]byte, n)
// load up our byte slice with random bytes
if _, err = rand.Read(b); err != nil {
panic(err)
}
// write buffer to temp file
if _, err := bytes.NewBuffer(b).WriteTo(file); err != nil {
panic(err)
}
// seek to beginning of file
if _, err := file.Seek(0, 0); err != nil {
panic(err)
}
if _, err = GeneratePieceCID(abi.RegisteredSealProof_StackedDrg2KiBV1, file.Name(), abi.UnpaddedPieceSize(n)); err != nil {
panic(err)
}
if err = file.Close(); err != nil {
panic(err)
}
}
}
func newTestingTeeHelper(t *testing.T) *testingTeeHelper {
return &testingTeeHelper{t: t}
}
type testingTeeHelper struct {
t *testing.T
}
func (tth *testingTeeHelper) RequireTrue(value bool, msgAndArgs ...interface{}) {
require.True(tth.t, value, msgAndArgs)
}
func (tth *testingTeeHelper) RequireNoError(err error, msgAndArgs ...interface{}) {
require.NoError(tth.t, err, msgAndArgs)
}
func (tth *testingTeeHelper) RequireEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) {
require.Equal(tth.t, expected, actual, msgAndArgs)
}
func (tth *testingTeeHelper) AssertNoError(err error, msgAndArgs ...interface{}) bool {
return assert.NoError(tth.t, err, msgAndArgs)
}
func (tth *testingTeeHelper) AssertEqual(expected, actual interface{}, msgAndArgs ...interface{}) bool {
return assert.Equal(tth.t, expected, actual, msgAndArgs)
}
func (tth *testingTeeHelper) AssertTrue(value bool, msgAndArgs ...interface{}) bool {
return assert.True(tth.t, value, msgAndArgs)
}
func TestProofTypes(t *testing.T) {
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWinning2KiBV1, abi.RegisteredPoStProof_StackedDrgWinning2KiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWinning8MiBV1, abi.RegisteredPoStProof_StackedDrgWinning8MiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWinning512MiBV1, abi.RegisteredPoStProof_StackedDrgWinning512MiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWinning32GiBV1, abi.RegisteredPoStProof_StackedDrgWinning32GiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWinning64GiBV1, abi.RegisteredPoStProof_StackedDrgWinning64GiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWindow2KiBV1, abi.RegisteredPoStProof_StackedDrgWindow2KiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWindow8MiBV1, abi.RegisteredPoStProof_StackedDrgWindow8MiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWindow512MiBV1, abi.RegisteredPoStProof_StackedDrgWindow512MiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWindow32GiBV1, abi.RegisteredPoStProof_StackedDrgWindow32GiBV1)
assert.EqualValues(t, cgo.RegisteredPoStProofStackedDrgWindow64GiBV1, abi.RegisteredPoStProof_StackedDrgWindow64GiBV1)
assert.EqualValues(t, cgo.RegisteredSealProofStackedDrg2KiBV1, abi.RegisteredSealProof_StackedDrg2KiBV1)
assert.EqualValues(t, cgo.RegisteredSealProofStackedDrg8MiBV1, abi.RegisteredSealProof_StackedDrg8MiBV1)
assert.EqualValues(t, cgo.RegisteredSealProofStackedDrg512MiBV1, abi.RegisteredSealProof_StackedDrg512MiBV1)
assert.EqualValues(t, cgo.RegisteredSealProofStackedDrg32GiBV1, abi.RegisteredSealProof_StackedDrg32GiBV1)
assert.EqualValues(t, cgo.RegisteredSealProofStackedDrg64GiBV1, abi.RegisteredSealProof_StackedDrg64GiBV1)
}