@@ -164,15 +164,26 @@ mod tests {
164
164
( hashes, transactions)
165
165
}
166
166
167
+ fn build_prover < F > ( retriever_mock_config : F ) -> MithrilProverService
168
+ where
169
+ F : FnOnce ( & mut MockTransactionsRetriever ) ,
170
+ {
171
+ let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
172
+ retriever_mock_config ( & mut transaction_retriever) ;
173
+
174
+ MithrilProverService :: new ( Arc :: new ( transaction_retriever) )
175
+ }
176
+
167
177
#[ tokio:: test]
168
178
async fn compute_proof_for_one_set_with_multiple_transactions ( ) {
169
179
let ( transaction_hashes, transactions) = generate_transactions ( 3 ) ;
170
- let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
171
- transaction_retriever
172
- . expect_get_up_to ( )
173
- . with ( eq ( fake_data:: beacon ( ) ) )
174
- . return_once ( move |_| Ok ( transactions) ) ;
175
- let prover = MithrilProverService :: new ( Arc :: new ( transaction_retriever) ) ;
180
+ let prover = build_prover ( |retriever_mock| {
181
+ retriever_mock
182
+ . expect_get_up_to ( )
183
+ . with ( eq ( fake_data:: beacon ( ) ) )
184
+ . return_once ( move |_| Ok ( transactions) ) ;
185
+ } ) ;
186
+
176
187
let transactions_set_proof = prover
177
188
. compute_transactions_proofs ( & fake_data:: beacon ( ) , & transaction_hashes)
178
189
. await
@@ -189,12 +200,13 @@ mod tests {
189
200
#[ tokio:: test]
190
201
async fn cant_compute_proof_for_unknown_transaction ( ) {
191
202
let ( transaction_hashes, _transactions) = generate_transactions ( 3 ) ;
192
- let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
193
- transaction_retriever
194
- . expect_get_up_to ( )
195
- . with ( eq ( fake_data:: beacon ( ) ) )
196
- . returning ( |_| Ok ( vec ! [ ] ) ) ;
197
- let prover = MithrilProverService :: new ( Arc :: new ( transaction_retriever) ) ;
203
+ let prover = build_prover ( |retriever_mock| {
204
+ retriever_mock
205
+ . expect_get_up_to ( )
206
+ . with ( eq ( fake_data:: beacon ( ) ) )
207
+ . returning ( |_| Ok ( vec ! [ ] ) ) ;
208
+ } ) ;
209
+
198
210
let transactions_set_proof = prover
199
211
. compute_transactions_proofs ( & fake_data:: beacon ( ) , & transaction_hashes)
200
212
. await
@@ -206,14 +218,15 @@ mod tests {
206
218
#[ tokio:: test]
207
219
async fn compute_proof_for_one_set_of_three_known_transactions_and_two_unknowns ( ) {
208
220
let ( transaction_hashes, transactions) = generate_transactions ( 5 ) ;
209
- // The last two are not in the "store"
210
- let transactions = transactions[ 0 ..=2 ] . to_vec ( ) ;
211
- let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
212
- transaction_retriever
213
- . expect_get_up_to ( )
214
- . with ( eq ( fake_data:: beacon ( ) ) )
215
- . return_once ( move |_| Ok ( transactions) ) ;
216
- let prover = MithrilProverService :: new ( Arc :: new ( transaction_retriever) ) ;
221
+ let prover = build_prover ( |retriever_mock| {
222
+ // The last two are not in the "store"
223
+ let transactions = transactions[ 0 ..=2 ] . to_vec ( ) ;
224
+ retriever_mock
225
+ . expect_get_up_to ( )
226
+ . with ( eq ( fake_data:: beacon ( ) ) )
227
+ . return_once ( move |_| Ok ( transactions) ) ;
228
+ } ) ;
229
+
217
230
let transactions_set_proof = prover
218
231
. compute_transactions_proofs ( & fake_data:: beacon ( ) , & transaction_hashes)
219
232
. await
@@ -230,13 +243,13 @@ mod tests {
230
243
#[ tokio:: test]
231
244
async fn cant_compute_proof_if_retriever_fail ( ) {
232
245
let ( transaction_hashes, _transactions) = generate_transactions ( 3 ) ;
233
- let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
234
- transaction_retriever
235
- . expect_get_up_to ( )
236
- . with ( eq ( fake_data:: beacon ( ) ) )
237
- . returning ( |_| Err ( anyhow ! ( "Error" ) ) ) ;
246
+ let prover = build_prover ( |retriever_mock| {
247
+ retriever_mock
248
+ . expect_get_up_to ( )
249
+ . with ( eq ( fake_data:: beacon ( ) ) )
250
+ . returning ( |_| Err ( anyhow ! ( "Error" ) ) ) ;
251
+ } ) ;
238
252
239
- let prover = MithrilProverService :: new ( Arc :: new ( transaction_retriever) ) ;
240
253
prover
241
254
. compute_transactions_proofs ( & fake_data:: beacon ( ) , & transaction_hashes)
242
255
. await
0 commit comments