Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dputko committed Dec 23, 2024
1 parent a17b7d5 commit 0e52491
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 84 deletions.
9 changes: 2 additions & 7 deletions tests/execution_requests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions tests/execution_requests/helpers.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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
11 changes: 7 additions & 4 deletions tests/execution_requests/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
64 changes: 36 additions & 28 deletions tests/execution_requests/test_consolidations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
66 changes: 32 additions & 34 deletions tests/execution_requests/test_withdrawals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 0e52491

Please sign in to comment.