Skip to content

Commit

Permalink
test: add validation of EDS in tests (#165)
Browse files Browse the repository at this point in the history
* fix: handling of the namespaces in v255

* use split_last instead of crazy indexing

* test: add validation of EDS in tests

---------

Co-authored-by: Mikołaj Florkiewicz <[email protected]>
  • Loading branch information
zvolin and fl0rek authored Dec 14, 2023
1 parent 8e9be75 commit e238a66
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ libp2p = { workspace = true, features = [
anyhow = "1.0.71"
dotenvy = "0.15.7"
futures = "0.3.28"
nmt-rs = "0.1.0"
rand = "0.8.5"
tokio = { version = "1.32.0", features = ["rt", "macros"] }
tracing = "0.1.37"
Expand Down
28 changes: 24 additions & 4 deletions rpc/tests/share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use celestia_types::consts::appconsts::{
CONTINUATION_SPARSE_SHARE_CONTENT_SIZE, FIRST_SPARSE_SHARE_CONTENT_SIZE, SEQUENCE_LEN_BYTES,
SHARE_INFO_BYTES,
};
use celestia_types::nmt::{Namespace, NamespacedSha2Hasher};
use celestia_types::Blob;
use celestia_types::nmt::{Namespace, NamespacedSha2Hasher, Nmt};
use celestia_types::{Blob, Share};
use nmt_rs::NamespaceMerkleHasher;

pub mod utils;

Expand Down Expand Up @@ -148,7 +149,26 @@ async fn get_eds() {

let header = client.header_get_by_height(submitted_height).await.unwrap();

let _eds = client.share_get_eds(&header).await.unwrap();
let eds = client.share_get_eds(&header).await.unwrap();
let width = header.dah.square_len();

// TODO: validate
for (y, chunk) in eds.data_square.chunks(width).enumerate() {
let mut nmt = Nmt::with_hasher(NamespacedSha2Hasher::with_ignore_max_ns(true));

for (x, leaf) in chunk.iter().enumerate() {
if x < width / 2 && y < width / 2 {
// the `OriginalDataSquare` part of the `EDS`
let share = Share::from_raw(leaf).unwrap();
let ns = share.namespace();
nmt.push_leaf(share.as_ref(), *ns).unwrap();
} else {
// the parity data computed using `eds.codec`
nmt.push_leaf(leaf, *Namespace::PARITY_SHARE).unwrap();
}
}

// check if the root corresponds to the one from the dah
let root = nmt.root();
assert_eq!(root, header.dah.row_root(y).unwrap());
}
}

0 comments on commit e238a66

Please sign in to comment.