diff --git a/da/api/common.py b/da/api/common.py index 44259f40..6a17ff75 100644 --- a/da/api/common.py +++ b/da/api/common.py @@ -8,16 +8,20 @@ @dataclass class Metadata: - # index of VID certificate blob - index: int # app identifier app_id: bytes + # index of VID certificate blob + index: int + @dataclass -class VID(): +class VID: + # da certificate id cert_id: bytes + # application + index information metadata: Metadata + class BlobStore(ABC): @abstractmethod def add(self, certificate: Certificate, metadata: Metadata): diff --git a/da/api/test_flow.py b/da/api/test_flow.py index bf88fc17..fc051da3 100644 --- a/da/api/test_flow.py +++ b/da/api/test_flow.py @@ -23,12 +23,12 @@ def add(self, cert_id: bytes, metadata: Metadata): raise ValueError("index already written") blob = self.blob_store.pop(cert_id) - self.app_id_store[metadata.app_id][metadata.index] = blob + self.app_id_store[metadata.app_id][metadata.index] = blob # Implements `get_multiple` method from BlobStore abstract class. def get_multiple(self, app_id, indexes) -> List[Optional[DABlob]]: return [ - self.app_id_store[app_id].get(i) for i in indexes + self.app_id_store[app_id].get(i) for i in indexes ] diff --git a/da/test_full_flow.py b/da/test_full_flow.py index 59e33fec..85037284 100644 --- a/da/test_full_flow.py +++ b/da/test_full_flow.py @@ -1,16 +1,19 @@ +from itertools import chain from unittest import TestCase from typing import List, Optional + from py_ecc.bls import G2ProofOfPossession as bls_pop -from da.common import Certificate, NodeId, build_attestation_message +from da.common import NodeId, build_attestation_message from da.api.common import DAApi, VID, Metadata from da.verifier import DAVerifier, DABlob from da.api.test_flow import MockStore -from da.dispersal import Dispersal, EncodedData, DispersalSettings +from da.dispersal import Dispersal, DispersalSettings from da.test_encoder import TestEncoder from da.encoder import DAEncoderParams, DAEncoder -class DAVerifierWApi(): + +class DAVerifierWApi: def __init__(self, sk: int): self.store = MockStore() self.api = DAApi(self.store) @@ -25,11 +28,14 @@ def receive_blob(self, blob: DABlob): return attestation def receive_cert(self, vid: VID): - # Usually the certificate would be verifier here, but we are assuming that this it is already comming from the verified block, in which case all certificates had been already verified by the DA Node. + # 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) def read(self, app_id, indexes) -> List[Optional[DABlob]]: - self.api.read(app_id, indexes) + return self.api.read(app_id, indexes) + class TestFullFlow(TestCase): def setUp(self): @@ -40,14 +46,13 @@ def setUp(self): dispersal_settings = DispersalSettings( self.nodes_ids, self.public_keys, - self.n_nodes // 2 + 1 + self.n_nodes ) self.dispersal = Dispersal(dispersal_settings) self.encoder_test = TestEncoder() self.encoder_test.setUp() - self.api_nodes = [ DAVerifierWApi(k) for k in self.secret_keys ] - + self.api_nodes = [DAVerifierWApi(k) for k in self.secret_keys] def test_full_flow(self): app_id = int.to_bytes(1) @@ -67,17 +72,21 @@ def __send_and_await_response(node: int, blob: DABlob): self.dispersal._send_and_await_response = __send_and_await_response certificate = self.dispersal.disperse(encoded_data) - print(">>>>", self.api_nodes[0].store.blob_store) - vid = VID( - certificate.id(), - Metadata(app_id, index) - ) + certificate.id(), + Metadata(app_id, index) + ) # verifier for node in self.api_nodes: node.receive_cert(vid) # read from api and confirm its working - blobs = [node.read(app_id, index) for node in self.api_nodes] - blobs.sort(key = lambda x: x.index) + # notice that we need to sort the api_nodes by their public key to have the blobs sorted in the same fashion + # 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)) + )) + original_blobs = list(self.dispersal._prepare_data(encoded_data)) + self.assertEqual(blobs, original_blobs) \ No newline at end of file