mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-26 00:43:11 +00:00
test_concatenate_standard_qcs
This commit is contained in:
parent
962be7c094
commit
8cc47c1efe
@ -245,29 +245,32 @@ class Carnot2(Carnot):
|
||||
|
||||
# A node may receive QCs from child committee members. It may also build it's own QC.
|
||||
# These QCs are then concatenated into one before sending to the parent committee.
|
||||
|
||||
|
||||
def concatenate_standard_qcs(qc_set: Set[StandardQc]) -> StandardQc:
|
||||
# Convert the set of StandardQc objects into a list
|
||||
qc_list = list(qc_set)
|
||||
|
||||
# Initialize the attributes for the concatenated StandardQc
|
||||
concatenated_block = None
|
||||
concatenated_view = None
|
||||
concatenated_voters = set()
|
||||
|
||||
# Iterate through the input set of StandardQc objects
|
||||
for qc in qc_set:
|
||||
# Iterate through the input list of StandardQc objects
|
||||
for qc in qc_list:
|
||||
concatenated_voters.update(qc.voters)
|
||||
|
||||
# Choose the block and view values from the first StandardQc in the set
|
||||
if qc_set:
|
||||
concatenated_block = qc_set[0].block
|
||||
concatenated_view = qc_set[0].view
|
||||
# Choose the block and view values from the first StandardQc in the list
|
||||
if qc_list:
|
||||
concatenated_block = qc_list[0].block
|
||||
concatenated_view = qc_list[0].view
|
||||
|
||||
# Create the concatenated StandardQc object
|
||||
concatenated_qc = StandardQc(concatenated_block, concatenated_view, concatenated_voters)
|
||||
|
||||
return concatenated_qc
|
||||
|
||||
from carnot import AggregateQc, Qc, StandardQc
|
||||
|
||||
# Similarly aggregated qcs are concatenated after timeout t2:
|
||||
# Similarly aggregated qcs are concatenated after timeout t2:
|
||||
def concatenate_aggregate_qcs(qc_set: Set[AggregateQc]) -> AggregateQc:
|
||||
# Initialize the attributes for the concatenated AggregateQc
|
||||
concatenated_qcs = []
|
||||
|
||||
@ -48,13 +48,29 @@ def int_to_id(i: int) -> Id:
|
||||
return bytes(str(i), encoding="utf8")
|
||||
|
||||
|
||||
@dataclass(unsafe_hash=True)
|
||||
class StandardQc:
|
||||
block: Id
|
||||
view: View
|
||||
voters: Set[Id]
|
||||
def get_view(self) -> View:
|
||||
return self.get_view
|
||||
|
||||
def __init__(self, block: Id, view: View, voters: Set[Id]):
|
||||
self.block = block
|
||||
self.view = view
|
||||
self.voters = voters
|
||||
|
||||
def __hash__(self):
|
||||
# Customize the hash function based on your requirements
|
||||
return hash((self.block, self.view, frozenset(self.voters)))
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, StandardQc):
|
||||
return (
|
||||
self.block == other.block and
|
||||
self.view == other.view and
|
||||
self.voters == other.voters
|
||||
)
|
||||
return False
|
||||
|
||||
|
||||
@dataclass
|
||||
class AggregateQc:
|
||||
|
||||
@ -5,7 +5,7 @@ from carnot import merging_committees
|
||||
from carnot.merging_committees import merge_committees
|
||||
import itertools
|
||||
import unittest
|
||||
|
||||
from carnot.carnot_vote_aggregation import Carnot2,StandardQc
|
||||
class TestMergeCommittees(unittest.TestCase):
|
||||
|
||||
def assertMergedSetsEqual(self, merged, original):
|
||||
@ -30,5 +30,24 @@ class TestMergeCommittees(unittest.TestCase):
|
||||
merged = merge_committees(original_sets)
|
||||
self.assertMergedSetsEqual(merged, set.union(*original_sets))
|
||||
|
||||
|
||||
|
||||
class TestConcatenateStandardQcs(unittest.TestCase):
|
||||
def test_concatenate_standard_qcs(self):
|
||||
# Create some StandardQc objects
|
||||
qc1 = StandardQc(block=1, view=1, voters={1, 2, 3})
|
||||
qc2 = StandardQc(block=1, view=1, voters={4, 5, 6})
|
||||
qc3 = StandardQc(block=1, view=1, voters={7, 8, 6})
|
||||
|
||||
# Concatenate the StandardQc objects
|
||||
concatenated_qc = carnot.carnot_vote_aggregation.Carnot2.concatenate_standard_qcs({qc1, qc2, qc3})
|
||||
|
||||
# Define the expected concatenated StandardQc
|
||||
expected_qc = StandardQc(block=1, view=1, voters={1, 2, 3, 4, 5, 6, 7, 8})
|
||||
|
||||
# Assert that the concatenated StandardQc matches the expected one
|
||||
self.assertEqual(concatenated_qc, expected_qc)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user