commit 755a030175bab3034b389f3e8894ef787d02eb27
parent 2b5383e9e0877521046f70df27b6669ef56cf5e0
Author: lash <dev@holbrook.no>
Date: Sat, 19 Mar 2022 01:24:08 +0000
Syncitem sync state done on last next
Diffstat:
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/chainsyncer/store/fs.py b/chainsyncer/store/fs.py
@@ -83,6 +83,7 @@ class SyncFsItem:
block_number += 1
tx_index = 0
if self.target >= 0 and block_number > self.target:
+ self.sync_state.move(self.state_key, self.sync_state.DONE)
raise SyncDone(self.target)
else:
tx_index += 1
@@ -186,7 +187,7 @@ class SyncFsStore:
factory = SimpleFileStoreFactory(base_filter_path, binary=True)
filter_state_backend = PersistedState(factory.add, 0, check_alias=False)
self.filter_state = SyncState(filter_state_backend)
- self.filters = []
+ self.filters = [] # used by SyncSession
def register(self, fltr):
diff --git a/tests/test_fs.py b/tests/test_fs.py
@@ -216,6 +216,29 @@ class TestFs(unittest.TestCase):
store = SyncFsStore(self.path, session_id='foo')
store.start()
o = store.get(0)
+ self.assertEqual(o.cursor, 2)
+ self.assertEqual(o.target, 13)
+ o.next(advance_block=True)
+ o.next(advance_block=True)
+
+ session.stop(o)
+ store = SyncFsStore(self.path, session_id='foo')
+ store.start()
+ self.assertEqual(o.cursor, 4)
+ self.assertEqual(o.target, 13)
+
+
+ def test_sync_history_complete(self):
+ store = SyncFsStore(self.path, session_id='foo')
+ session = SyncSession(store)
+
+ session.start(target=3)
+ o = session.get(0)
+ o.next(advance_block=True)
+ o.next(advance_block=True)
+ o.next(advance_block=True)
+ with self.assertRaises(SyncDone):
+ o.next(advance_block=True)
if __name__ == '__main__':