forked from Consensys/gnark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert_options.go
178 lines (155 loc) · 5.27 KB
/
assert_options.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package test
import (
"testing"
"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend"
"github.com/consensys/gnark/constraint/solver"
"github.com/consensys/gnark/frontend"
)
// TestingOption defines option for altering the behavior of Assert methods.
// See the descriptions of functions returning instances of this type for
// particular options.
type TestingOption func(*testingConfig) error
type testingConfig struct {
profile
solverOpts []solver.Option
proverOpts []backend.ProverOption
verifierOpts []backend.VerifierOption
compileOpts []frontend.CompileOption
validAssignments []frontend.Circuit
invalidAssignments []frontend.Circuit
}
// default options
func (assert *Assert) options(opts ...TestingOption) testingConfig {
var opt testingConfig
// default options;
// go test -short --> testEngineOnly
// go test --> constraintOnlyProfile
// go test -tags=prover_checks --> proverOnlyProfile
// go test -tags=release_checks --> releaseProfile
if releaseTestFlag {
opt.profile = releaseChecks
} else if proverTestFlag {
opt.profile = proverChecks
} else if testing.Short() {
opt.profile = testEngineChecks
} else {
opt.profile = constraintSolverChecks
}
// apply user provided options.
for _, option := range opts {
err := option(&opt)
assert.NoError(err, "parsing TestingOption")
}
return opt
}
// WithValidAssignment is a testing option which adds a valid assignment
func WithValidAssignment(validAssignment frontend.Circuit) TestingOption {
return func(opt *testingConfig) error {
opt.validAssignments = append(opt.validAssignments, validAssignment)
return nil
}
}
// WithInvalidAssignment is a testing option which adds an invalid assignment
func WithInvalidAssignment(invalidAssignment frontend.Circuit) TestingOption {
return func(opt *testingConfig) error {
opt.invalidAssignments = append(opt.invalidAssignments, invalidAssignment)
return nil
}
}
// WithBackends is testing option which restricts the backends the assertions are
// run. When not given, runs on all implemented backends.
func WithBackends(b backend.ID, backends ...backend.ID) TestingOption {
return func(opt *testingConfig) error {
opt.backends = []backend.ID{b}
opt.backends = append(opt.backends, backends...)
return nil
}
}
// WithCurves is a testing option which restricts the curves the assertions are
// run. When not given, runs on all implemented curves.
func WithCurves(c ecc.ID, curves ...ecc.ID) TestingOption {
return func(opt *testingConfig) error {
opt.curves = []ecc.ID{c}
opt.curves = append(opt.curves, curves...)
return nil
}
}
// NoSerializationChecks is a testing option which disables serialization checks,
// even when the build tag "release_checks" is set.
func NoSerializationChecks() TestingOption {
return func(opt *testingConfig) error {
opt.checkSerialization = false
return nil
}
}
// NoFuzzing is a testing option which disables fuzzing tests,
// even when the build tag "release_checks" is set.
func NoFuzzing() TestingOption {
return func(opt *testingConfig) error {
opt.fuzzing = false
return nil
}
}
// NoProverChecks is a testing option which disables prover checks,
// even when the build tag "prover_checks" or "release_checks" are set.
func NoProverChecks() TestingOption {
return func(opt *testingConfig) error {
opt.checkProver = false
return nil
}
}
// NoTestEngine is a testing option which disables test engine checks
func NoTestEngine() TestingOption {
return func(opt *testingConfig) error {
opt.skipTestEngine = true
return nil
}
}
// NoSolidityChecks is a testing option which disables solidity checks,
// even when the build tags "solccheck" and "release_checks" are set.
//
// When the tags are set; this requires gnark-solidity-checker to be installed, which in turns
// requires solc and abigen to be reachable in the PATH.
//
// See https://github.com/ConsenSys/gnark-solidity-checker for more details.
func NoSolidityChecks() TestingOption {
return func(opt *testingConfig) error {
opt.checkSolidity = false
return nil
}
}
// WithProverOpts is a testing option which uses the given proverOpts when
// calling backend.Prover, backend.ReadAndProve and backend.IsSolved methods in
// assertions.
func WithProverOpts(proverOpts ...backend.ProverOption) TestingOption {
return func(opt *testingConfig) error {
opt.proverOpts = proverOpts
return nil
}
}
// WithSolverOpts is a testing option which uses the given solverOpts when
// calling constraint system solver.
func WithSolverOpts(solverOpts ...solver.Option) TestingOption {
return func(opt *testingConfig) error {
opt.proverOpts = append(opt.proverOpts, backend.WithSolverOptions(solverOpts...))
opt.solverOpts = solverOpts
return nil
}
}
// WithCompileOpts is a testing option which uses the given compileOpts when
// calling frontend.Compile in assertions.
func WithCompileOpts(compileOpts ...frontend.CompileOption) TestingOption {
return func(opt *testingConfig) error {
opt.compileOpts = compileOpts
return nil
}
}
// WithVerifierOpts is a testing option which uses the given verifierOpts when
// calling backend.Verify method.
func WithVerifierOpts(verifierOpts ...backend.VerifierOption) TestingOption {
return func(tc *testingConfig) error {
tc.verifierOpts = append(tc.verifierOpts, verifierOpts...)
return nil
}
}