From e8e8c730438d17e11572ba74e201f52a312fb220 Mon Sep 17 00:00:00 2001 From: mjalalzai <33738574+MForensic@users.noreply.github.com> Date: Mon, 10 Apr 2023 23:53:10 -0700 Subject: [PATCH] Unhappy path tests assertions. --- carnot/__init__.py | 0 carnot/carnot.py | 12 ++++++++---- carnot/test_happy_path.py | 2 +- carnot/test_unhappy_path.py | 18 ++++++++++++------ 4 files changed, 21 insertions(+), 11 deletions(-) delete mode 100644 carnot/__init__.py diff --git a/carnot/__init__.py b/carnot/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/carnot/carnot.py b/carnot/carnot.py index bddad3c..12c9503 100644 --- a/carnot/carnot.py +++ b/carnot/carnot.py @@ -468,9 +468,13 @@ class Carnot: def approve_new_view(self, NewViews: Set[NewView]): assert not self.overlay.is_member_of_leaf_committee(self.id) + # print(f"NewViews: {NewViews}") + # print(f"Views: {[newView.view for newView in NewViews]}") assert len(set(newView.view for newView in NewViews)) == 1 - # This check is done in self.is_safe_to_timeout() - # assert all(timeout.view >= self.current_view for timeout in timeouts) + # newView.view == self.last_timeout_view_qc.view for member of root committee and its children because + # they have already created the timeout_qc. For other nodes newView.view > self.last_timeout_view_qc.view. + if not self.last_timeout_view_qc is None: + assert all(newView.view >= self.last_timeout_view_qc.view for newView in NewViews) assert all(newView.view == newView.timeout_qc.view for newView in NewViews) assert len(NewViews) == self.overlay.super_majority_threshold(self.id) assert all(self.overlay.is_member_of_child_committee(self.id, newView.sender) for newView in NewViews) @@ -515,11 +519,11 @@ class Carnot: if self.highest_voted_view < self.current_view: self.increment_voted_view(timeout_qc.view) -# Just a suggestion that received_timeout_qc can be reused by each node when the process timeout_qc of the NewView msg. + # Just a suggestion that received_timeout_qc can be reused by each node when the process timeout_qc of the NewView msg. def received_timeout_qc(self, timeout_qc: TimeoutQc): # assert timeout_qc.view >= self.current_view new_high_qc = timeout_qc.high_qc - if new_high_qc.view >= self.local_high_qc.view: + if new_high_qc.view > self.local_high_qc.view: self.update_high_qc(new_high_qc) self.update_timeout_qc(timeout_qc) if not self.is_safe_to_timeout(): diff --git a/carnot/test_happy_path.py b/carnot/test_happy_path.py index e574507..c0d3d26 100644 --- a/carnot/test_happy_path.py +++ b/carnot/test_happy_path.py @@ -1,4 +1,4 @@ -from .carnot import * +from carnot import * from unittest import TestCase diff --git a/carnot/test_unhappy_path.py b/carnot/test_unhappy_path.py index d4b3127..f58347b 100644 --- a/carnot/test_unhappy_path.py +++ b/carnot/test_unhappy_path.py @@ -1,5 +1,6 @@ -from unittest import TestCase from .carnot import * +from unittest import TestCase + # Unhappy path tests @@ -67,6 +68,7 @@ class TestCarnotHappyPath(TestCase): │ 3◄─┴─►4 """ + def __init__(self): self.parents = { int_to_id(1): int_to_id(0), @@ -126,7 +128,6 @@ class TestCarnotHappyPath(TestCase): } return thresholds.get(_id, 0) - nodes = {int_to_id(i): MockCarnot(int_to_id(i)) for i in range(5)} overlay = MockOverlay() # add overlay @@ -184,8 +185,13 @@ class TestCarnotHappyPath(TestCase): # Add final assertions on nodes + new_block_1 = node_1.latest_event + # Gives an error that AttributeError: 'NewView' object has no attribute 'qc' somehow it returns newView + # instead of a block + self.assertEqual(new_block_1.qc.view, 0) - - - - +# Assertion should be: +# last_timeout_view_qc.view should be 1 +# high_qc.view should be 0 +# current_view should be 2 (after voting for block) +# last_voted_view should be 1 before voting and 2 after voting for the block \ No newline at end of file