Skip to content

Commit

Permalink
better tests, et al
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek committed Dec 2, 2024
1 parent 4d2494c commit 93514f2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
40 changes: 22 additions & 18 deletions node-wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>) -> NodeClient {
Expand Down
7 changes: 2 additions & 5 deletions rpc/tests/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down Expand Up @@ -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 { hash: random_bytes_array() };

let submitted_height = blob_submit(&client, &[blob.clone()]).await.unwrap();

Expand Down
10 changes: 9 additions & 1 deletion types/src/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<u8> {
todo!()
}
}

impl From<Blob> for RawBlob {
fn from(value: Blob) -> RawBlob {
RawBlob {
Expand Down

0 comments on commit 93514f2

Please sign in to comment.