Add state finalizers

This commit is contained in:
lash
2022-03-14 21:17:00 +00:00
parent f8b256b51b
commit 92cb5d1978
7 changed files with 33 additions and 11 deletions

View File

@@ -27,7 +27,7 @@ class MockTokenCache(Cache):
self.last_filter = None
def put(self, chain_spec, cache_tx):
self.db[cache_tx.tx_hash] = cache_tx
self.db[cache_tx.hash] = cache_tx
def get(self, chain_spec, tx_hash):

View File

@@ -57,7 +57,7 @@ class TestCache(TestShepBase):
self.assertTrue(isinstance(tx.value, float))
self.assertEqual(tx.sender[:4], 'addr')
self.assertEqual(tx.recipient[:4], 'addr')
self.assertEqual(tx.tx_hash[:11], 'ashbashhash')
self.assertEqual(tx.hash[:11], 'ashbashhash')
def test_cache_putget(self):
@@ -65,7 +65,7 @@ class TestCache(TestShepBase):
tx = MockCacheTokenTx()
tx.deserialize(a)
self.cache.put(self.chain_spec, tx)
tx_retrieved = self.cache.get(self.chain_spec, tx.tx_hash)
tx_retrieved = self.cache.get(self.chain_spec, tx.hash)
self.assertEqual(tx, tx_retrieved)

View File

@@ -44,7 +44,7 @@ class TestEntry(TestShepBase):
txs = self.store.by_state(state=self.store.IN_NETWORK)
self.assertEqual(len(txs), 1)
entry.succeed(0)
entry.succeed(None, None)
txs = self.store.by_state()
self.assertEqual(len(txs), 1)

View File

@@ -67,6 +67,7 @@ class TestIntegrateBase(TestShepBase):
def test_state_defer(self):
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
v = self.store.deferred()
self.assertEqual(len(v), 1)
@@ -76,9 +77,11 @@ class TestIntegrateBase(TestShepBase):
def test_state_multiple(self):
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
hx = os.urandom(8).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
v = self.store.deferred()
self.assertEqual(len(v), 2)
@@ -87,12 +90,14 @@ class TestIntegrateBase(TestShepBase):
def test_state_multiple_sort(self):
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.enqueue(hx)
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
hx = os.urandom(4).hex()
self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
@@ -103,12 +108,14 @@ class TestIntegrateBase(TestShepBase):
def test_state_date_threshold(self):
hx = os.urandom(4).hex()
s = self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
then = self.store.modified(s)
time.sleep(0.1)
hx = os.urandom(4).hex()
s = self.store.put(hx, os.urandom(8).hex(), cache_adapter=MockCacheTokenTx)
self.store.reserve(hx)
self.store.fail(hx)
v = self.store.deferred(threshold=then)