Skip to content

Commit

Permalink
Update scanner test
Browse files Browse the repository at this point in the history
  • Loading branch information
cyc60 committed Nov 18, 2024
1 parent 98b79ef commit ffe7d0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion sw_utils/event_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ async def _scan_chunk(
if i < retries - 1:
# Decrease the `eth_getBlocks` range
self.chunk_size = self.chunk_size // 2
to_block = BlockNumber(from_block + self.chunk_size)
# Let the JSON-RPC to recover e.g. from restart
await sleep(self.request_retry_seconds)
continue
Expand Down
26 changes: 17 additions & 9 deletions sw_utils/tests/test_event_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ class TestExitSignatureCrud:
async def test_basic(self):
default_chunk_size = 500000
p = MockedEventProcessor()
s = EventScanner(processor=p)
s._contract_call = fetch_events
assert s.chunk_size == default_chunk_size
scanner = EventScanner(processor=p)
scanner._contract_call = fetch_events
assert scanner.chunk_size == default_chunk_size

s._contract_call = fetch_events_broken
s.max_request_retries = 1
scanner._contract_call = fetch_events_broken
scanner.request_retry_seconds = 0
scanner.max_request_retries = 1
with pytest.raises(ConnectionError):
await s.process_new_events(888)
assert s.chunk_size == default_chunk_size / 2
await scanner.process_new_events(888)
assert scanner.chunk_size == default_chunk_size

await s.process_new_events(888)
assert s.chunk_size == default_chunk_size / 4
scanner.max_request_retries = 2
with pytest.raises(ConnectionError):
await scanner.process_new_events(888)
assert scanner.chunk_size == default_chunk_size // 2

scanner.max_request_retries = 3
with pytest.raises(ConnectionError):
await scanner.process_new_events(888)
assert scanner.chunk_size == default_chunk_size // 8

0 comments on commit ffe7d0e

Please sign in to comment.