@@ -12,16 +12,17 @@ import (
1212 "runtime"
1313 "strconv"
1414 "testing"
15+ "time"
1516
1617 math "github.com/IBM/mathlib"
1718 "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
18- "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/benchmark"
1919 math2 "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/crypto/math"
2020 v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
2121 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/token"
2222 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/transfer"
2323 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/transfer/mock"
2424 "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
25+ benchmark2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/benchmark"
2526 token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
2627 "github.com/stretchr/testify/assert"
2728 "github.com/stretchr/testify/require"
@@ -65,14 +66,14 @@ func TestSender(t *testing.T) {
6566// BenchmarkSender benchmarks transfer action generation and serialization.
6667// This includes the proof generation as well.
6768func BenchmarkSender (b * testing.B ) {
68- bits , err := benchmark .Bits (32 , 64 )
69+ bits , err := benchmark2 .Bits (32 , 64 )
6970 require .NoError (b , err )
70- curves := benchmark .Curves (math .BN254 , math .BLS12_381_BBS_GURVY , math2 .BLS12_381_BBS_GURVY_FAST_RNG )
71- inputs , err := benchmark .NumInputs (1 , 2 , 3 )
71+ curves := benchmark2 .Curves (math .BN254 , math .BLS12_381_BBS_GURVY , math2 .BLS12_381_BBS_GURVY_FAST_RNG )
72+ inputs , err := benchmark2 .NumInputs (1 , 2 , 3 )
7273 require .NoError (b , err )
73- outputs , err := benchmark .NumOutputs (1 , 2 , 3 )
74+ outputs , err := benchmark2 .NumOutputs (1 , 2 , 3 )
7475 require .NoError (b , err )
75- testCases := benchmark .GenerateCases (bits , curves , inputs , outputs , []int {1 })
76+ testCases := benchmark2 .GenerateCases (bits , curves , inputs , outputs , []int {1 })
7677
7778 for _ , tc := range testCases {
7879 b .Run (tc .Name , func (b * testing.B ) {
@@ -100,37 +101,39 @@ func BenchmarkSender(b *testing.B) {
100101
101102// TestParallelBenchmarkSender benchmarks transfer action generation and serialization when multiple go routines are doing the same thing.
102103func TestParallelBenchmarkSender (t * testing.T ) {
103- bits , err := benchmark .Bits (32 )
104+ bits , err := benchmark2 .Bits (32 )
104105 require .NoError (t , err )
105- curves := benchmark .Curves (math .BN254 )
106- inputs , err := benchmark .NumInputs (2 )
106+ curves := benchmark2 .Curves (math .BN254 )
107+ inputs , err := benchmark2 .NumInputs (2 )
107108 require .NoError (t , err )
108- outputs , err := benchmark .NumOutputs (2 )
109+ outputs , err := benchmark2 .NumOutputs (2 )
109110 require .NoError (t , err )
110- workers , err := benchmark .Workers (runtime .NumCPU ())
111+ workers , err := benchmark2 .Workers (runtime .NumCPU ())
111112 require .NoError (t , err )
112- testCases := benchmark .GenerateCases (bits , curves , inputs , outputs , workers )
113+ testCases := benchmark2 .GenerateCases (bits , curves , inputs , outputs , workers )
113114
114115 for _ , tc := range testCases {
115116 t .Run (tc .Name , func (t * testing.T ) {
116- r := benchmark .RunBenchmark (
117+ r := benchmark2 .RunBenchmark (
117118 tc .BenchmarkCase .Workers ,
118- benchmark .Duration (),
119+ benchmark2 .Duration (),
120+ 3 * time .Second ,
119121 func () * benchmarkSenderEnv {
120122 env , err := newBenchmarkSenderEnv (1 , tc .BenchmarkCase )
121123 require .NoError (t , err )
122124 return env
123125 },
124- func (env * benchmarkSenderEnv ) {
126+ func (env * benchmarkSenderEnv ) error {
125127 transfer , _ , err := env .SenderEnvs [0 ].sender .GenerateZKTransfer (
126128 t .Context (),
127129 env .SenderEnvs [0 ].outvalues ,
128130 env .SenderEnvs [0 ].owners ,
129131 )
130- require .NoError (t , err )
131- assert .NotNil (t , transfer )
132+ if err != nil {
133+ return err
134+ }
132135 _ , err = transfer .Serialize ()
133- require . NoError ( t , err )
136+ return err
134137 },
135138 )
136139 r .Print ()
@@ -140,14 +143,14 @@ func TestParallelBenchmarkSender(t *testing.T) {
140143
141144// BenchmarkVerificationSenderProof benchmarks transfer action deserialization and proof verification.
142145func BenchmarkVerificationSenderProof (b * testing.B ) {
143- bits , err := benchmark .Bits (32 , 64 )
146+ bits , err := benchmark2 .Bits (32 , 64 )
144147 require .NoError (b , err )
145- curves := benchmark .Curves (math .BN254 , math .BLS12_381_BBS_GURVY , math2 .BLS12_381_BBS_GURVY_FAST_RNG )
146- inputs , err := benchmark .NumInputs (1 , 2 , 3 )
148+ curves := benchmark2 .Curves (math .BN254 , math .BLS12_381_BBS_GURVY , math2 .BLS12_381_BBS_GURVY_FAST_RNG )
149+ inputs , err := benchmark2 .NumInputs (1 , 2 , 3 )
147150 require .NoError (b , err )
148- outputs , err := benchmark .NumOutputs (1 , 2 , 3 )
151+ outputs , err := benchmark2 .NumOutputs (1 , 2 , 3 )
149152 require .NoError (b , err )
150- testCases := benchmark .GenerateCases (bits , curves , inputs , outputs , []int {1 })
153+ testCases := benchmark2 .GenerateCases (bits , curves , inputs , outputs , []int {1 })
151154
152155 for _ , tc := range testCases {
153156 b .Run (tc .Name , func (b * testing.B ) {
@@ -182,44 +185,45 @@ func BenchmarkVerificationSenderProof(b *testing.B) {
182185
183186// TestParallelBenchmarkVerificationSenderProof benchmarks transfer action deserialization and proof verification when multiple go routines are doing the same thing.
184187func TestParallelBenchmarkVerificationSenderProof (t * testing.T ) {
185- bits , err := benchmark .Bits (32 )
188+ bits , err := benchmark2 .Bits (32 )
186189 require .NoError (t , err )
187- curves := benchmark .Curves (math .BN254 )
188- inputs , err := benchmark .NumInputs (2 )
190+ curves := benchmark2 .Curves (math .BN254 )
191+ inputs , err := benchmark2 .NumInputs (2 )
189192 require .NoError (t , err )
190- outputs , err := benchmark .NumOutputs (2 )
193+ outputs , err := benchmark2 .NumOutputs (2 )
191194 require .NoError (t , err )
192- workers , err := benchmark .Workers (runtime .NumCPU ())
195+ workers , err := benchmark2 .Workers (runtime .NumCPU ())
193196 require .NoError (t , err )
194- testCases := benchmark .GenerateCases (bits , curves , inputs , outputs , workers )
197+ testCases := benchmark2 .GenerateCases (bits , curves , inputs , outputs , workers )
195198
196199 for _ , tc := range testCases {
197200 t .Run (tc .Name , func (t * testing.T ) {
198- r := benchmark .RunBenchmark (
201+ r := benchmark2 .RunBenchmark (
199202 tc .BenchmarkCase .Workers ,
200- benchmark .Duration (),
203+ benchmark2 .Duration (),
204+ 3 * time .Second ,
201205 func () * benchmarkSenderEnv {
202206 env , err := newBenchmarkSenderProofVerificationEnv (t .Context (), 1 , tc .BenchmarkCase )
203207 require .NoError (t , err )
204208 return env
205209 },
206- func (env * benchmarkSenderEnv ) {
210+ func (env * benchmarkSenderEnv ) error {
207211 // deserialize action
208212 ta := & transfer.Action {}
209- require .NoError (t , ta .Deserialize (env .SenderEnvs [0 ].transferRaw ))
213+ if err := ta .Deserialize (env .SenderEnvs [0 ].transferRaw ); err != nil {
214+ return err
215+ }
210216 inputTokens := make ([]* math.G1 , len (ta .Inputs ))
211217 for j , in := range ta .Inputs {
212218 inputTokens [j ] = in .Token .Data
213219 }
214220
215221 // instantiate the verifier and verify
216- require .NoError (t ,
217- transfer .NewVerifier (
218- inputTokens ,
219- ta .GetOutputCommitments (),
220- env .SenderEnvs [0 ].sender .PublicParams ,
221- ).Verify (ta .GetProof ()),
222- )
222+ return transfer .NewVerifier (
223+ inputTokens ,
224+ ta .GetOutputCommitments (),
225+ env .SenderEnvs [0 ].sender .PublicParams ,
226+ ).Verify (ta .GetProof ())
223227 },
224228 )
225229 r .Print ()
@@ -329,7 +333,7 @@ type benchmarkSenderEnv struct {
329333 SenderEnvs []* senderEnv
330334}
331335
332- func newBenchmarkSenderEnv (n int , benchmarkCase * benchmark .Case ) (* benchmarkSenderEnv , error ) {
336+ func newBenchmarkSenderEnv (n int , benchmarkCase * benchmark2 .Case ) (* benchmarkSenderEnv , error ) {
333337 envs := make ([]* senderEnv , n )
334338 pp , err := setup (benchmarkCase .Bits , benchmarkCase .CurveID )
335339 if err != nil {
@@ -344,7 +348,7 @@ func newBenchmarkSenderEnv(n int, benchmarkCase *benchmark.Case) (*benchmarkSend
344348 return & benchmarkSenderEnv {SenderEnvs : envs }, nil
345349}
346350
347- func newBenchmarkSenderProofVerificationEnv (ctx context.Context , n int , benchmarkCase * benchmark .Case ) (* benchmarkSenderEnv , error ) {
351+ func newBenchmarkSenderProofVerificationEnv (ctx context.Context , n int , benchmarkCase * benchmark2 .Case ) (* benchmarkSenderEnv , error ) {
348352 envs := make ([]* senderEnv , n )
349353 pp , err := setup (benchmarkCase .Bits , benchmarkCase .CurveID )
350354 if err != nil {
0 commit comments