From f5f22a8c3d51b83f9eef040bb5bf695203814f01 Mon Sep 17 00:00:00 2001 From: danielSanchezQ <3danimanimal@gmail.com> Date: Fri, 24 Jan 2025 17:08:14 +0000 Subject: [PATCH] Fix tests --- da/dispersal.py | 4 +--- da/test_dispersal.py | 12 ++++++++---- da/test_full_flow.py | 14 +++++++------- da/test_verifier.py | 3 +++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/da/dispersal.py b/da/dispersal.py index a7a6039..19fc1ba 100644 --- a/da/dispersal.py +++ b/da/dispersal.py @@ -44,12 +44,10 @@ def _send_and_await_response(self, node: NodeId, blob: DABlob) -> bool: pass def disperse(self, encoded_data: EncodedData): - attestations = [] blob_data = zip( - range(len(self.settings.nodes_ids)), self.settings.nodes_ids, self._prepare_data(encoded_data) ) - for i, node, blob in blob_data: + for node, blob in blob_data: self._send_and_await_response(node, blob) diff --git a/da/test_dispersal.py b/da/test_dispersal.py index e8d1ec6..a90e14b 100644 --- a/da/test_dispersal.py +++ b/da/test_dispersal.py @@ -26,11 +26,15 @@ def test_disperse(self): encoded_data = DAEncoder(encoding_params).encode(data) # mock send and await method with local verifiers - def __send_and_await_response(blob: DABlob): + verifiers_res = [] + def __send_and_await_response(_, blob: DABlob): verifier = DAVerifier() - return verifier.verify(blob) + res = verifier.verify(blob) + verifiers_res.append(res) + return res # inject mock send and await method self.dispersal._send_and_await_response = __send_and_await_response - - self.assertTrue(self.dispersal.disperse(encoded_data)) + self.dispersal.disperse(encoded_data) + for res in verifiers_res: + self.assertTrue(res) diff --git a/da/test_full_flow.py b/da/test_full_flow.py index 215dd15..32d4827 100644 --- a/da/test_full_flow.py +++ b/da/test_full_flow.py @@ -29,7 +29,7 @@ def receive_metadata(self, vid: BlobMetadata): # Usually the certificate would be verifier here, # but we are assuming that this it is already coming from the verified block, # in which case all certificates had been already verified by the DA Node. - self.api.write(vid.cert_id, vid.metadata) + self.api.write(vid.blob_id, vid.metadata) def read(self, app_id, indexes) -> List[Optional[DABlob]]: return self.api.read(app_id, indexes) @@ -66,10 +66,9 @@ def __send_and_await_response(node: int, blob: DABlob): # inject mock send and await method self.dispersal._send_and_await_response = __send_and_await_response - certificate = self.dispersal.disperse(encoded_data) - + blob_id = build_blob_id(encoded_data.aggregated_column_commitment, encoded_data.row_commitments) vid = BlobMetadata( - certificate.id(), + blob_id, Metadata(app_id, index) ) @@ -103,12 +102,13 @@ def __send_and_await_response(node: int, blob: DABlob): # inject mock send and await method self.dispersal._send_and_await_response = __send_and_await_response - certificate = self.dispersal.disperse(encoded_data) + self.dispersal.disperse(encoded_data) + blob_id = build_blob_id(encoded_data.aggregated_column_commitment, encoded_data.row_commitments) # Loop through each index and simulate dispersal with the same cert_id but different metadata for index in indexes: metadata = BlobMetadata( - certificate.id(), + blob_id, Metadata(app_id, index) ) @@ -122,7 +122,7 @@ def __send_and_await_response(node: int, blob: DABlob): # as we do actually do dispersal. blobs = list(chain.from_iterable( node.read(app_id, [index]) - for node in sorted(self.api_nodes, key=lambda n: bls_pop.SkToPk(n.verifier.sk)) + for node in self.api_nodes )) original_blobs = list(self.dispersal._prepare_data(encoded_data)) self.assertEqual(blobs, original_blobs, f"Failed at index {index}") diff --git a/da/test_verifier.py b/da/test_verifier.py index 4fcd03d..8a65d51 100644 --- a/da/test_verifier.py +++ b/da/test_verifier.py @@ -34,6 +34,7 @@ def test_verify(self): verifier = DAVerifier() da_blob = DABlob( Column(column), + i, encoded_data.column_commitments[i], encoded_data.aggregated_column_commitment, encoded_data.aggregated_column_proofs[i], @@ -50,6 +51,7 @@ def test_verify_duplicated_blob(self): i, column = next(columns) da_blob = DABlob( Column(column), + i, encoded_data.column_commitments[i], encoded_data.aggregated_column_commitment, encoded_data.aggregated_column_proofs[i], @@ -60,6 +62,7 @@ def test_verify_duplicated_blob(self): for i, column in columns: da_blob = DABlob( Column(column), + i, encoded_data.column_commitments[i], encoded_data.aggregated_column_commitment, encoded_data.aggregated_column_proofs[i],