From 26155149096c90ad84eef13211b072c0633aacc4 Mon Sep 17 00:00:00 2001 From: Agnish Ghosh Date: Thu, 13 Jun 2024 16:19:15 +0530 Subject: [PATCH] add: testing init for peerdas eip --- beacon_chain/spec/datatypes/eip7594.nim | 2 +- beacon_chain/spec/eip7594_helpers.nim | 24 ++++------ tests/all_tests.nim | 1 + tests/test_eip7594_helpers.nim | 59 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 tests/test_eip7594_helpers.nim diff --git a/beacon_chain/spec/datatypes/eip7594.nim b/beacon_chain/spec/datatypes/eip7594.nim index cfdafefd7..b39a5190c 100644 --- a/beacon_chain/spec/datatypes/eip7594.nim +++ b/beacon_chain/spec/datatypes/eip7594.nim @@ -9,7 +9,7 @@ import "."/[base, deneb], kzg4844 -export base, kzg4844 +export base const FIELD_ELEMENTS_PER_EXT_BLOB* = 2 * kzg_abi.FIELD_ELEMENTS_PER_BLOB diff --git a/beacon_chain/spec/eip7594_helpers.nim b/beacon_chain/spec/eip7594_helpers.nim index bc09fdebf..524ea6d3c 100644 --- a/beacon_chain/spec/eip7594_helpers.nim +++ b/beacon_chain/spec/eip7594_helpers.nim @@ -14,6 +14,7 @@ import ssz_serialization/proofs, chronicles, ./[beacon_time, crypto], + kzg4844/kzg_ex, eth/p2p/discoveryv5/[node], ./helpers, ./datatypes/[eip7594, deneb] @@ -67,14 +68,15 @@ proc get_custody_columns*(node_id: NodeId, custody_subnet_count: uint64): Result proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[ExtendedMatrix, cstring] = # This helper demonstrates the relationship between blobs and `ExtendedMatrix` var extended_matrix: ExtendedMatrix - for blob in blobs: - let res = computeCells(blob) - + for i in 0.. MAX_TOP_BYTE and i %% kzg_abi.BYTES_PER_FIELD_ELEMENT == 0: + blob[i] = MAX_TOP_BYTE + blobs.add(blob) + + ok(blobs) + +suite "EIP-7594 Unit Tests": + test "EIP-7594: Compute Extended Matrix": + proc testComputeExtendedMatrix() = + let blob_count = 2 + let input_blobs = createSampleKzgBlobs(blob_count) + let extended_matrix = compute_extended_matrix(input_blobs.get) + + doAssert extended_matrix.get.len == kzg_abi.CELLS_PER_EXT_BLOB * blob_count + + testComputeExtendedMatrix() \ No newline at end of file