Added remaining stem choice test cases

This commit is contained in:
Kevin F 2022-05-10 09:29:28 -05:00
parent 3a26d053fe
commit 93fc1827b5

View File

@ -2,7 +2,7 @@ import os, uuid
from sqlite3 import Time from sqlite3 import Time
import socket import socket
from queue import Queue from queue import Queue
from time import sleep from time import sleep, time
import secrets import secrets
@ -65,24 +65,49 @@ class MockPeer:
class MockPhase: class MockPhase:
def __init__(self): def __init__(self):
self.stem = False
return return
def remaining_time(self): def remaining_time(self):
return 120 return 120
def is_stem_phase(self): def is_stem_phase(self):
return False return self.stem
class OnionrGossipClientBlockChoice(unittest.TestCase): class OnionrGossipClientBlockChoice(unittest.TestCase):
@patch('gossip.client.dandelionstem.stem_out')
@patch('gossip.client.store_blocks') @patch('gossip.client.store_blocks')
def test_client_block_processing_fluff_phase(self, mock_store_blocks, mock_stem_out): @patch('gossip.client.stem_out')
def test_no_peers(self, mock_stem_out, mock_store_blocks):
def _add_peer():
sleep(5)
gossip_peer_set.add(MockPeer())
client.dandelion_phase = MockPhase()
gossip_peer_set.clear()
Thread(target=_add_peer, daemon=True).start()
t = time()
block_queue_processing()
self.assertAlmostEqual(time() - t, 5, 1)
self.assertFalse(mock_stem_out.called)
self.assertTrue(mock_store_blocks.called)
@patch('gossip.client.store_blocks')
def test_client_block_processing_fluff_phase(self, mock_store_blocks):
gossip_peer_set.add(MockPeer()) gossip_peer_set.add(MockPeer())
client.dandelion_phase = MockPhase() client.dandelion_phase = MockPhase()
block_queue_processing() block_queue_processing()
self.assertTrue(mock_store_blocks.called) self.assertTrue(mock_store_blocks.called)
@patch('gossip.client.stem_out')
def test_client_block_processing_stem_phase(self, mock_stem_out):
gossip_peer_set.add(MockPeer())
client.dandelion_phase = MockPhase()
client.dandelion_phase.stem = True
block_queue_processing()
self.assertTrue(mock_stem_out.called)
unittest.main() unittest.main()