Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter step to github actions #14

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ jobs:
run: pytest tests
- name: Run type checker
run: python -m mypy --config-file mypy.ini -p staking_deposit
- name: Run linter
run: flake8 --config=flake8.ini ./staking_deposit ./tests
24 changes: 14 additions & 10 deletions staking_deposit/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def withdrawal_credentials(self) -> bytes:
def deposit_message(self) -> DepositMessage:
if not MIN_DEPOSIT_AMOUNT <= self.amount <= MAX_DEPOSIT_AMOUNT:
raise ValidationError(f"{self.amount / ETH2GWEI} ETH deposits are not within the bounds of this cli.")
return DepositMessage( # type: ignore[no-untyped-call]
return DepositMessage( # type: ignore[no-untyped-call]
pubkey=self.signing_pk,
withdrawal_credentials=self.withdrawal_credentials,
amount=self.amount,
Expand All @@ -125,8 +125,8 @@ def deposit_message(self) -> DepositMessage:
def signed_deposit(self) -> DepositData:
domain = compute_deposit_domain(fork_version=self.chain_setting.GENESIS_FORK_VERSION)
signing_root = compute_signing_root(self.deposit_message, domain)
signed_deposit = DepositData( # type: ignore[no-untyped-call]
**self.deposit_message.as_dict(), # type: ignore[no-untyped-call]
signed_deposit = DepositData( # type: ignore[no-untyped-call]
**self.deposit_message.as_dict(), # type: ignore[no-untyped-call]
signature=bls.Sign(self.signing_sk, signing_root)
)
return signed_deposit
Expand All @@ -138,7 +138,7 @@ def deposit_datum_dict(self) -> Dict[str, bytes]:
the information needed to verify and process the deposit.
"""
signed_deposit_datum = self.signed_deposit
datum_dict = signed_deposit_datum.as_dict() # type: ignore[no-untyped-call]
datum_dict = signed_deposit_datum.as_dict() # type: ignore[no-untyped-call]
datum_dict.update({'deposit_message_root': self.deposit_message.hash_tree_root})
datum_dict.update({'deposit_data_root': signed_deposit_datum.hash_tree_root})
datum_dict.update({'fork_version': self.chain_setting.GENESIS_FORK_VERSION})
Expand All @@ -165,7 +165,7 @@ def get_bls_to_execution_change(self, validator_index: int) -> SignedBLSToExecut
if self.eth1_withdrawal_address is None:
raise ValueError("The execution address should NOT be empty.")

message = BLSToExecutionChange( # type: ignore[no-untyped-call]
message = BLSToExecutionChange( # type: ignore[no-untyped-call]
validator_index=validator_index,
from_bls_pubkey=self.withdrawal_pk,
to_execution_address=self.eth1_withdrawal_address,
Expand All @@ -177,7 +177,7 @@ def get_bls_to_execution_change(self, validator_index: int) -> SignedBLSToExecut
signing_root = compute_signing_root(message, domain)
signature = bls.Sign(self.withdrawal_sk, signing_root)

return SignedBLSToExecutionChange( # type: ignore[no-untyped-call]
return SignedBLSToExecutionChange( # type: ignore[no-untyped-call]
message=message,
signature=signature,
)
Expand All @@ -186,12 +186,16 @@ def get_bls_to_execution_change_dict(self, validator_index: int) -> Dict[str, by
result_dict: Dict[str, Any] = {}
signed_bls_to_execution_change = self.get_bls_to_execution_change(validator_index)
message = {
'validator_index': str(signed_bls_to_execution_change.message.validator_index), # type: ignore[attr-defined]
'from_bls_pubkey': '0x' + signed_bls_to_execution_change.message.from_bls_pubkey.hex(), # type: ignore[attr-defined]
'to_execution_address': '0x' + signed_bls_to_execution_change.message.to_execution_address.hex(), # type: ignore[attr-defined]
'validator_index':
str(signed_bls_to_execution_change.message.validator_index), # type: ignore[attr-defined]
'from_bls_pubkey': '0x' +
signed_bls_to_execution_change.message.from_bls_pubkey.hex(), # type: ignore[attr-defined]
'to_execution_address': '0x' +
signed_bls_to_execution_change.message.to_execution_address.hex(), # type: ignore[attr-defined]
}
result_dict.update({'message': message})
result_dict.update({'signature': '0x' + signed_bls_to_execution_change.signature.hex()}) # type: ignore[attr-defined]
result_dict.update({'signature': '0x' +
signed_bls_to_execution_change.signature.hex()}) # type: ignore[attr-defined]

# metadata
metadata: Dict[str, Any] = {
Expand Down
4 changes: 2 additions & 2 deletions staking_deposit/utils/ssz.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def compute_fork_data_root(current_version: bytes, genesis_validators_root: byte
"""
if len(current_version) != 4:
raise ValueError(f"Fork version should be in 4 bytes. Got {len(current_version)}.")
return ForkData( # type: ignore[no-untyped-call]
return ForkData( # type: ignore[no-untyped-call]
current_version=current_version,
genesis_validators_root=genesis_validators_root,
).hash_tree_root
Expand Down Expand Up @@ -83,7 +83,7 @@ def compute_signing_root(ssz_object: Serializable, domain: bytes) -> bytes:
"""
if len(domain) != 32:
raise ValueError(f"Domain should be in 32 bytes. Got {len(domain)}.")
domain_wrapped_object = SigningData( # type: ignore[no-untyped-call]
domain_wrapped_object = SigningData( # type: ignore[no-untyped-call]
object_root=ssz_object.hash_tree_root,
domain=domain,
)
Expand Down
10 changes: 7 additions & 3 deletions staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ def validate_deposit(deposit_data_dict: Dict[str, Any], credential: Credential)
return False

# Verify deposit signature && pubkey
deposit_message = DepositMessage(pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount) # type: ignore[no-untyped-call]
deposit_message = DepositMessage( # type: ignore[no-untyped-call]
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount
)
domain = compute_deposit_domain(fork_version)
signing_root = compute_signing_root(deposit_message, domain)
if not bls.Verify(pubkey, signing_root, signature):
return False

# Verify Deposit Root
signed_deposit = DepositData( # type: ignore[no-untyped-call]
signed_deposit = DepositData( # type: ignore[no-untyped-call]
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount,
Expand Down Expand Up @@ -189,7 +193,7 @@ def validate_bls_to_execution_change(btec_dict: Dict[str, Any],
if genesis_validators_root != chain_setting.GENESIS_VALIDATORS_ROOT:
return False

message = BLSToExecutionChange( # type: ignore[no-untyped-call]
message = BLSToExecutionChange( # type: ignore[no-untyped-call]
validator_index=validator_index,
from_bls_pubkey=from_bls_pubkey,
to_execution_address=to_execution_address,
Expand Down