Coverage for tests/utils/wallet_error_utils.py: 94%

50 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1from abc import ABC 

2 

3from .rpc_connection_utils import RpcConnectionUtils 

4 

5 

6class WalletErrorUtils(ABC): 

7 

8 CREATED_WALLET_KEYS_ERROR: str = "Wallet created from keys is not connected to authenticated daemon" 

9 """Create wallet error message.""" 

10 

11 WALLET_IS_CLOSED_ERROR: str = "Wallet is closed" 

12 """Wallet is closed error message.""" 

13 

14 @classmethod 

15 def test_invalid_address_error(cls, ex: Exception, address: str | None = None) -> None: 

16 """Test exception is invalid address. 

17 

18 :param Exception ex: exception to test. 

19 :param str | None address: the invalid address expected to appear in the error message, 

20 if any (default `None`). 

21 """ 

22 msg: str = str(ex) 

23 err_msg: str = "Invalid address" 

24 if address is not None: 

25 err_msg = f"{err_msg}: {address}" 

26 assert msg == err_msg 

27 

28 @classmethod 

29 def test_invalid_tx_hash_error(cls, ex: Exception) -> None: 

30 """Test exception is invalid hash format. 

31 

32 :param Exception ex: exception to test. 

33 """ 

34 msg: str = str(ex) 

35 assert msg == "TX hash has invalid format" 

36 

37 @classmethod 

38 def test_invalid_tx_key_error(cls, ex: Exception) -> None: 

39 """Test exception is invalid key error. 

40 

41 :param Exception ex: exception to test. 

42 """ 

43 msg: str = str(ex) 

44 assert msg == "Tx key has invalid format" 

45 

46 @classmethod 

47 def test_invalid_signature_error(cls, ex: Exception) -> None: 

48 """Test exception is invalid signature error. 

49 

50 :param Exception ex: exception to test. 

51 """ 

52 msg: str = str(ex) 

53 assert msg == "Signature size mismatch with additional tx pubkeys" 

54 

55 @classmethod 

56 def test_no_subaddress_error(cls, ex: Exception) -> None: 

57 """Test exception is no subaddress error. 

58 

59 :param Exception ex: exception to test. 

60 """ 

61 msg: str = str(ex) 

62 assert msg == "Address must not be a subaddress" 

63 

64 @classmethod 

65 def test_signature_header_error(cls, ex: Exception) -> None: 

66 """Test exception is signature header error. 

67 

68 :param Exception ex: exception to test. 

69 """ 

70 msg: str = str(ex) 

71 assert msg == "Signature header check error" 

72 

73 @classmethod 

74 def test_no_wallet_file_error(cls, error: Exception) -> None: 

75 """Test for `No wallet file` monero error. 

76 

77 :param Exception | None error: error to test. 

78 """ 

79 err_msg: str = str(error) 

80 assert err_msg == "No wallet file" 

81 

82 @classmethod 

83 def test_wallet_is_closed_error(cls, error: Exception) -> None: 

84 """Test for `Wallet is closed` monero error. 

85 

86 :param Exception | None error: error to test. 

87 """ 

88 err_msg: str = str(error) 

89 assert err_msg == cls.WALLET_IS_CLOSED_ERROR 

90 

91 @classmethod 

92 def test_wallet_is_not_connected_error(cls, error: Exception) -> None: 

93 """Test exception is wallet-not-connected-to-daemon error. 

94 

95 :param Exception error: error to test. 

96 """ 

97 err_msg: str = str(error) 

98 # TODO normalize Network error message? 

99 assert err_msg == "Wallet is not connected to daemon" or err_msg == RpcConnectionUtils.NETWORK_ERROR_MSG, err_msg 

100 

101 @classmethod 

102 def test_deprecated_payment_id_error(cls, error: Exception) -> None: 

103 """Test exception is deprecated-standalone-payment-id error. 

104 

105 :param Exception error: error to test. 

106 """ 

107 err_msg: str = str(error) 

108 assert err_msg == "Standalone payment id deprecated, use integrated address instead"