Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
F4ever committed Aug 21, 2023
1 parent 7328240 commit f60a3b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 16 additions & 3 deletions src/transport/msg_schemas.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import logging
import re
from typing import Callable, TypedDict

from eth_typing import Hash32
from schema import Regex, Schema, And

from cryptography.verify_signature import verify_message_with_signature


logger = logging.getLogger(__name__)


HASH_REGREX = Regex('^0x[0-9,A-F]{64}$', flags=re.IGNORECASE)
ADDRESS_REGREX = Regex('^0x[0-9,A-F]{40}$', flags=re.IGNORECASE)

Expand Down Expand Up @@ -73,7 +76,7 @@ class DepositMessage(TypedDict):
def get_deposit_messages_sign_filter(attestation_prefix: bytes) -> Callable:
"""Returns filter that checks message validity"""
def check_deposit_messages(msg: DepositMessage) -> bool:
return verify_message_with_signature(
verified = verify_message_with_signature(
data=[attestation_prefix, msg['blockNumber'], msg['blockHash'], msg['depositRoot'], msg['stakingModuleId'], msg['nonce']],
abi=['bytes32', 'uint256', 'bytes32', 'bytes32', 'uint256', 'uint256'],
address=msg['guardianAddress'],
Expand All @@ -84,6 +87,11 @@ def check_deposit_messages(msg: DepositMessage) -> bool:
),
)

if not verified:
logger.error({'msg': 'Message verification failed.', 'value': msg})

return verified

return check_deposit_messages


Expand Down Expand Up @@ -123,7 +131,7 @@ class PauseMessage(TypedDict):

def get_pause_messages_sign_filter(attestation_prefix: bytes) -> Callable:
def check_pause_message(msg: PauseMessage) -> bool:
return verify_message_with_signature(
verified = verify_message_with_signature(
data=[attestation_prefix, msg['blockNumber'], msg['stakingModuleId']],
abi=['bytes32', 'uint256', 'uint256'],
address=msg['guardianAddress'],
Expand All @@ -134,6 +142,11 @@ def check_pause_message(msg: PauseMessage) -> bool:
),
)

if not verified:
logger.error({'msg': 'Message verification failed.', 'value': msg})

return verified

return check_pause_message


Expand Down
6 changes: 1 addition & 5 deletions tests/bots/test_depositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_depositor_one_module_deposited(depositor_bot, block_data):
depositor_bot._deposit_to_module = Mock(return_value=True)
depositor_bot.execute(block_data)

depositor_bot._deposit_to_module.assert_called_once()
assert depositor_bot._deposit_to_module.call_count == 2


@pytest.mark.unit
Expand All @@ -67,10 +67,6 @@ def test_check_balance_dry(depositor_bot, caplog):
def test_check_balance(depositor_bot, caplog, set_account):
caplog.set_level(logging.INFO)

depositor_bot.w3.eth.get_balance = Mock(return_value=50)
depositor_bot._check_balance()
assert 'Small account balance on address ' in caplog.messages[-1]

depositor_bot.w3.eth.get_balance = Mock(return_value=10*10**18)
depositor_bot._check_balance()
assert 'Check account balance' in caplog.messages[-1]
Expand Down

0 comments on commit f60a3b5

Please sign in to comment.