Extract MockCarnot in happy path tests

This commit is contained in:
danielsanchezq 2023-04-10 10:50:40 +02:00
parent d8d22e7219
commit 0922aec404
1 changed files with 14 additions and 22 deletions

View File

@ -1,6 +1,18 @@
from .carnot import * from .carnot import *
from unittest import TestCase, mock from unittest import TestCase
from unittest.mock import patch
class MockCarnot(Carnot):
def __init__(self, id):
super(MockCarnot, self).__init__(id)
self.proposed_block = None
self.latest_vote = None
def broadcast(self, block):
self.proposed_block = block
def send(self, vote: Vote | Timeout | TimeoutQc, *ids: Id):
self.latest_vote = vote
class TestCarnotHappyPath(TestCase): class TestCarnotHappyPath(TestCase):
@ -289,14 +301,6 @@ class TestCarnotHappyPath(TestCase):
def parent_committee(self, _id: Id) -> Optional[Committee]: def parent_committee(self, _id: Id) -> Optional[Committee]:
return set() return set()
class MockCarnot(Carnot):
def __init__(self, _id):
super(MockCarnot, self).__init__(_id)
self.proposed_block = None
def broadcast(self, block):
self.proposed_block = block
carnot = MockCarnot(int_to_id(0)) carnot = MockCarnot(int_to_id(0))
carnot.overlay = MockOverlay() carnot.overlay = MockOverlay()
genesis_block = self.add_genesis_block(carnot) genesis_block = self.add_genesis_block(carnot)
@ -380,18 +384,6 @@ class TestCarnotHappyPath(TestCase):
""" """
Test that having a single committee (both root and leaf) and a leader is able to advance Test that having a single committee (both root and leaf) and a leader is able to advance
""" """
class MockCarnot(Carnot):
def __init__(self, id):
super(MockCarnot, self).__init__(id)
self.proposed_block = None
self.latest_vote = None
def broadcast(self, block):
self.proposed_block = block
def send(self, vote: Vote | Timeout | TimeoutQc, *ids: Id):
self.latest_vote = vote
nodes = [MockCarnot(int_to_id(i)) for i in range(4)] nodes = [MockCarnot(int_to_id(i)) for i in range(4)]
leader = nodes[0] leader = nodes[0]