From b0edea6a98f1d40b39cfd9a9566e4b924782d900 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Wed, 24 May 2023 13:44:23 +0200 Subject: [PATCH] Tiny fixes (#28) --- carnot/test_beaconized_carnot.py | 11 +++++------ carnot/test_unhappy_path.py | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/carnot/test_beaconized_carnot.py b/carnot/test_beaconized_carnot.py index f5b57e5..968cb64 100644 --- a/carnot/test_beaconized_carnot.py +++ b/carnot/test_beaconized_carnot.py @@ -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()]) diff --git a/carnot/test_unhappy_path.py b/carnot/test_unhappy_path.py index 2012453..f2f37d7 100644 --- a/carnot/test_unhappy_path.py +++ b/carnot/test_unhappy_path.py @@ -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()])