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 linting to GH action workflow #5

Merged
merged 4 commits into from
Apr 17, 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
27 changes: 0 additions & 27 deletions .github/workflows/run-tests.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: ci-runner
run-name: ${{ github.actor }} is running ci
on: [push, pull_request]
jobs:
ci-runner:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements_test.txt
- name: Run tests
run: pytest tests
- name: Run type checker
run: python -m mypy --config-file mypy.ini -p staking_deposit
20 changes: 10 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(
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(
**self.deposit_message.as_dict(),
signed_deposit = DepositData( # type: ignore[no-untyped-call]
valefar-on-discord marked this conversation as resolved.
Show resolved Hide resolved
**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()
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(
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(
return SignedBLSToExecutionChange( # type: ignore[no-untyped-call]
message=message,
signature=signature,
)
Expand All @@ -186,12 +186,12 @@ 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),
'from_bls_pubkey': '0x' + signed_bls_to_execution_change.message.from_bls_pubkey.hex(),
'to_execution_address': '0x' + signed_bls_to_execution_change.message.to_execution_address.hex(),
'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()})
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(
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(
domain_wrapped_object = SigningData( # type: ignore[no-untyped-call]
object_root=ssz_object.hash_tree_root,
domain=domain,
)
Expand Down
6 changes: 3 additions & 3 deletions staking_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ 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)
deposit_message = DepositMessage(pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount) # type: ignore[no-untyped-call]
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(
signed_deposit = DepositData( # type: ignore[no-untyped-call]
pubkey=pubkey,
withdrawal_credentials=withdrawal_credentials,
amount=amount,
Expand Down Expand Up @@ -189,7 +189,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(
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