Skip to content

Commit 2dc358e

Browse files
committed
feat(client-wasm): expose fetch_current_mithril_era to retrieve the current Mithril era
1 parent 26935c3 commit 2dc358e

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

mithril-client-wasm/src/client_wasm.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,19 @@ impl MithrilClient {
424424

425425
Ok(serde_wasm_bindgen::to_value(&result)?)
426426
}
427+
428+
/// Call the client to fetch the current Mithril era
429+
#[wasm_bindgen]
430+
pub async fn fetch_current_mithril_era(&self) -> WasmResult {
431+
let result = self
432+
.client
433+
.mithril_era_client()
434+
.fetch_current()
435+
.await
436+
.map_err(|err| format!("{err:?}"))?;
437+
438+
Ok(serde_wasm_bindgen::to_value(&result)?)
439+
}
427440
}
428441

429442
// Unstable functions are only available when the unstable flag is set
@@ -506,7 +519,7 @@ mod tests {
506519
CardanoDatabaseSnapshot, CardanoDatabaseSnapshotListItem, CardanoStakeDistribution,
507520
CardanoStakeDistributionListItem, CardanoTransactionSnapshot, MithrilCertificateListItem,
508521
MithrilStakeDistribution, MithrilStakeDistributionListItem, Snapshot, SnapshotListItem,
509-
common::ProtocolMessage,
522+
common::ProtocolMessage, common::SupportedEra, era::FetchedEra,
510523
};
511524

512525
use crate::test_data;
@@ -960,4 +973,18 @@ mod tests {
960973
.await
961974
.expect_err("get_cardano_database_v2 should fail");
962975
}
976+
977+
#[wasm_bindgen_test]
978+
async fn fetch_current_mithril_era_should_return_value_convertible_to_supported_era() {
979+
let fetched_era_js_value = get_mithril_client_stable()
980+
.fetch_current_mithril_era()
981+
.await
982+
.expect("fetch_current_mithril_era should not fail");
983+
let fetched_era = serde_wasm_bindgen::from_value::<FetchedEra>(fetched_era_js_value)
984+
.expect("conversion should not fail");
985+
986+
let era = fetched_era.to_supported_era().expect("conversion should not fail");
987+
988+
assert_eq!(era, SupportedEra::Pythagoras);
989+
}
963990
}

0 commit comments

Comments
 (0)