-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
from eth_typing import BlockNumber | ||
from web3.types import EventData | ||
|
||
from sw_utils.event_scanner import EventProcessor, EventScanner | ||
|
||
|
||
class MockedEventProcessor(EventProcessor): | ||
@staticmethod | ||
async def get_from_block() -> BlockNumber: | ||
return BlockNumber(777) | ||
|
||
@staticmethod | ||
async def process_events(events: list[EventData], to_block: BlockNumber) -> None: | ||
pass | ||
|
||
|
||
async def fetch_events(a, b): | ||
return [] | ||
|
||
|
||
async def fetch_events_broken(a, b): | ||
raise ConnectionError | ||
|
||
|
||
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 | ||
|
||
s._contract_call = fetch_events_broken | ||
s.max_request_retries = 1 | ||
with pytest.raises(ConnectionError): | ||
await s.process_new_events(888) | ||
assert s.chunk_size == default_chunk_size / 2 | ||
|
||
await s.process_new_events(888) | ||
assert s.chunk_size == default_chunk_size / 4 |