PageRenderTime 68ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/test/functional/rpc_invalid_address_message.py

https://github.com/denis2342/bitcoin
Python | 98 lines | 94 code | 0 blank | 4 comment | 2 complexity | 3a4e1bff9370bf3a7e4bccfe05ce701c MD5 | raw file
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2020 The Bitcoin Core developers
  3. # Distributed under the MIT software license, see the accompanying
  4. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. """Test error messages for 'getaddressinfo' and 'validateaddress' RPC commands."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import (
  8. assert_equal,
  9. assert_raises_rpc_error,
  10. )
  11. BECH32_VALID = 'bcrt1qtmp74ayg7p24uslctssvjm06q5phz4yrxucgnv'
  12. BECH32_INVALID_BECH32 = 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqdmchcc'
  13. BECH32_INVALID_BECH32M = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7k35mrzd'
  14. BECH32_INVALID_VERSION = 'bcrt130xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqynjegk'
  15. BECH32_INVALID_SIZE = 'bcrt1s0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav25430mtr'
  16. BECH32_INVALID_V0_SIZE = 'bcrt1qw508d6qejxtdg4y5r3zarvary0c5xw7kqqq5k3my'
  17. BECH32_INVALID_PREFIX = 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx'
  18. BASE58_VALID = 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn'
  19. BASE58_INVALID_PREFIX = '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem'
  20. INVALID_ADDRESS = 'asfah14i8fajz0123f'
  21. class InvalidAddressErrorMessageTest(BitcoinTestFramework):
  22. def set_test_params(self):
  23. self.setup_clean_chain = True
  24. self.num_nodes = 1
  25. def test_validateaddress(self):
  26. node = self.nodes[0]
  27. # Bech32
  28. info = node.validateaddress(BECH32_INVALID_SIZE)
  29. assert not info['isvalid']
  30. assert_equal(info['error'], 'Invalid Bech32 address data size')
  31. info = node.validateaddress(BECH32_INVALID_PREFIX)
  32. assert not info['isvalid']
  33. assert_equal(info['error'], 'Invalid prefix for Bech32 address')
  34. info = node.validateaddress(BECH32_INVALID_BECH32)
  35. assert not info['isvalid']
  36. assert_equal(info['error'], 'Version 1+ witness address must use Bech32m checksum')
  37. info = node.validateaddress(BECH32_INVALID_BECH32M)
  38. assert not info['isvalid']
  39. assert_equal(info['error'], 'Version 0 witness address must use Bech32 checksum')
  40. info = node.validateaddress(BECH32_INVALID_V0_SIZE)
  41. assert not info['isvalid']
  42. assert_equal(info['error'], 'Invalid Bech32 v0 address data size')
  43. info = node.validateaddress(BECH32_VALID)
  44. assert info['isvalid']
  45. assert 'error' not in info
  46. info = node.validateaddress(BECH32_INVALID_VERSION)
  47. assert not info['isvalid']
  48. assert_equal(info['error'], 'Invalid Bech32 address witness version')
  49. # Base58
  50. info = node.validateaddress(BASE58_INVALID_PREFIX)
  51. assert not info['isvalid']
  52. assert_equal(info['error'], 'Invalid prefix for Base58-encoded address')
  53. info = node.validateaddress(BASE58_VALID)
  54. assert info['isvalid']
  55. assert 'error' not in info
  56. # Invalid address format
  57. info = node.validateaddress(INVALID_ADDRESS)
  58. assert not info['isvalid']
  59. assert_equal(info['error'], 'Invalid address format')
  60. def test_getaddressinfo(self):
  61. node = self.nodes[0]
  62. assert_raises_rpc_error(-5, "Invalid Bech32 address data size", node.getaddressinfo, BECH32_INVALID_SIZE)
  63. assert_raises_rpc_error(-5, "Invalid prefix for Bech32 address", node.getaddressinfo, BECH32_INVALID_PREFIX)
  64. assert_raises_rpc_error(-5, "Invalid prefix for Base58-encoded address", node.getaddressinfo, BASE58_INVALID_PREFIX)
  65. assert_raises_rpc_error(-5, "Invalid address format", node.getaddressinfo, INVALID_ADDRESS)
  66. def run_test(self):
  67. self.test_validateaddress()
  68. if self.is_wallet_compiled():
  69. self.init_wallet(node=0)
  70. self.test_getaddressinfo()
  71. if __name__ == '__main__':
  72. InvalidAddressErrorMessageTest().main()