Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielSanchezQ committed Jan 24, 2025
1 parent 787062e commit f5f22a8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 1 addition & 3 deletions da/dispersal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

12 changes: 8 additions & 4 deletions da/test_dispersal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

14 changes: 7 additions & 7 deletions da/test_full_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
)

Expand Down Expand Up @@ -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)
)

Expand All @@ -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}")
3 changes: 3 additions & 0 deletions da/test_verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down

0 comments on commit f5f22a8

Please sign in to comment.