Skip to content

Commit

Permalink
test: add WASM functions for CardanoStakeDistribution in www-test
Browse files Browse the repository at this point in the history
  • Loading branch information
dlachaume committed Aug 12, 2024
1 parent 83c9da3 commit c20ee4d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
6 changes: 6 additions & 0 deletions mithril-client-wasm/src/client_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ impl MithrilUnstableClient {
}
}

/// Create an Epoch
#[wasm_bindgen]
pub fn create_epoch(&self, epoch_value: u64) -> Epoch {
Epoch(epoch_value)
}

/// Call the client for the list of available Cardano transactions snapshots
#[wasm_bindgen]
pub async fn list_cardano_transactions_snapshots(&self) -> WasmResult {
Expand Down
64 changes: 64 additions & 0 deletions mithril-client-wasm/www-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,68 @@ if (aggregator_capabilities.includes("CardanoTransactions")) {
}
}

if (aggregator_capabilities.includes("CardanoStakeDistribution")) {
let cardano_stake_distributions;
test_number++;
await run_test("list_cardano_stake_distributions", test_number, async () => {
cardano_stake_distributions = await client.unstable.list_cardano_stake_distributions();
console.log("cardano_stake_distributions", cardano_stake_distributions);
});

let cardano_stake_distribution;
test_number++;
await run_test("get_cardano_stake_distribution", test_number, async () => {
cardano_stake_distribution = await client.unstable.get_cardano_stake_distribution(
cardano_stake_distributions[0].hash,
);
console.log("cardano_stake_distribution", cardano_stake_distribution);
});

test_number++;
await run_test("get_cardano_stake_distribution_by_epoch", test_number, async () => {
let epoch = client.unstable.create_epoch(BigInt(cardano_stake_distributions[0].epoch));

cardano_stake_distribution =
await client.unstable.get_cardano_stake_distribution_by_epoch(epoch);
console.log("cardano_stake_distribution by epoch", cardano_stake_distribution);
});

let certificate;
test_number++;
await run_test("get_mithril_certificate", test_number, async () => {
certificate = await client.get_mithril_certificate(cardano_stake_distribution.certificate_hash);
console.log("certificate", certificate);
});

let last_certificate_from_chain;
test_number++;
await run_test("verify_certificate_chain", test_number, async () => {
last_certificate_from_chain = await client.verify_certificate_chain(certificate.hash);
console.log("last_certificate_from_chain", last_certificate_from_chain);
});

let cardano_stake_distribution_message;
test_number++;
await run_test("compute_cardano_stake_distribution_message", test_number, async () => {
cardano_stake_distribution_message =
await client.unstable.compute_cardano_stake_distribution_message(
certificate,
cardano_stake_distribution,
);
console.log("cardano_stake_distribution_message", cardano_stake_distribution_message);
});

test_number++;
await run_test("verify_message_match_certificate", test_number, async () => {
const valid_cardano_stake_distribution_message = await client.verify_message_match_certificate(
cardano_stake_distribution_message,
last_certificate_from_chain,
);
console.log(
"valid_cardano_stake_distribution_message",
valid_cardano_stake_distribution_message,
);
});
}

add_finished_div();
6 changes: 3 additions & 3 deletions mithril-client-wasm/www-test/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c20ee4d

Please sign in to comment.