Skip to content
Open
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
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ omit = ["src/staking_sdk_py/__about__.py"]

[tool.coverage.paths]
staking_sdk_py = ["src/staking_sdk_py", "*/staking-sdk-py/src/staking_sdk_py"]
tests = ["tests", "*/staking-sdk-py/tests"]
tests = ["*/staking-sdk-py/tests"]

[tool.coverage.report]
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]

[tool.hatch.build.targets.wheel]
packages = ["src/staking_sdk_py"]

[tool.pytest.ini_options]
testpaths = ["staking-cli/tests"]
Empty file added staking-cli/src/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion staking-cli/src/add_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def register_validator_cli(config: dict, secp_privkey: str, bls_privkey: str, au
# Input validation
try:
if not is_valid_bls_private_key(bls_privkey):
log.error("Key validation failed! Verify bls key")
log.error("Key validation failed! Verify bls key and don't forget to add 0x prefix")
return
if not is_valid_secp256k1_private_key(secp_privkey):
log.error("Key validation failed! Verify secp key")
Expand Down
3 changes: 3 additions & 0 deletions staking-cli/src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def is_valid_amount(amount: int, register=False) -> bool:
def is_valid_bls_private_key(private_key: Union[int, str]) -> bool:
'''Validates a BLS12-381 private key.'''
if isinstance(private_key, str):
if not private_key.startswith("0x"):
return False

try:
# Convert hex string (with '0x' prefix) to integer
key_int = int(private_key, 16)
Expand Down
Empty file added staking-cli/tests/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions staking-cli/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
from pathlib import Path

# Add the staking-cli directory to the Python path
staking_cli_dir = Path(__file__).parent.parent
sys.path.insert(0, str(staking_cli_dir))

18 changes: 18 additions & 0 deletions staking-cli/tests/test_prefix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from src.helpers import is_valid_bls_private_key

BLS_PRIV_NO_PREFIX = "1f8b8a9d3c4e5f112233445566778899aabbccddeeff00112233445566778899"
BLS_PRIV_WITH_PREFIX = "0x" + BLS_PRIV_NO_PREFIX

def test_accepts_0x_prefixed_hex():
assert is_valid_bls_private_key(BLS_PRIV_WITH_PREFIX) is True

def test_rejects_hex_without_prefix():
assert is_valid_bls_private_key(BLS_PRIV_NO_PREFIX) is False

@pytest.mark.parametrize("bad", ["0X" + BLS_PRIV_NO_PREFIX, "0xGG", None, []])
def test_rejects_invalid_inputs(bad):
assert is_valid_bls_private_key(bad) is False

def test_accepts_int():
assert is_valid_bls_private_key(int(BLS_PRIV_NO_PREFIX, 16)) is True