@@ -51,9 +51,18 @@ impl From<MithrilEvent> for MithrilEventWasm {
51
51
}
52
52
53
53
/// Structure that wraps a [Client] and enables its functions to be used in WASM
54
- #[ wasm_bindgen]
54
+ #[ wasm_bindgen( getter_with_clone ) ]
55
55
pub struct MithrilClient {
56
56
client : Client ,
57
+
58
+ /// Unstable fonctions
59
+ pub unstable : MithrilUnstableClient ,
60
+ }
61
+
62
+ #[ wasm_bindgen]
63
+ #[ derive( Clone ) ]
64
+ pub struct MithrilUnstableClient {
65
+ client : Client ,
57
66
}
58
67
59
68
#[ wasm_bindgen]
@@ -67,7 +76,8 @@ impl MithrilClient {
67
76
. build ( )
68
77
. map_err ( |err| format ! ( "{err:?}" ) )
69
78
. unwrap ( ) ;
70
- MithrilClient { client }
79
+ let unstable = MithrilUnstableClient :: new ( client. clone ( ) ) ;
80
+ MithrilClient { client, unstable }
71
81
}
72
82
73
83
/// Call the client to get a snapshot from a digest
@@ -200,24 +210,58 @@ impl MithrilClient {
200
210
}
201
211
}
202
212
213
+ #[ wasm_bindgen]
214
+ impl MithrilUnstableClient {
215
+ /// Constructor for unstable wasm client
216
+ fn new ( inner_client : Client ) -> MithrilUnstableClient {
217
+ Self {
218
+ client : inner_client,
219
+ }
220
+ }
221
+
222
+ /// Call the client for the list of available Cardano transactions sets
223
+ #[ wasm_bindgen]
224
+ pub async fn list_cardano_transaction_sets ( & self ) -> WasmResult {
225
+ let result = self
226
+ . client
227
+ . cardano_transaction_proof ( )
228
+ . list ( )
229
+ . await
230
+ . map_err ( |err| format ! ( "{err:?}" ) ) ?;
231
+
232
+ Ok ( serde_wasm_bindgen:: to_value ( & result) ?)
233
+ }
234
+
235
+ /// Call the client to get a Cardano transactions set from a hash
236
+ #[ wasm_bindgen]
237
+ pub async fn get_cardano_transaction_set ( & self , hash : & str ) -> WasmResult {
238
+ let result = self
239
+ . client
240
+ . cardano_transaction_proof ( )
241
+ . get ( hash)
242
+ . await
243
+ . map_err ( |err| format ! ( "{err:?}" ) ) ?
244
+ . ok_or ( JsValue :: from_str ( & format ! (
245
+ "No cardano transactions commitment found for hash: '{hash}'"
246
+ ) ) ) ?;
247
+
248
+ Ok ( serde_wasm_bindgen:: to_value ( & result) ?)
249
+ }
250
+ }
251
+
203
252
#[ cfg( test) ]
204
253
mod tests {
205
254
use super :: * ;
255
+ use crate :: test_data;
206
256
use mithril_client:: {
207
- common:: ProtocolMessage , MithrilCertificateListItem , MithrilStakeDistribution ,
208
- MithrilStakeDistributionListItem , Snapshot , SnapshotListItem ,
257
+ common:: ProtocolMessage , CardanoTransactionCommitment , MithrilCertificateListItem ,
258
+ MithrilStakeDistribution , MithrilStakeDistributionListItem , Snapshot , SnapshotListItem ,
209
259
} ;
210
260
use wasm_bindgen_test:: * ;
211
261
212
262
const GENESIS_VERIFICATION_KEY : & str = "5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c3235322c3138302c37322c3133342c3133372c3234372c3136312c36385d" ;
213
263
const FAKE_AGGREGATOR_IP : & str = "127.0.0.1" ;
214
264
const FAKE_AGGREGATOR_PORT : & str = "8000" ;
215
- const FAKE_AGGREGATOR_SNAPSHOT_DIGEST : & str =
216
- "000ee4c84c7b64a62dc30ec78a765a1f3bb81cd9dd4bd1eccf9f2da785e70877" ;
217
- const FAKE_AGGREGATOR_MSD_HASH : & str =
218
- "03ebb00e6626037f2e58eb7cc50d308fd57c253baa1fe2b04eb5945ced16b5bd" ;
219
- const FAKE_CERTIFICATE_HASH : & str =
220
- "05bf6740e781e649dd2fe7e3319818747d8038ca759c67711c90cf24cdade8a9" ;
221
265
222
266
fn get_mithril_client ( ) -> MithrilClient {
223
267
MithrilClient :: new (
@@ -240,19 +284,23 @@ mod tests {
240
284
serde_wasm_bindgen:: from_value :: < Vec < SnapshotListItem > > ( snapshots_list_js_value)
241
285
. expect ( "conversion should not fail" ) ;
242
286
243
- assert_eq ! ( snapshots_list. len( ) , 3 ) ;
287
+ assert_eq ! (
288
+ snapshots_list. len( ) ,
289
+ // Aggregator return up to 20 items for a list route
290
+ test_data:: snapshot_digests( ) . len( ) . min( 20 )
291
+ ) ;
244
292
}
245
293
246
294
#[ wasm_bindgen_test]
247
295
async fn get_snapshot_should_return_value_convertible_in_rust_type ( ) {
248
296
let snapshot_js_value = get_mithril_client ( )
249
- . get_snapshot ( FAKE_AGGREGATOR_SNAPSHOT_DIGEST )
297
+ . get_snapshot ( test_data :: snapshot_digests ( ) [ 0 ] )
250
298
. await
251
299
. expect ( "get_snapshot should not fail" ) ;
252
300
let snapshot = serde_wasm_bindgen:: from_value :: < Snapshot > ( snapshot_js_value)
253
301
. expect ( "conversion should not fail" ) ;
254
302
255
- assert_eq ! ( snapshot. digest, FAKE_AGGREGATOR_SNAPSHOT_DIGEST ) ;
303
+ assert_eq ! ( snapshot. digest, test_data :: snapshot_digests ( ) [ 0 ] ) ;
256
304
}
257
305
258
306
#[ wasm_bindgen_test]
@@ -274,19 +322,23 @@ mod tests {
274
322
)
275
323
. expect ( "conversion should not fail" ) ;
276
324
277
- assert_eq ! ( msd_list. len( ) , 3 ) ;
325
+ assert_eq ! (
326
+ msd_list. len( ) ,
327
+ // Aggregator return up to 20 items for a list route
328
+ test_data:: msd_hashes( ) . len( ) . min( 20 )
329
+ ) ;
278
330
}
279
331
280
332
#[ wasm_bindgen_test]
281
333
async fn get_mithril_stake_distribution_should_return_value_convertible_in_rust_type ( ) {
282
334
let msd_js_value = get_mithril_client ( )
283
- . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
335
+ . get_mithril_stake_distribution ( test_data :: msd_hashes ( ) [ 0 ] )
284
336
. await
285
337
. expect ( "get_mithril_stake_distribution should not fail" ) ;
286
338
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value)
287
339
. expect ( "conversion should not fail" ) ;
288
340
289
- assert_eq ! ( msd. hash, FAKE_AGGREGATOR_MSD_HASH ) ;
341
+ assert_eq ! ( msd. hash, test_data :: msd_hashes ( ) [ 0 ] ) ;
290
342
}
291
343
292
344
#[ wasm_bindgen_test]
@@ -308,20 +360,24 @@ mod tests {
308
360
)
309
361
. expect ( "conversion should not fail" ) ;
310
362
311
- assert_eq ! ( certificates_list. len( ) , 7 ) ;
363
+ assert_eq ! (
364
+ certificates_list. len( ) ,
365
+ // Aggregator return up to 20 items for a list route
366
+ test_data:: certificate_hashes( ) . len( ) . min( 20 )
367
+ ) ;
312
368
}
313
369
314
370
#[ wasm_bindgen_test]
315
371
async fn get_mithril_certificate_should_return_value_convertible_in_rust_type ( ) {
316
372
let certificate_js_value = get_mithril_client ( )
317
- . get_mithril_certificate ( FAKE_CERTIFICATE_HASH )
373
+ . get_mithril_certificate ( test_data :: certificate_hashes ( ) [ 0 ] )
318
374
. await
319
375
. expect ( "get_mithril_certificate should not fail" ) ;
320
376
let certificate =
321
377
serde_wasm_bindgen:: from_value :: < MithrilCertificate > ( certificate_js_value)
322
378
. expect ( "conversion should not fail" ) ;
323
379
324
- assert_eq ! ( certificate. hash, FAKE_CERTIFICATE_HASH ) ;
380
+ assert_eq ! ( certificate. hash, test_data :: certificate_hashes ( ) [ 0 ] ) ;
325
381
}
326
382
327
383
#[ wasm_bindgen_test]
@@ -337,7 +393,7 @@ mod tests {
337
393
) {
338
394
let client = get_mithril_client ( ) ;
339
395
let msd_js_value = client
340
- . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
396
+ . get_mithril_stake_distribution ( test_data :: msd_hashes ( ) [ 0 ] )
341
397
. await
342
398
. unwrap ( ) ;
343
399
@@ -353,7 +409,7 @@ mod tests {
353
409
async fn verify_certificate_chain_should_return_value_convertible_in_rust_type ( ) {
354
410
let client = get_mithril_client ( ) ;
355
411
let msd_js_value = client
356
- . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
412
+ . get_mithril_stake_distribution ( test_data :: msd_hashes ( ) [ 0 ] )
357
413
. await
358
414
. unwrap ( ) ;
359
415
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value) . unwrap ( ) ;
@@ -370,7 +426,7 @@ mod tests {
370
426
async fn verify_message_match_certificate_should_return_true ( ) {
371
427
let client = get_mithril_client ( ) ;
372
428
let msd_js_value = client
373
- . get_mithril_stake_distribution ( FAKE_AGGREGATOR_MSD_HASH )
429
+ . get_mithril_stake_distribution ( test_data :: msd_hashes ( ) [ 0 ] )
374
430
. await
375
431
. unwrap ( ) ;
376
432
let msd = serde_wasm_bindgen:: from_value :: < MithrilStakeDistribution > ( msd_js_value. clone ( ) )
@@ -389,4 +445,46 @@ mod tests {
389
445
. await
390
446
. expect ( "verify_message_match_certificate should not fail" ) ;
391
447
}
448
+
449
+ #[ wasm_bindgen_test]
450
+ async fn list_cardano_transaction_sets_should_return_value_convertible_in_rust_type ( ) {
451
+ let cardano_tx_sets_js_value = get_mithril_client ( )
452
+ . unstable
453
+ . list_cardano_transaction_sets ( )
454
+ . await
455
+ . expect ( "list_cardano_transaction_sets should not fail" ) ;
456
+ let cardano_tx_sets = serde_wasm_bindgen:: from_value :: < Vec < CardanoTransactionCommitment > > (
457
+ cardano_tx_sets_js_value,
458
+ )
459
+ . expect ( "conversion should not fail" ) ;
460
+
461
+ assert_eq ! (
462
+ cardano_tx_sets. len( ) ,
463
+ // Aggregator return up to 20 items for a list route
464
+ test_data:: ctx_commitment_hashes( ) . len( ) . min( 20 )
465
+ ) ;
466
+ }
467
+
468
+ #[ wasm_bindgen_test]
469
+ async fn get_cardano_transaction_set_should_return_value_convertible_in_rust_type ( ) {
470
+ let cardano_tx_set_js_value = get_mithril_client ( )
471
+ . unstable
472
+ . get_cardano_transaction_set ( test_data:: ctx_commitment_hashes ( ) [ 0 ] )
473
+ . await
474
+ . expect ( "get_cardano_transaction_set should not fail" ) ;
475
+ let cardano_tx_set =
476
+ serde_wasm_bindgen:: from_value :: < CardanoTransactionCommitment > ( cardano_tx_set_js_value)
477
+ . expect ( "conversion should not fail" ) ;
478
+
479
+ assert_eq ! ( cardano_tx_set. hash, test_data:: ctx_commitment_hashes( ) [ 0 ] ) ;
480
+ }
481
+
482
+ #[ wasm_bindgen_test]
483
+ async fn get_cardano_transaction_set_should_fail_with_unknown_digest ( ) {
484
+ get_mithril_client ( )
485
+ . unstable
486
+ . get_cardano_transaction_set ( "whatever" )
487
+ . await
488
+ . expect_err ( "get_cardano_transaction_set should fail" ) ;
489
+ }
392
490
}
0 commit comments