chainsyncer/tests/test_basic.py

76 lines
1.6 KiB
Python
Raw Normal View History

# standard imports
2021-02-17 12:44:35 +01:00
import unittest
2022-03-17 15:54:34 +01:00
import tempfile
import shutil
import logging
2021-02-17 12:44:35 +01:00
# local imports
2022-03-17 11:16:55 +01:00
from chainsyncer.session import SyncSession
from chainsyncer.filter import FilterState
2022-03-17 15:54:34 +01:00
from chainsyncer.store.fs import SyncFsStore
2022-03-17 23:07:19 +01:00
from chainsyncer.unittest import (
MockStore,
MockFilter,
)
2021-02-17 12:44:35 +01:00
2022-03-17 15:54:34 +01:00
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
2021-02-17 12:44:35 +01:00
2022-03-16 19:44:13 +01:00
class TestSync(unittest.TestCase):
2022-03-16 19:44:13 +01:00
2022-03-17 15:54:34 +01:00
def setUp(self):
self.path = tempfile.mkdtemp()
self.store = SyncFsStore(self.path)
def tearDown(self):
shutil.rmtree(self.path)
2022-03-16 19:44:13 +01:00
def test_basic(self):
store = MockStore(6)
2022-04-20 14:58:50 +02:00
state = FilterState(store)
2022-03-17 20:36:27 +01:00
session = SyncSession(state)
2022-03-16 19:44:13 +01:00
def test_sum(self):
2022-03-17 23:07:19 +01:00
store = MockStore(6)
2022-04-20 14:58:50 +02:00
state = FilterState(store)
2022-03-16 19:44:13 +01:00
b = b'\x2a' * 32
fltr = MockFilter('foo', z=b)
state.register(fltr)
2022-03-16 19:44:13 +01:00
b = b'\x0d' * 31
fltr = MockFilter('bar', z=b)
2022-03-16 19:44:13 +01:00
with self.assertRaises(ValueError):
state.register(fltr)
2022-03-16 19:44:13 +01:00
b = b'\x0d' * 32
fltr = MockFilter('bar', z=b)
state.register(fltr)
2022-03-16 19:44:13 +01:00
v = state.sum()
2022-03-16 19:44:13 +01:00
self.assertEqual(v.hex(), 'a24abf9fec112b4e0210ae874b4a371f8657b1ee0d923ad6d974aef90bad8550')
def test_session_start(self):
store = MockStore(6)
2022-04-20 14:58:50 +02:00
state = FilterState(store)
2022-03-17 20:36:27 +01:00
session = SyncSession(state)
2022-03-16 19:44:13 +01:00
session.start()
def test_state_dynamic(self):
store = MockStore()
2022-04-20 14:58:50 +02:00
state = FilterState(store)
b = b'\x0d' * 32
fltr = MockFilter(name='foo', z=b)
state.register(fltr)
2021-02-17 12:44:35 +01:00
if __name__ == '__main__':
unittest.main()