Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danielSanchezQ authored and bacv committed Mar 22, 2024
1 parent cfe46ba commit c3027e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
10 changes: 7 additions & 3 deletions da/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions da/api/test_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]


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

0 comments on commit c3027e8

Please sign in to comment.