Tiny fixes (#28)

This commit is contained in:
Daniel Sanchez 2023-05-24 13:44:23 +02:00 committed by GitHub
parent 5a169039b5
commit b0edea6a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 10 deletions

View File

@ -35,9 +35,8 @@ def succeed(nodes: Dict[Id, BeaconizedCarnot], proposed_block: BeaconizedBlock)
for node_id in parents:
node = nodes[node_id]
child_votes = [votes[_id] for _id in votes.keys() if overlay.is_member_of_child_committee(node_id, _id)]
if len(child_votes) == overlay.super_majority_threshold(node_id) and node_id not in votes:
vote = node.approve_block(proposed_block, child_votes).payload
votes[node_id] = vote
vote = node.approve_block(proposed_block, child_votes).payload
votes[node_id] = vote
childs_ids = list(set(parents))
root_votes = [
@ -115,7 +114,7 @@ def add_genesis_block(carnot: BeaconizedCarnot, sk: PrivateKey) -> Block:
return genesis_block
def setup_initial_setup(test_case: TestCase, size: int) -> (Dict[Id, Carnot], Carnot, Block, EntropyOverlay):
def initial_setup(test_case: TestCase, size: int) -> (Dict[Id, Carnot], Carnot, Block, EntropyOverlay):
keys = [generate_random_sk() for _ in range(size)]
nodes_ids = [bytes(key.get_g1()) for key in keys]
genesis_sk = generate_random_sk()
@ -153,7 +152,7 @@ class TestBeaconizedCarnot(TestCase):
Majority means more than two thirds of total number of nodes, randomly assigned to committees.
"""
leader: BeaconizedCarnot
nodes, leader, proposed_block, overlay = setup_initial_setup(self, 5)
nodes, leader, proposed_block, overlay = initial_setup(self, 5)
for view in range(2, 5):
root_votes, overlay = succeed(nodes, proposed_block)
@ -178,7 +177,7 @@ class TestBeaconizedCarnot(TestCase):
leader = nodes[overlay.leader()]
proposed_block = leader.propose_block(view, root_votes).payload
committed_blocks = [view for view in range(1, 11) if view not in (4, 5, 7, 8)]
committed_blocks = [view for view in range(1, 11) if view not in (4, 5, 7, 8, 9, 10, 11, 12, 13)]
for node in nodes.values():
for view in committed_blocks:
self.assertIn(view, [block.view for block in node.committed_blocks().values()])

View File

@ -90,7 +90,7 @@ def add_genesis_block(carnot: Carnot) -> Block:
return genesis_block
def setup_initial_setup(test_case: TestCase, overlay: MockOverlay, size: int) -> (Dict[Id, Carnot], MockCarnot, Block):
def initial_setup(test_case: TestCase, overlay: MockOverlay, size: int) -> (Dict[Id, Carnot], MockCarnot, Block):
nodes = {int_to_id(i): MockCarnot(int_to_id(i)) for i in range(size)}
# add overlay
for node in nodes.values():
@ -207,7 +207,7 @@ class TestCarnotUnhappyPath(TestCase):
overlay = MockOverlay()
nodes, leader, proposed_block = setup_initial_setup(self, overlay, 5)
nodes, leader, proposed_block = initial_setup(self, overlay, 5)
# In this loop 'view' is the view that fails
for view in range(1, 4, 2):
@ -239,7 +239,7 @@ class TestCarnotUnhappyPath(TestCase):
"""
overlay = MockOverlay()
leader: MockCarnot
nodes, leader, proposed_block = setup_initial_setup(self, overlay, 5)
nodes, leader, proposed_block = initial_setup(self, overlay, 5)
for view in range(2, 5):
root_votes = succeed(self, overlay, nodes, proposed_block)
@ -259,7 +259,7 @@ class TestCarnotUnhappyPath(TestCase):
root_votes = succeed(self, overlay, nodes, proposed_block)
proposed_block = leader.propose_block(view, root_votes).payload
committed_blocks = [view for view in range(1, 11) if view not in (4, 5, 7, 8)]
committed_blocks = [view for view in range(1, 11) if view not in (4, 5, 7, 8, 9, 10, 11, 12, 13)]
for node in nodes.values():
for view in committed_blocks:
self.assertIn(view, [block.view for block in node.committed_blocks().values()])