Add interrupt test base

This commit is contained in:
nolash
2021-04-15 09:59:45 +02:00
parent c738563d89
commit 908f762cd0
4 changed files with 127 additions and 6 deletions

View File

@@ -14,6 +14,8 @@ class MemBackend:
self.flags = 0
self.target_block = target_block
self.db_session = None
self.filter_names = []
self.filter_values = []
def connect(self):
@@ -28,6 +30,8 @@ class MemBackend:
logg.debug('stateless backend received {} {}'.format(block_height, tx_height))
self.block_height = block_height
self.tx_height = tx_height
for i in range(len(self.filter_values)):
self.filter_values[i] = False
def get(self):
@@ -39,11 +43,13 @@ class MemBackend:
def register_filter(self, name):
pass
self.filter_names.append(name)
self.filter_values.append(False)
def complete_filter(self, n):
pass
self.filter_values[n-1] = True
logg.debug('set filter {}'.format(self.filter_names[n-1]))
def __str__(self):

View File

@@ -72,6 +72,11 @@ class Syncer:
self.backend.register_filter(str(f))
def process_single(self, conn, block, tx, block_height, tx_index):
self.backend.set(block_height, tx_index)
self.filter.apply(conn, block, tx)
class BlockPollSyncer(Syncer):
def __init__(self, backend, pre_callback=None, block_callback=None, post_callback=None):
@@ -120,14 +125,16 @@ class HeadSyncer(BlockPollSyncer):
while True:
try:
tx = block.tx(i)
rcpt = conn.do(receipt(tx.hash))
tx.apply_receipt(rcpt)
self.backend.set(block.number, i)
self.filter.apply(conn, block, tx)
except IndexError as e:
logg.debug('index error syncer rcpt get {}'.format(e))
self.backend.set(block.number + 1, 0)
break
rcpt = conn.do(receipt(tx.hash))
tx.apply_receipt(rcpt)
self.process_single(conn, block, tx, block.number, i)
i += 1