-
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.
Update event scanner chunk logic (#127)
* Update event scanner chunk logic * Add test for event scanner chunks * Remove execution client retries * Add chunk comments * Fix comment typo * Update scanner test
- Loading branch information
Showing
3 changed files
with
68 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "sw-utils" | ||
version = "v0.6.30" | ||
version = "v0.6.31" | ||
description = "StakeWise Python utils" | ||
authors = ["StakeWise Labs <[email protected]>"] | ||
license = "GPL-3.0-or-later" | ||
|
@@ -36,6 +36,7 @@ exclude_dirs = ["sw_utils/tests/"] | |
|
||
[tool.pylint."pre-commit-hook"] | ||
disable=["C0103", "C0114", "C0115", "C0116", "R0801", "R0903", "W0703", "W1514", "W0511"] | ||
ignore-paths=["sw_utils/tests/.*"] | ||
|
||
[tool.pylint."BASIC"] | ||
good-names = ["i", "el", "e", "w", "f", "w3"] | ||
|
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,49 @@ | ||
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() | ||
scanner = EventScanner(processor=p) | ||
scanner._contract_call = fetch_events | ||
assert scanner.chunk_size == default_chunk_size | ||
|
||
scanner._contract_call = fetch_events_broken | ||
scanner.request_retry_seconds = 0 | ||
scanner.max_request_retries = 1 | ||
with pytest.raises(ConnectionError): | ||
await scanner.process_new_events(888) | ||
assert scanner.chunk_size == default_chunk_size | ||
|
||
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 |