From f3e5b983366f0979a87166998b6aa9c6142872e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Mon, 2 Dec 2024 09:33:08 +0100 Subject: [PATCH] better tests, et al --- node-wasm/src/client.rs | 40 ++++++++++++++++++++++------------------ rpc/tests/blob.rs | 7 ++----- types/src/blob.rs | 10 +++++++++- 3 files changed, 33 insertions(+), 24 deletions(-) diff --git a/node-wasm/src/client.rs b/node-wasm/src/client.rs index 10f81f53b..81d4a20e4 100644 --- a/node-wasm/src/client.rs +++ b/node-wasm/src/client.rs @@ -451,7 +451,7 @@ mod tests { use celestia_rpc::{prelude::*, Client}; use celestia_types::p2p::PeerId; - use celestia_types::ExtendedHeader; + use celestia_types::{AppVersion, ExtendedHeader, TxConfig}; use gloo_timers::future::sleep; use libp2p::{multiaddr::Protocol, Multiaddr}; use rexie::Rexie; @@ -519,29 +519,33 @@ mod tests { crate::utils::setup_logging(); remove_database().await.expect("failed to clear db"); let rpc_client = Client::new(WS_URL).await.unwrap(); + let namespace = Namespace::new_v0(&[0xCD, 0xDC, 0xCD, 0xDC, 0xCD, 0xDC]).unwrap(); + let data = b"Hello, World"; + let blobs = vec![Blob::new(namespace, data.to_vec(), AppVersion::V3).unwrap()]; + info!("presubmit"); + let submitted_height = rpc_client + .blob_submit(&blobs, TxConfig::default()) + .await + .expect("successful submission"); + info!("preheader"); + let header = rpc_client + .header_get_by_height(submitted_height) + .await + .expect("header for blob"); + let bridge_ma = fetch_bridge_webtransport_multiaddr(&rpc_client).await; let client = spawn_connected_node(vec![bridge_ma.to_string()]).await; - let namespace = Namespace::new_v0(&[0xAF, 0xAF, 0xAF, 0xAF, 0xAF, 0xAF]).unwrap(); - let mut found = None; - // TODO: once gRPC blob submission works from browser, submit blob and get its height that - // way. Otherwise, this looks for a blob submitted from the RPC tests `rpc/tests/blob.rs` - 'find_header: for h in 1..=500 { - info!("HH: {h}"); - let header = rpc_client.header_get_by_height(h).await.unwrap(); - for row in header.dah.row_roots() { - if row.min_namespace() < *namespace && *namespace < row.max_namespace() { - found = Some(header.clone()); - break 'find_header; - } - } - } - let header = found.expect("blob to exists"); + info!("pregetblobs"); - let _blob = client + let mut blobs = client .request_all_blobs(to_value(&header).unwrap(), namespace, None) .await - .unwrap(); + .expect("to fetch blob"); + assert_eq!(blobs.len(), 1); + let blob = blobs.pop().unwrap(); + assert_eq!(blob.data, data); + assert_eq!(blob.namespace, namespace); } async fn spawn_connected_node(bootnodes: Vec) -> NodeClient { diff --git a/rpc/tests/blob.rs b/rpc/tests/blob.rs index 89abf0d72..575772700 100644 --- a/rpc/tests/blob.rs +++ b/rpc/tests/blob.rs @@ -6,7 +6,6 @@ use std::time::Duration; use celestia_rpc::blob::BlobsAtHeight; use celestia_rpc::prelude::*; use celestia_types::consts::appconsts::AppVersion; -use celestia_types::nmt::Namespace; use celestia_types::{Blob, Commitment}; use jsonrpsee::core::client::Subscription; @@ -18,7 +17,7 @@ use crate::utils::{random_bytes, random_bytes_array, random_ns}; #[tokio::test] async fn blob_submit_and_get() { let client = new_test_client(AuthLevel::Write).await.unwrap(); - let namespace = Namespace::new_v0(&[0xAF, 0xAF, 0xAF, 0xAF, 0xAF, 0xAF]).unwrap(); + let namespace = random_ns(); let data = random_bytes(5); let blob = Blob::new(namespace, data, AppVersion::V2).unwrap(); @@ -195,9 +194,7 @@ async fn blob_get_get_proof_wrong_commitment() { let namespace = random_ns(); let data = random_bytes(5); let blob = Blob::new(namespace, data, AppVersion::V2).unwrap(); - let commitment = Commitment { - hash: random_bytes_array(), - }; + let commitment = Commitment(random_bytes_array()); let submitted_height = blob_submit(&client, &[blob.clone()]).await.unwrap(); diff --git a/types/src/blob.rs b/types/src/blob.rs index 184fcd2ec..566d972c6 100644 --- a/types/src/blob.rs +++ b/types/src/blob.rs @@ -41,7 +41,6 @@ pub struct Blob { pub share_version: u8, /// A [`Commitment`] computed from the [`Blob`]s data. pub commitment: Commitment, - /// Index of the blob's first share in the EDS. Only set for blobs retrieved from chain. // note: celestia supports deserializing blobs without index, so we should too #[serde(default, with = "index_serde")] @@ -316,6 +315,15 @@ impl Blob { } } +#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))] +#[wasm_bindgen] +impl Blob { + #[wasm_bindgen(getter)] + pub fn commitment() -> Vec { + todo!() + } +} + impl From for RawBlob { fn from(value: Blob) -> RawBlob { RawBlob {