chainsyncer

Blockchain syncer driver
Log | Files | Refs | LICENSE

commit 05898a7e003f4848a5594fda0004a15a266b0258
parent 4bda7522ab62613efaa2e4f2af49b5f3de4780f4
Author: lash <dev@holbrook.no>
Date:   Wed, 20 Apr 2022 16:36:06 +0000

Complete rocksdb test

Diffstat:
Mchainsyncer/store/base.py | 2--
Mchainsyncer/store/rocksdb.py | 12++++++++----
Mchainsyncer/unittest/base.py | 9+++++++++
Mchainsyncer/unittest/store.py | 22+++++++++++++---------
4 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/chainsyncer/store/base.py b/chainsyncer/store/base.py @@ -228,8 +228,6 @@ class SyncStore: state_bytes = sync_state_serialize(item.cursor, 0, -1) self.state.put(str(item.cursor), state_bytes) - logg.debug('item {}'.format(self.state.state(item.state_key))) - def load(self, target): self.state.sync(self.state.NEW) diff --git a/chainsyncer/store/rocksdb.py b/chainsyncer/store/rocksdb.py @@ -50,13 +50,17 @@ class SyncRocksDbStore(SyncStore): def get_target(self): - self.target_db.get('target') + v = self.target_db.get('target') + if v != None: + self.target = int(v) def set_target(self, v): - self.target_db.put('target') + self.target_db.put('target', str(v)) + self.target = v - def disconnect(self): - super(SyncRocksDbStore, self).disconnect() + def stop(self, item): + if item != None: + super(SyncRocksDbStore, self).stop(item) self.factory.close() diff --git a/chainsyncer/unittest/base.py b/chainsyncer/unittest/base.py @@ -267,3 +267,12 @@ class MockChainInterfaceConn(MockConn): def handle_receipt(self, hsh): return {} + + +class MockItem: + + def __init__(self, target, offset, cursor, state_key): + self.target = target + self.offset = offset + self.cursor = cursor + self.state_key = state_key diff --git a/chainsyncer/unittest/store.py b/chainsyncer/unittest/store.py @@ -14,7 +14,10 @@ from chainsyncer.error import ( IncompleteFilterError, SyncDone, ) -from chainsyncer.unittest import MockFilter +from chainsyncer.unittest import ( + MockFilter, + MockItem, + ) logg = logging.getLogger(__name__) @@ -50,6 +53,7 @@ class TestStoreBase(unittest.TestCase): def t_default(self): + bogus_item = MockItem(0, 0, 0, 0) store = self.store_factory() fp = os.path.join(self.path, store.session_id) @@ -66,19 +70,19 @@ class TestStoreBase(unittest.TestCase): fpd = os.path.realpath(fpd) self.assertEqual(fpd, fp) - store.disconnect() + store.stop(bogus_item) store = self.store_factory() fpr = os.path.join(self.path, session_id) self.assertEqual(fp, fpr) self.assertTrue(store.is_default) - store.disconnect() + store.stop(bogus_item) store = self.store_factory('default') fpr = os.path.join(self.path, session_id) self.assertEqual(fp, fpr) self.assertTrue(store.is_default) - store.disconnect() + store.stop(bogus_item) store = self.store_factory('foo') fpf = os.path.join(self.path, 'foo') st = os.stat(fpf) @@ -87,11 +91,12 @@ class TestStoreBase(unittest.TestCase): def t_store_start(self): + bogus_item = MockItem(0, 0, 0, 0) store = self.store_factory() store.start(42) self.assertTrue(store.first) - store.disconnect() + store.stop(bogus_item) store = self.store_factory() store.start() self.assertFalse(store.first) @@ -221,13 +226,13 @@ class TestStoreBase(unittest.TestCase): o.next(advance_block=True) session.stop(o) - store.disconnect() store = self.store_factory('foo') store.start() o = store.get(2) def t_sync_history_interrupted(self): + bogus_item = MockItem(0, 0, 0, 0) store = self.store_factory('foo') session = SyncSession(store) @@ -237,7 +242,7 @@ class TestStoreBase(unittest.TestCase): o.next(advance_block=True) session.stop(o) - store.disconnect() + store.stop(bogus_item) store = self.store_factory('foo') store.start() o = store.get(0) @@ -246,8 +251,7 @@ class TestStoreBase(unittest.TestCase): o.next(advance_block=True) o.next(advance_block=True) - session.stop(o) - store.disconnect() + store.stop(bogus_item) store = self.store_factory('foo') store.start() self.assertEqual(o.cursor, 4)