Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add block found tests #278

Merged
merged 2 commits into from
Aug 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/chia_log/handlers/test_block_found_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# std
import unittest
from pathlib import Path

# project
from src.chia_log.handlers import block_handler
from src.notifier import EventType, EventService, EventPriority


class TestBlockFoundHandler(unittest.TestCase):
def setUp(self) -> None:
self.handler = block_handler.BlockHandler()
self.example_logs_path = Path(__file__).resolve().parents[1] / "logs/block_found"

def testNominal(self):
with open(self.example_logs_path / "nominal.txt", encoding="UTF-8") as f:
logs = f.readlines()

expected_number_events = [1, 0]
for log, number_events in zip(logs, expected_number_events):
events = self.handler.handle(log)
self.assertEqual(len(events), number_events, "Un-expected number of events")
if number_events == 1:
self.assertEqual(events[0].type, EventType.USER, "Unexpected event type")
self.assertEqual(events[0].priority, EventPriority.LOW, "Unexpected priority")
self.assertEqual(events[0].service, EventService.FULL_NODE, "Unexpected service")


if __name__ == "__main__":
unittest.main()
2 changes: 2 additions & 0 deletions tests/chia_log/logs/block_found/nominal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
21:09:51.795 full_node chia.full_node.full_node: INFO 🍀 Farmed unfinished_block a29012c891bf8d764e66605ff3c5b9b12b125d528f3c530b8c68bf5c8b17d4d0, SP: 49, validation time: 0.06956624984741211, cost: 159432740
23:19:13.564 full_node chia.full_node.full_node: INFO Added unfinished_block 5ee48d91aabf8ba33eda4b67076e1348e64a6059995b25b4e1d0de77e3a5c18e, not farmed by us, SP: 5 farmer response time: 8.495556116104126, Pool pk xch189rpsfgve6d7rcm4aamgur5munpzfaaca89jcfdjczfjhnvjzz8qw5k3ru, validation time: 0.18387579917907715, cost: 560859505, percent full: 5.099%
33 changes: 33 additions & 0 deletions tests/chia_log/parsers/test_block_found_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# std
import unittest
from pathlib import Path

# project
from src.chia_log.parsers import block_parser


class TestBlockFoundParser(unittest.TestCase):
def setUp(self) -> None:
self.parser = block_parser.BlockParser()
self.example_logs_path = Path(__file__).resolve().parents[1] / "logs/block_found"
with open(self.example_logs_path / "nominal.txt", encoding="UTF-8") as f:
self.nominal_logs = f.read()

def tearDown(self) -> None:
pass

def testBasicParsing(self):
for logs in [self.nominal_logs]:
activity_messages = self.parser.parse(logs)
self.assertNotEqual(len(activity_messages), 0, "No log messages found")

expected_eligible_block_counts = [1, 0]
for msg, found in zip(
activity_messages,
expected_eligible_block_counts,
):
self.assertEqual(msg.blocks_count, found, "Found block count don't match")


if __name__ == "__main__":
unittest.main()