test_basic.py (1670B)
1 # standard imports 2 import unittest 3 import tempfile 4 import shutil 5 import logging 6 7 # local imports 8 from chainsyncer.session import SyncSession 9 from chainsyncer.filter import FilterState 10 from chainsyncer.store.fs import SyncFsStore 11 from chainsyncer.unittest import ( 12 MockStore, 13 MockFilter, 14 ) 15 16 logging.basicConfig(level=logging.DEBUG) 17 logg = logging.getLogger() 18 19 20 class TestSync(unittest.TestCase): 21 22 def setUp(self): 23 self.path = tempfile.mkdtemp() 24 self.store = SyncFsStore(self.path) 25 26 27 def tearDown(self): 28 shutil.rmtree(self.path) 29 30 31 def test_basic(self): 32 store = MockStore(6) 33 state = FilterState(store) 34 session = SyncSession(state) 35 36 37 def test_sum(self): 38 store = MockStore(6) 39 state = FilterState(store) 40 41 b = b'\x2a' * 32 42 fltr = MockFilter('foo', z=b) 43 state.register(fltr) 44 45 b = b'\x0d' * 31 46 fltr = MockFilter('bar', z=b) 47 with self.assertRaises(ValueError): 48 state.register(fltr) 49 50 b = b'\x0d' * 32 51 fltr = MockFilter('bar', z=b) 52 state.register(fltr) 53 54 v = state.sum() 55 self.assertEqual(v.hex(), 'a24abf9fec112b4e0210ae874b4a371f8657b1ee0d923ad6d974aef90bad8550') 56 57 58 def test_session_start(self): 59 store = MockStore(6) 60 state = FilterState(store) 61 session = SyncSession(state) 62 session.start() 63 64 65 def test_state_dynamic(self): 66 store = MockStore() 67 state = FilterState(store) 68 69 b = b'\x0d' * 32 70 fltr = MockFilter(name='foo', z=b) 71 state.register(fltr) 72 73 74 if __name__ == '__main__': 75 unittest.main()