Skip to content
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
10 changes: 10 additions & 0 deletions cdp/user_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ def __repr__(self) -> str:
"""Return a string representation of the Status."""
return str(self)

def __eq__(self, other):
"""Check if the status is equal to another object. Supports string comparison."""
if isinstance(other, str):
return self.value == other
return super().__eq__(other)

def __hash__(self):
"""Return a hash value for the enum member to allow use as dictionary keys."""
return hash(self.name)

def __init__(self, model: UserOperationModel, smart_wallet_address: str) -> None:
"""Initialize the UserOperation class.

Expand Down
4 changes: 3 additions & 1 deletion tests/factories/api_key_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def dummy_key_factory():
- "ed25519-32": Returns a base64-encoded 32-byte Ed25519 private key.
- "ed25519-64": Returns a base64-encoded 64-byte dummy Ed25519 key (the first 32 bytes will be used).
"""

def _create_dummy(key_type: str = "ecdsa") -> str:
if key_type == "ecdsa":
return (
Expand All @@ -25,9 +26,10 @@ def _create_dummy(key_type: str = "ecdsa") -> str:
return "BXyKC+eFINc/6ztE/3neSaPGgeiU9aDRpaDnAbaA/vyTrUNgtuh/1oX6Vp+OEObV3SLWF+OkF2EQNPtpl0pbfA=="
elif key_type == "ed25519-64":
# Create a 64-byte dummy by concatenating a 32-byte sequence with itself.
dummy_32 = b'\x01' * 32
dummy_32 = b"\x01" * 32
dummy_64 = dummy_32 + dummy_32
return base64.b64encode(dummy_64).decode("utf-8")
else:
raise ValueError("Unsupported key type for dummy key creation")

return _create_dummy
3 changes: 3 additions & 0 deletions tests/test_api_key_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ def test_parse_private_key_pem_ec(dummy_key_factory):
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ec.EllipticCurvePrivateKey)


def test_parse_private_key_ed25519_32(dummy_key_factory):
"""Test that a base64-encoded 32-byte Ed25519 key is parsed correctly using a dummy key from the factory."""
dummy_key = dummy_key_factory("ed25519-32")
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ed25519.Ed25519PrivateKey)


def test_parse_private_key_ed25519_64(dummy_key_factory):
"""Test that a base64-encoded 64-byte input is parsed correctly by taking the first 32 bytes using a dummy key from the factory."""
dummy_key = dummy_key_factory("ed25519-64")
parsed_key = _parse_private_key(dummy_key)
assert isinstance(parsed_key, ed25519.Ed25519PrivateKey)


def test_parse_private_key_invalid():
"""Test that an invalid key string raises a ValueError."""
with pytest.raises(ValueError, match="Could not parse the private key"):
Expand Down