diff --git a/cdp/user_operation.py b/cdp/user_operation.py index ded73a6..e78b05b 100644 --- a/cdp/user_operation.py +++ b/cdp/user_operation.py @@ -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. diff --git a/tests/factories/api_key_factory.py b/tests/factories/api_key_factory.py index 1d54679..af80376 100644 --- a/tests/factories/api_key_factory.py +++ b/tests/factories/api_key_factory.py @@ -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 ( @@ -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 diff --git a/tests/test_api_key_utils.py b/tests/test_api_key_utils.py index 30f347a..21b178a 100644 --- a/tests/test_api_key_utils.py +++ b/tests/test_api_key_utils.py @@ -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"):