From 4305e506fb311c6ad8a1837a489bb7f6e2cfc427 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Fri, 2 Nov 2018 14:38:52 -0400 Subject: [PATCH] Add testcase for prior --- tests/server/test_notifications.py | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/server/test_notifications.py diff --git a/tests/server/test_notifications.py b/tests/server/test_notifications.py new file mode 100644 index 0000000..af559a4 --- /dev/null +++ b/tests/server/test_notifications.py @@ -0,0 +1,47 @@ +import asyncio + +import pytest + +from electrumx.server.controller import Notifications + + +@pytest.mark.asyncio +async def test_simple_mempool(): + n = Notifications() + notified = [] + async def notify(height, touched): + notified.append((height, touched)) + await n.start(5, notify) + + mtouched = {'a', 'b'} + btouched = {'b', 'c'} + await n.on_mempool(mtouched, 6) + assert notified == [(5, set())] + await n.on_block(btouched, 6) + assert notified == [(5, set()), (6, set.union(mtouched, btouched))] + + +@pytest.mark.asyncio +async def test_enter_mempool_quick_blocks_2(): + n = Notifications() + notified = [] + async def notify(height, touched): + notified.append((height, touched)) + await n.start(5, notify) + + # Suppose a gets in block 6 and blocks 7,8 found right after and + # the block processer processes them together. + await n.on_mempool({'a'}, 5) + assert notified == [(5, set()), (5, {'a'})] + # Mempool refreshes with daemon on block 6 + await n.on_mempool({'a'}, 6) + assert notified == [(5, set()), (5, {'a'})] + # Blocks 6, 7 processed together + await n.on_block({'a', 'b'}, 7) + assert notified == [(5, set()), (5, {'a'})] + # Then block 8 processed + await n.on_block({'c'}, 8) + assert notified == [(5, set()), (5, {'a'})] + # Now mempool refreshes + await n.on_mempool(set(), 8) + assert notified == [(5, set()), (5, {'a'}), (8, {'a', 'b', 'c'})]