Reinstate start tx setter

This commit is contained in:
nolash
2021-04-15 14:11:06 +02:00
parent b4be9ff04c
commit d1077bf87a
6 changed files with 45 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
# standard imports
import os
import logging
# external imports
from hexathon import add_0x
@@ -8,10 +9,12 @@ from hexathon import add_0x
from chainsyncer.driver import HistorySyncer
from chainsyncer.error import NoBlockForYou
logg = logging.getLogger().getChild(__name__)
class MockTx:
def __init__(self, tx_hash, index):
def __init__(self, index, tx_hash):
self.hash = tx_hash
self.index = index
@@ -39,21 +42,23 @@ class TestSyncer(HistorySyncer):
if self.backend.block_height == self.backend.target_block:
self.running = False
raise NoBlockForYou()
if self.backend.block_height > len(self.tx_counts):
return []
block_txs = []
for i in range(self.tx_counts[self.backend.block_height]):
block_txs.append(add_0x(os.urandom(32).hex()))
if self.backend.block_height < len(self.tx_counts):
for i in range(self.tx_counts[self.backend.block_height]):
block_txs.append(add_0x(os.urandom(32).hex()))
logg.debug('get tx height {}'.format(self.backend.tx_height))
return MockBlock(self.backend.block_height, block_txs)
# TODO: implement mock conn instead, and use HeadSyncer.process
def process(self, conn, block):
i = 0
for tx in block.txs:
self.process_single(conn, block, tx)
self.process_single(conn, block, block.tx(i))
self.backend.reset_filter()
i += 1
self.backend.set(self.backend.block_height + 1, 0)