chainsyncer

Blockchain syncer driver
Log | Files | Refs | LICENSE

commit e8decb9cb7c4f82b8749225b19f7e7fd7e1ea879
parent 18f9b9bd1f5bcfc18a9c8f4fa9dea2be42951cd5
Author: lash <dev@holbrook.no>
Date:   Wed, 30 Mar 2022 05:25:26 +0000

Add filter counts in session tests, finish sync interrupt test

Diffstat:
Mchainsyncer/unittest/base.py | 3++-
Mtests/test_session.py | 24+++++++++++++++++++-----
2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/chainsyncer/unittest/base.py b/chainsyncer/unittest/base.py @@ -67,6 +67,7 @@ class MockBlockGenerator: driver.add_block(block) + class MockConn: """Noop connection mocker. @@ -157,7 +158,6 @@ class MockFilter: def filter(self, conn, block, tx): r = False - self.contents.append((block.number, tx.index, tx.hash,)) if self.brk_hard != None: r = True if self.brk_hard > 0: @@ -169,6 +169,7 @@ class MockFilter: if self.brk > 0: r = True self.brk -= 1 + self.contents.append((block.number, tx.index, tx.hash,)) logg.debug('filter {} result {} block {}'.format(self.common_name(), r, block.number)) return r diff --git a/tests/test_session.py b/tests/test_session.py @@ -80,14 +80,17 @@ class TestFilter(unittest.TestCase): generator = MockBlockGenerator() generator.generate([1], driver=drv) - fltr_one = MockFilter('foo', brk_hard=1) + fltr_one = MockFilter('foo') self.store.register(fltr_one) - fltr_two = MockFilter('bar') + fltr_two = MockFilter('bar', brk_hard=1) self.store.register(fltr_two) with self.assertRaises(MockFilterError): drv.run(self.conn) + self.assertEqual(len(fltr_one.contents), 1) + self.assertEqual(len(fltr_two.contents), 0) + store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler) fltr_one = MockFilter('foo') #, brk_hard=1) @@ -98,16 +101,21 @@ class TestFilter(unittest.TestCase): with self.assertRaises(LockError): drv = MockDriver(store, target=1) + self.assertEqual(len(fltr_one.contents), 0) + self.assertEqual(len(fltr_two.contents), 0) + def test_driver_interrupt_filter(self): drv = MockDriver(self.store, target=1) generator = MockBlockGenerator() generator.generate([1, 1], driver=drv) - fltr_one = MockFilter('foo', brk=1) + fltr_one = MockFilter('foo') self.store.register(fltr_one) - fltr_two = MockFilter('bar') + fltr_two = MockFilter('bar', brk=1) self.store.register(fltr_two) + fltr_three = MockFilter('baz') + self.store.register(fltr_three) store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler) @@ -115,6 +123,10 @@ class TestFilter(unittest.TestCase): with self.assertRaises(SyncDone): drv.run(self.conn) + self.assertEqual(len(fltr_one.contents), 2) + self.assertEqual(len(fltr_two.contents), 2) + self.assertEqual(len(fltr_three.contents), 1) + def test_driver_interrupt_sync(self): drv = MockDriver(self.store, interrupt_block=1, target=2) @@ -126,9 +138,9 @@ class TestFilter(unittest.TestCase): drv.run(self.conn, interval=0.1) + self.assertEqual(len(fltr_one.contents), 3) store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler) - fltr_one = MockFilter('foo') store.register(fltr_one) drv = MockDriver(store) generator.apply(drv, offset=1) @@ -137,6 +149,8 @@ class TestFilter(unittest.TestCase): drv.run(self.conn, interval=0.1) self.assertEqual(e, 2) + self.assertEqual(len(fltr_one.contents), 6) + if __name__ == '__main__': unittest.main()