@@ -199,8 +199,6 @@ impl MithrilClient {
199
199
}
200
200
}
201
201
202
- // The tests are commented for now, as we don't want to run them on a testnet aggregator.
203
- /*
204
202
#[ cfg( test) ]
205
203
mod tests {
206
204
use super :: * ;
@@ -210,60 +208,63 @@ mod tests {
210
208
} ;
211
209
use wasm_bindgen_test:: * ;
212
210
213
- const AGGREGATOR_ENDPOINT: &str =
214
- "https://aggregator.testing-preview.api.mithril.network/aggregator";
215
211
const GENESIS_VERIFICATION_KEY : & str = "5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c3235322c3138302c37322c3133342c3133372c3234372c3136312c36385d" ;
212
+ const FAKE_AGGREGATOR_IP : & str = "127.0.0.1" ;
213
+ const FAKE_AGGREGATOR_PORT : & str = "8000" ;
214
+ const FAKE_AGGREGATOR_SNAPSHOT_DIGEST : & str =
215
+ "000ee4c84c7b64a62dc30ec78a765a1f3bb81cd9dd4bd1eccf9f2da785e70877" ;
216
+ const FAKE_AGGREGATOR_MSD_HASH : & str =
217
+ "03ebb00e6626037f2e58eb7cc50d308fd57c253baa1fe2b04eb5945ced16b5bd" ;
218
+ const FAKE_CERTIFICATE_HASH : & str =
219
+ "05bf6740e781e649dd2fe7e3319818747d8038ca759c67711c90cf24cdade8a9" ;
220
+
221
+ fn get_mithril_client ( ) -> MithrilClient {
222
+ MithrilClient :: new (
223
+ & format ! (
224
+ "http://{}:{}/aggregator" ,
225
+ FAKE_AGGREGATOR_IP , FAKE_AGGREGATOR_PORT
226
+ ) ,
227
+ GENESIS_VERIFICATION_KEY ,
228
+ )
229
+ }
216
230
217
231
wasm_bindgen_test_configure ! ( run_in_browser) ;
218
232
#[ wasm_bindgen_test]
219
233
async fn list_snapshots_should_return_value_convertible_in_rust_type ( ) {
220
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
221
-
222
- let snapshots_list_js_value = client
234
+ let snapshots_list_js_value = get_mithril_client ( )
223
235
. list_snapshots ( )
224
236
. await
225
237
. expect ( "list_snapshots should not fail" ) ;
226
238
let snapshots_list =
227
239
serde_wasm_bindgen:: from_value :: < Vec < SnapshotListItem > > ( snapshots_list_js_value)
228
240
. expect ( "conversion should not fail" ) ;
229
241
230
- assert_eq!(snapshots_list.len(), 20 );
242
+ assert_eq ! ( snapshots_list. len( ) , 3 ) ;
231
243
}
232
244
233
245
#[ wasm_bindgen_test]
234
246
async fn get_snapshot_should_return_value_convertible_in_rust_type ( ) {
235
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
236
- let snapshots_list_js_value = client.list_snapshots().await.unwrap();
237
- let snapshots_list =
238
- serde_wasm_bindgen::from_value::<Vec<SnapshotListItem>>(snapshots_list_js_value)
239
- .unwrap();
240
- let last_digest = &snapshots_list.first().unwrap().digest;
241
-
242
- let snapshot_js_value = client
243
- .get_snapshot(last_digest)
247
+ let snapshot_js_value = get_mithril_client ( )
248
+ . get_snapshot ( FAKE_AGGREGATOR_SNAPSHOT_DIGEST )
244
249
. await
245
250
. expect ( "get_snapshot should not fail" ) ;
246
251
let snapshot = serde_wasm_bindgen:: from_value :: < Snapshot > ( snapshot_js_value)
247
252
. expect ( "conversion should not fail" ) ;
248
253
249
- assert_eq!(snapshot.digest, last_digest.to_string() );
254
+ assert_eq ! ( snapshot. digest, FAKE_AGGREGATOR_SNAPSHOT_DIGEST ) ;
250
255
}
251
256
252
257
#[ wasm_bindgen_test]
253
258
async fn get_snapshot_should_fail_with_unknown_digest ( ) {
254
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
255
-
256
- client
259
+ get_mithril_client ( )
257
260
. get_snapshot ( "whatever" )
258
261
. await
259
262
. expect_err ( "get_snapshot should fail" ) ;
260
263
}
261
264
262
265
#[ wasm_bindgen_test]
263
266
async fn list_mithril_stake_distributions_should_return_value_convertible_in_rust_type ( ) {
264
- let wasm_client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
265
-
266
- let msd_list_js_value = wasm_client
267
+ let msd_list_js_value = get_mithril_client ( )
267
268
. list_mithril_stake_distributions ( )
268
269
. await
269
270
. expect ( "list_mithril_stake_distributions should not fail" ) ;
@@ -272,44 +273,32 @@ mod tests {
272
273
)
273
274
. expect ( "conversion should not fail" ) ;
274
275
275
- assert_eq!(msd_list.len(), 20 );
276
+ assert_eq ! ( msd_list. len( ) , 3 ) ;
276
277
}
277
278
278
279
#[ wasm_bindgen_test]
279
280
async fn get_mithril_stake_distribution_should_return_value_convertible_in_rust_type ( ) {
280
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
281
- let msd_list_js_value = client.list_mithril_stake_distributions().await.unwrap();
282
- let msd_list = serde_wasm_bindgen::from_value::<Vec<MithrilStakeDistributionListItem>>(
283
- msd_list_js_value,
284
- )
285
- .unwrap();
286
- let last_hash = &msd_list.first().unwrap().hash;
287
-
288
- let msd_js_value = client
289
- .get_mithril_stake_distribution(last_hash)
281
+ let msd_js_value = get_mithril_client ( )
282
+ . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
290
283
. await
291
284
. expect ( "get_mithril_stake_distribution should not fail" ) ;
292
285
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value)
293
286
. expect ( "conversion should not fail" ) ;
294
287
295
- assert_eq!(msd.hash, last_hash.to_string() );
288
+ assert_eq ! ( msd. hash, FAKE_AGGREGATOR_MSD_HASH ) ;
296
289
}
297
290
298
291
#[ wasm_bindgen_test]
299
292
async fn get_mithril_stake_distribution_should_fail_with_unknown_hash ( ) {
300
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
301
-
302
- client
293
+ get_mithril_client ( )
303
294
. get_mithril_stake_distribution ( "whatever" )
304
295
. await
305
296
. expect_err ( "get_mithril_stake_distribution should fail" ) ;
306
297
}
307
298
308
299
#[ wasm_bindgen_test]
309
300
async fn list_mithril_certificates_should_return_value_convertible_in_rust_type ( ) {
310
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
311
-
312
- let certificates_list_js_value = client
301
+ let certificates_list_js_value = get_mithril_client ( )
313
302
. list_mithril_certificates ( )
314
303
. await
315
304
. expect ( "list_mithril_certificates should not fail" ) ;
@@ -318,35 +307,25 @@ mod tests {
318
307
)
319
308
. expect ( "conversion should not fail" ) ;
320
309
321
- assert_eq!(certificates_list.len(), 20 );
310
+ assert_eq ! ( certificates_list. len( ) , 7 ) ;
322
311
}
323
312
324
313
#[ wasm_bindgen_test]
325
314
async fn get_mithril_certificate_should_return_value_convertible_in_rust_type ( ) {
326
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
327
- let certificates_list_js_value = client.list_mithril_certificates().await.unwrap();
328
- let certificates_list = serde_wasm_bindgen::from_value::<Vec<MithrilCertificateListItem>>(
329
- certificates_list_js_value,
330
- )
331
- .unwrap();
332
- let last_hash = &certificates_list.first().unwrap().hash;
333
-
334
- let certificate_js_value = client
335
- .get_mithril_certificate(last_hash)
315
+ let certificate_js_value = get_mithril_client ( )
316
+ . get_mithril_certificate ( FAKE_CERTIFICATE_HASH )
336
317
. await
337
318
. expect ( "get_mithril_certificate should not fail" ) ;
338
319
let certificate =
339
320
serde_wasm_bindgen:: from_value :: < MithrilCertificate > ( certificate_js_value)
340
321
. expect ( "conversion should not fail" ) ;
341
322
342
- assert_eq!(certificate.hash, last_hash.to_string() );
323
+ assert_eq ! ( certificate. hash, FAKE_CERTIFICATE_HASH ) ;
343
324
}
344
325
345
326
#[ wasm_bindgen_test]
346
327
async fn get_mithril_certificate_should_fail_with_unknown_hash ( ) {
347
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
348
-
349
- client
328
+ get_mithril_client ( )
350
329
. get_mithril_certificate ( "whatever" )
351
330
. await
352
331
. expect_err ( "get_mithril_certificate should fail" ) ;
@@ -355,15 +334,9 @@ mod tests {
355
334
#[ wasm_bindgen_test]
356
335
async fn compute_mithril_stake_distribution_message_should_return_value_convertible_in_rust_type (
357
336
) {
358
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
359
- let msd_list_js_value = client.list_mithril_stake_distributions().await.unwrap();
360
- let msd_list = serde_wasm_bindgen::from_value::<Vec<MithrilStakeDistributionListItem>>(
361
- msd_list_js_value,
362
- )
363
- .unwrap();
364
- let last_hash = &msd_list.first().unwrap().hash;
337
+ let client = get_mithril_client ( ) ;
365
338
let msd_js_value = client
366
- .get_mithril_stake_distribution(last_hash )
339
+ . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
367
340
. await
368
341
. unwrap ( ) ;
369
342
@@ -375,20 +348,11 @@ mod tests {
375
348
. expect ( "conversion should not fail" ) ;
376
349
}
377
350
378
- // This test is commented for now as it's execution takes too long with a real testnet aggregator
379
- // Timeout in tests is 20s
380
- /*
381
351
#[ wasm_bindgen_test]
382
352
async fn verify_certificate_chain_should_return_value_convertible_in_rust_type ( ) {
383
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
384
- let msd_list_js_value = client.list_mithril_stake_distributions().await.unwrap();
385
- let msd_list = serde_wasm_bindgen::from_value::<Vec<MithrilStakeDistributionListItem>>(
386
- msd_list_js_value,
387
- )
388
- .unwrap();
389
- let last_hash = &msd_list.first().unwrap().hash;
353
+ let client = get_mithril_client ( ) ;
390
354
let msd_js_value = client
391
- .get_mithril_stake_distribution(last_hash )
355
+ . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
392
356
. await
393
357
. unwrap ( ) ;
394
358
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value) . unwrap ( ) ;
@@ -400,22 +364,12 @@ mod tests {
400
364
serde_wasm_bindgen:: from_value :: < MithrilCertificate > ( certificate_js_value)
401
365
. expect ( "conversion should not fail" ) ;
402
366
}
403
- */
404
367
405
- // This test is commented for now as it's execution takes too long with a real testnet aggregator
406
- // Timeout in tests is 20s
407
- /*
408
368
#[ wasm_bindgen_test]
409
369
async fn verify_message_match_certificate_should_return_true ( ) {
410
- let client = MithrilClient::new(AGGREGATOR_ENDPOINT, GENESIS_VERIFICATION_KEY);
411
- let msd_list_js_value = client.list_mithril_stake_distributions().await.unwrap();
412
- let msd_list = serde_wasm_bindgen::from_value::<Vec<MithrilStakeDistributionListItem>>(
413
- msd_list_js_value,
414
- )
415
- .unwrap();
416
- let last_hash = &msd_list.first().unwrap().hash;
370
+ let client = get_mithril_client ( ) ;
417
371
let msd_js_value = client
418
- .get_mithril_stake_distribution(last_hash )
372
+ . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
419
373
. await
420
374
. unwrap ( ) ;
421
375
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value. clone ( ) )
@@ -434,6 +388,4 @@ mod tests {
434
388
. await
435
389
. expect ( "verify_message_match_certificate should not fail" ) ;
436
390
}
437
- */
438
391
}
439
- */
0 commit comments