From 0e52491b8f41e15bc46ebf516848cb3ac61382f5 Mon Sep 17 00:00:00 2001 From: Dmitrii Date: Mon, 23 Dec 2024 19:12:28 +0500 Subject: [PATCH] fix: formatting --- tests/execution_requests/conftest.py | 9 +-- tests/execution_requests/helpers.py | 32 +++++---- tests/execution_requests/stubs.py | 11 ++-- .../execution_requests/test_consolidations.py | 64 ++++++++++-------- tests/execution_requests/test_withdrawals.py | 66 +++++++++---------- 5 files changed, 98 insertions(+), 84 deletions(-) diff --git a/tests/execution_requests/conftest.py b/tests/execution_requests/conftest.py index d42e8c9..014eb26 100644 --- a/tests/execution_requests/conftest.py +++ b/tests/execution_requests/conftest.py @@ -19,19 +19,14 @@ def validator(): def user_validator(user_keys): random_validator = TestValidator.random() user_keys[random_validator.pubkey] = NamedKey( - key=random_validator.pubkey, - operatorName='Test operator', - operatorIndex='1', - moduleIndex='1' + key=random_validator.pubkey, operatorName='Test operator', operatorIndex='1', moduleIndex='1' ) return random_validator @pytest.fixture def watcher(user_keys) -> WatcherStub: - return WatcherStub( - user_keys=user_keys - ) + return WatcherStub(user_keys=user_keys) @pytest.fixture diff --git a/tests/execution_requests/helpers.py b/tests/execution_requests/helpers.py index 29c16cb..5d6a331 100644 --- a/tests/execution_requests/helpers.py +++ b/tests/execution_requests/helpers.py @@ -1,13 +1,23 @@ from secrets import token_hex -from src.providers.consensus.typings import FullBlockInfo, BlockHeader, BlockHeaderMessage, BlockMessage, BlockBody, \ - BlockExecutionPayload, ExecutionRequests, WithdrawalRequest, ConsolidationRequest +from src.providers.consensus.typings import ( + FullBlockInfo, + BlockHeader, + BlockHeaderMessage, + BlockMessage, + BlockBody, + BlockExecutionPayload, + ExecutionRequests, + WithdrawalRequest, + ConsolidationRequest, +) from src.typings import StateRoot, BlockRoot def gen_random_pubkey(): return random_hex(48) + def gen_random_address(): return random_hex(20) @@ -16,8 +26,9 @@ def random_hex(length: int) -> str: return '0x' + token_hex(length) -def create_sample_block(withdrawals: list[WithdrawalRequest] = None, - consolidations: list[ConsolidationRequest] = None) -> FullBlockInfo: +def create_sample_block( + withdrawals: list[WithdrawalRequest] = None, consolidations: list[ConsolidationRequest] = None +) -> FullBlockInfo: block = FullBlockInfo( root=BlockRoot('0xa69fd326c1e4a84ac56a9f1e440cdb451fce8c4535e4fabd8447cda15506a8d5'), canonical=True, @@ -27,8 +38,9 @@ def create_sample_block(withdrawals: list[WithdrawalRequest] = None, proposer_index='25', parent_root=BlockRoot('0x924057843cd2718a918a1e354c0eb111b15f471319195ed9eeb45e7bf2dae3a7'), state_root=StateRoot('0xcc026c107005b9442a26d763409886968cde30a1fbd605e2d9a1c813ddce9062'), - body_root='0x6f01de44a85b4cbe85d1d452de1979630217ce42e2326388152f39bb9d0a3dce'), - signature='0x99dde0eb3eaaec71e26e7a614f7eb99c37d7a143edbd55c0b2648dc9f2e754a4e26c3f1320592c2603567cc089a68d5d12f65ec1d9940837dd0d59b05356a0bbc1c3ad51a9546ece8c1233b7398ae3cf1df27c61591bf548b065b68d69bb9450' + body_root='0x6f01de44a85b4cbe85d1d452de1979630217ce42e2326388152f39bb9d0a3dce', + ), + signature='0x99dde0eb3eaaec71e26e7a614f7eb99c37d7a143edbd55c0b2648dc9f2e754a4e26c3f1320592c2603567cc089a68d5d12f65ec1d9940837dd0d59b05356a0bbc1c3ad51a9546ece8c1233b7398ae3cf1df27c61591bf548b065b68d69bb9450', ), message=BlockMessage( slot='33', @@ -40,17 +52,15 @@ def create_sample_block(withdrawals: list[WithdrawalRequest] = None, voluntary_exits=[], proposer_slashings=[], attester_slashings=[], - ) + ), ), - signature='0x99dde0eb3eaaec71e26e7a614f7eb99c37d7a143edbd55c0b2648dc9f2e754a4e26c3f1320592c2603567cc089a68d5d12f65ec1d9940837dd0d59b05356a0bbc1c3ad51a9546ece8c1233b7398ae3cf1df27c61591bf548b065b68d69bb9450' + signature='0x99dde0eb3eaaec71e26e7a614f7eb99c37d7a143edbd55c0b2648dc9f2e754a4e26c3f1320592c2603567cc089a68d5d12f65ec1d9940837dd0d59b05356a0bbc1c3ad51a9546ece8c1233b7398ae3cf1df27c61591bf548b065b68d69bb9450', ) if not withdrawals and not consolidations: return block execution_requests = ExecutionRequests( - deposits=[], - withdrawals=withdrawals or [], - consolidations=consolidations or [] + deposits=[], withdrawals=withdrawals or [], consolidations=consolidations or [] ) block.message.body.execution_requests = execution_requests return block diff --git a/tests/execution_requests/stubs.py b/tests/execution_requests/stubs.py index 37c1ee4..42f6e21 100644 --- a/tests/execution_requests/stubs.py +++ b/tests/execution_requests/stubs.py @@ -12,8 +12,7 @@ class TestValidator: @staticmethod def random(): - return TestValidator(pubkey=gen_random_pubkey(), - withdrawal_address=gen_random_address()) + return TestValidator(pubkey=gen_random_pubkey(), withdrawal_address=gen_random_address()) class AlertmanagerStub: @@ -32,8 +31,12 @@ class WatcherStub: indexed_validators_keys: dict[str, str] valid_withdrawal_addresses: set[str] - def __init__(self, user_keys: dict[str, NamedKey] = None, indexed_validators_keys: dict[str, str] = None, - valid_withdrawal_addresses: set[str] = None): + def __init__( + self, + user_keys: dict[str, NamedKey] = None, + indexed_validators_keys: dict[str, str] = None, + valid_withdrawal_addresses: set[str] = None, + ): self.alertmanager = AlertmanagerStub() self.user_keys = user_keys or dict() self.indexed_validators_keys = indexed_validators_keys or dict() diff --git a/tests/execution_requests/test_consolidations.py b/tests/execution_requests/test_consolidations.py index ac33aeb..8e6543d 100644 --- a/tests/execution_requests/test_consolidations.py +++ b/tests/execution_requests/test_consolidations.py @@ -9,13 +9,15 @@ def test_source_is_valid_withdrawal_address(withdrawal_address: str, watcher: Wa random_source_pubkey = gen_random_pubkey() random_target_pubkey = gen_random_pubkey() - block = create_sample_block(consolidations=[ - ConsolidationRequest( - source_address=withdrawal_address, - source_pubkey=random_source_pubkey, - target_pubkey=random_target_pubkey - ) - ]) + block = create_sample_block( + consolidations=[ + ConsolidationRequest( + source_address=withdrawal_address, + source_pubkey=random_source_pubkey, + target_pubkey=random_target_pubkey, + ) + ] + ) handler = ConsolidationHandler() task = handler.handle(watcher, block) @@ -36,13 +38,15 @@ def test_consolidate_user_validator(user_validator: TestValidator, watcher: Watc random_source_address = gen_random_address() random_target_pubkey = gen_random_pubkey() - block = create_sample_block(consolidations=[ - ConsolidationRequest( - source_address=random_source_address, - source_pubkey=user_validator.pubkey, - target_pubkey=random_target_pubkey - ) - ]) + block = create_sample_block( + consolidations=[ + ConsolidationRequest( + source_address=random_source_address, + source_pubkey=user_validator.pubkey, + target_pubkey=random_target_pubkey, + ) + ] + ) handler = ConsolidationHandler() task = handler.handle(watcher, block) @@ -63,13 +67,15 @@ def test_donation(user_validator: TestValidator, watcher: WatcherStub): random_source_address = gen_random_address() random_source_pubkey = gen_random_pubkey() - block = create_sample_block(consolidations=[ - ConsolidationRequest( - source_address=random_source_address, - source_pubkey=random_source_pubkey, - target_pubkey=user_validator.pubkey - ) - ]) + block = create_sample_block( + consolidations=[ + ConsolidationRequest( + source_address=random_source_address, + source_pubkey=random_source_pubkey, + target_pubkey=user_validator.pubkey, + ) + ] + ) handler = ConsolidationHandler() task = handler.handle(watcher, block) @@ -91,13 +97,15 @@ def test_absence_of_alerts_on_foreign_validators(watcher: WatcherStub): random_target_pubkey = gen_random_pubkey() random_source_pubkey = gen_random_pubkey() - block = create_sample_block(consolidations=[ - ConsolidationRequest( - source_address=random_source_address, - source_pubkey=random_source_pubkey, - target_pubkey=random_target_pubkey - ) - ]) + block = create_sample_block( + consolidations=[ + ConsolidationRequest( + source_address=random_source_address, + source_pubkey=random_source_pubkey, + target_pubkey=random_target_pubkey, + ) + ] + ) handler = ConsolidationHandler() task = handler.handle(watcher, block) diff --git a/tests/execution_requests/test_withdrawals.py b/tests/execution_requests/test_withdrawals.py index 8c1108b..fce1ce5 100644 --- a/tests/execution_requests/test_withdrawals.py +++ b/tests/execution_requests/test_withdrawals.py @@ -7,13 +7,11 @@ def tedt_user_validator(user_validator: TestValidator, watcher: WatcherStub): random_address = gen_random_address() - block = create_sample_block(withdrawals=[ - WithdrawalRequest( - source_address=random_address, - validator_pubkey=user_validator.pubkey, - amount='32' - ) - ]) + block = create_sample_block( + withdrawals=[ + WithdrawalRequest(source_address=random_address, validator_pubkey=user_validator.pubkey, amount='32') + ] + ) handler = ElTriggeredExitHandler() task = handler.handle(watcher, block) @@ -31,13 +29,11 @@ def tedt_user_validator(user_validator: TestValidator, watcher: WatcherStub): def test_absence_of_alerts_for_foreign_validator(validator: TestValidator, watcher: WatcherStub): - block = create_sample_block(withdrawals=[ - WithdrawalRequest( - source_address=gen_random_address(), - validator_pubkey=validator.pubkey, - amount='32' - ) - ]) + block = create_sample_block( + withdrawals=[ + WithdrawalRequest(source_address=gen_random_address(), validator_pubkey=validator.pubkey, amount='32') + ] + ) handler = ElTriggeredExitHandler() task = handler.handle(watcher, block) @@ -47,13 +43,11 @@ def test_absence_of_alerts_for_foreign_validator(validator: TestValidator, watch def test_from_user_withdrawal_address(validator: TestValidator, withdrawal_address: str, watcher: WatcherStub): - block = create_sample_block(withdrawals=[ - WithdrawalRequest( - source_address=withdrawal_address, - validator_pubkey=validator.pubkey, - amount='32' - ) - ]) + block = create_sample_block( + withdrawals=[ + WithdrawalRequest(source_address=withdrawal_address, validator_pubkey=validator.pubkey, amount='32') + ] + ) handler = ElTriggeredExitHandler() task = handler.handle(watcher, block) @@ -63,7 +57,10 @@ def test_from_user_withdrawal_address(validator: TestValidator, withdrawal_addre alert = watcher.alertmanager.sent_alerts[0] assert alert.labels.alertname.startswith('HeadWatcherELWithdrawalFromUserWithdrawalAddress') assert alert.labels.severity == 'critical' - assert alert.annotations.summary == "🔗‍🏃🚪Our validator triggered withdrawal was requested from our Withdrawal Vault address" + assert ( + alert.annotations.summary + == "🔗‍🏃🚪Our validator triggered withdrawal was requested from our Withdrawal Vault address" + ) assert validator.pubkey in alert.annotations.description assert withdrawal_address in alert.annotations.description assert '32' in alert.annotations.description @@ -81,25 +78,26 @@ def test_works_on_dencun(watcher: WatcherStub): def test_absense_of_alerts_for_foreign_validator(): - validator_pubkey = '0x84a687ffdf21a0ad754d0164d1e2c03035613ab76359e7f5cf51ea4a425a6ee026725ec0a0dbd336f7dab759596f0bf8' + validator_pubkey = ( + '0x84a687ffdf21a0ad754d0164d1e2c03035613ab76359e7f5cf51ea4a425a6ee026725ec0a0dbd336f7dab759596f0bf8' + ) amount = "32" watcher = WatcherStub( user_keys={ validator_pubkey: NamedKey( - key=validator_pubkey, - operatorName='Test operator', - operatorIndex='1', - moduleIndex='1' + key=validator_pubkey, operatorName='Test operator', operatorIndex='1', moduleIndex='1' ) } ) - block = create_sample_block(withdrawals=[ - WithdrawalRequest( - source_address='0x0048281f02e108ec495e48a25d2adb4732df75bf5750c060ff31c864c053d28d', - validator_pubkey='0xaaf6c1251e73fb600624937760fef218aace5b253bf068ed45398aeb29d821e4d2899343ddcbbe37cb3f6cf500dff26c', - amount=amount - ) - ]) + block = create_sample_block( + withdrawals=[ + WithdrawalRequest( + source_address='0x0048281f02e108ec495e48a25d2adb4732df75bf5750c060ff31c864c053d28d', + validator_pubkey='0xaaf6c1251e73fb600624937760fef218aace5b253bf068ed45398aeb29d821e4d2899343ddcbbe37cb3f6cf500dff26c', + amount=amount, + ) + ] + ) handler = ElTriggeredExitHandler() task = handler.handle(watcher, block)