Add tests for begin, end, middle revert and continue filter after lock
This commit is contained in:
@@ -154,6 +154,203 @@ class TestFilter(unittest.TestCase):
|
||||
session.filter(self.conn, block, tx)
|
||||
|
||||
|
||||
|
||||
def test_filter_resume_multi_revert_last(self):
|
||||
fltr_one = MockFilter('foo')
|
||||
self.store.register(fltr_one)
|
||||
|
||||
fltr_two = MockFilter('bar', brk_hard=True)
|
||||
self.store.register(fltr_two)
|
||||
|
||||
self.session.start()
|
||||
|
||||
item = self.store.get('0')
|
||||
item.next()
|
||||
|
||||
tx_hash = os.urandom(32).hex()
|
||||
tx = MockTx(42, tx_hash)
|
||||
block = MockBlock(13, [tx_hash])
|
||||
|
||||
with self.assertRaises(MockFilterError):
|
||||
self.session.filter(self.conn, block, tx)
|
||||
|
||||
# Unlock the state, reverting to previous filter
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
self.conn = MockConn()
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_bar = MockFilter('bar')
|
||||
store.register(fltr_bar)
|
||||
store.connect()
|
||||
store.start(ignore_lock=True)
|
||||
store.unlock_filter(revert=True)
|
||||
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
session = SyncSession(store)
|
||||
self.conn = MockConn()
|
||||
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
|
||||
store.connect()
|
||||
|
||||
session.start()
|
||||
|
||||
session.filter(self.conn, block, tx)
|
||||
|
||||
|
||||
def test_filter_resume_multi_continue_last(self):
|
||||
fltr_one = MockFilter('foo')
|
||||
self.store.register(fltr_one)
|
||||
|
||||
fltr_two = MockFilter('bar', brk_hard=True)
|
||||
self.store.register(fltr_two)
|
||||
|
||||
self.session.start()
|
||||
|
||||
item = self.store.get('0')
|
||||
item.next()
|
||||
|
||||
tx_hash = os.urandom(32).hex()
|
||||
tx = MockTx(42, tx_hash)
|
||||
block = MockBlock(13, [tx_hash])
|
||||
|
||||
with self.assertRaises(MockFilterError):
|
||||
self.session.filter(self.conn, block, tx)
|
||||
|
||||
# Unlock the state, reverting to previous filter
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
self.conn = MockConn()
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_bar = MockFilter('bar')
|
||||
store.register(fltr_bar)
|
||||
store.connect()
|
||||
store.start(ignore_lock=True)
|
||||
store.unlock_filter(revert=False)
|
||||
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
session = SyncSession(store)
|
||||
self.conn = MockConn()
|
||||
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
|
||||
session.start()
|
||||
|
||||
session.filter(self.conn, block, tx)
|
||||
|
||||
|
||||
def test_filter_resume_multi_revert_middle(self):
|
||||
fltr_one = MockFilter('foo')
|
||||
self.store.register(fltr_one)
|
||||
|
||||
fltr_two = MockFilter('bar', brk_hard=True)
|
||||
self.store.register(fltr_two)
|
||||
|
||||
fltr_three = MockFilter('baz')
|
||||
self.store.register(fltr_three)
|
||||
|
||||
self.session.start()
|
||||
|
||||
item = self.store.get('0')
|
||||
item.next()
|
||||
|
||||
tx_hash = os.urandom(32).hex()
|
||||
tx = MockTx(42, tx_hash)
|
||||
block = MockBlock(13, [tx_hash])
|
||||
|
||||
with self.assertRaises(MockFilterError):
|
||||
self.session.filter(self.conn, block, tx)
|
||||
|
||||
# Unlock the state, reverting to previous filter
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
self.conn = MockConn()
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
fltr_three = MockFilter('baz')
|
||||
store.register(fltr_three)
|
||||
|
||||
store.connect()
|
||||
store.start(ignore_lock=True)
|
||||
store.unlock_filter(revert=True)
|
||||
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
session = SyncSession(store)
|
||||
self.conn = MockConn()
|
||||
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
fltr_three = MockFilter('baz')
|
||||
store.register(fltr_three)
|
||||
|
||||
store.connect()
|
||||
|
||||
session.start()
|
||||
|
||||
session.filter(self.conn, block, tx)
|
||||
|
||||
|
||||
def test_filter_resume_multi_continue_middle(self):
|
||||
fltr_one = MockFilter('foo')
|
||||
self.store.register(fltr_one)
|
||||
|
||||
fltr_two = MockFilter('bar', brk_hard=True)
|
||||
self.store.register(fltr_two)
|
||||
|
||||
fltr_three = MockFilter('baz')
|
||||
self.store.register(fltr_three)
|
||||
|
||||
self.session.start()
|
||||
|
||||
item = self.store.get('0')
|
||||
item.next()
|
||||
|
||||
tx_hash = os.urandom(32).hex()
|
||||
tx = MockTx(42, tx_hash)
|
||||
block = MockBlock(13, [tx_hash])
|
||||
|
||||
with self.assertRaises(MockFilterError):
|
||||
self.session.filter(self.conn, block, tx)
|
||||
|
||||
# Unlock the state, reverting to previous filter
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
self.conn = MockConn()
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
fltr_three = MockFilter('baz')
|
||||
store.register(fltr_three)
|
||||
|
||||
store.connect()
|
||||
store.start(ignore_lock=True)
|
||||
store.unlock_filter(revert=False)
|
||||
|
||||
store = SyncFsStore(self.path, state_event_callback=state_event_handler, filter_state_event_callback=filter_state_event_handler)
|
||||
session = SyncSession(store)
|
||||
self.conn = MockConn()
|
||||
|
||||
fltr_one = MockFilter('foo')
|
||||
store.register(fltr_one)
|
||||
fltr_two = MockFilter('bar')
|
||||
store.register(fltr_two)
|
||||
fltr_three = MockFilter('baz')
|
||||
store.register(fltr_three)
|
||||
|
||||
session.start()
|
||||
|
||||
session.filter(self.conn, block, tx)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user