# Path: bitcoinlib/encoding.py
# def to_hexstring(string):
#     """
#     Convert bytes, string to a hexadecimal string. Use instead of built-in hex() method if format
#     of input string is not known.
# 
#     >>> to_hexstring(b'\\x12\\xaa\\xdd')
#     '12aadd'
# 
#     :param string: Variable to convert to hex string
#     :type string: bytes, str
# 
#     :return: hexstring
#     """
#     if not string:
#         return ''
#     try:
#         bytes.fromhex(string)
#         return string
#     except (ValueError, TypeError):
#         pass
# 
#     if not isinstance(string, bytes):
#         string = bytes(string, 'utf8')
#     return string.hex()
# 
# Path: tests/test_custom.py
# class CustomAssertions:
# 
#     def assertDictEqualExt(self, result_dict, expected_dict, none_allowed=None):
#         """
#         Compare dictionaries, skip items not found in expected dictionary.
# 
#         Lists and recursion's in dictionaries are allowed.
# 
#         :param result_dict: First dictionary with results
#         :type result_dict: dict
#         :param expected_dict: Second dictionary with expected values
#         :type expected_dict: dict
#         :param none_allowed: List of fields for which None value in result_dict is allowed
#         :type none_allowed: list
# 
#         :return bool: Dictionaries are identical?
#         """
#         if none_allowed is None:
#             none_allowed = []
#         if not isinstance(expected_dict, dict):
#             if expected_dict == result_dict:
#                 return True
#             else:
#                 raise AssertionError("Different value for %s != %s" % (result_dict, expected_dict))
#         expected_keys = expected_dict.keys()
#         for k in result_dict:
#             if k not in expected_keys:
#                 continue
#             if isinstance(result_dict[k], dict):
#                 self.assertDictEqualExt(result_dict[k], expected_dict[k], none_allowed)
#             elif isinstance(result_dict[k], list):
#                 for i in range(len(result_dict[k])):
#                     if not isinstance(expected_dict[k], list):
#                         raise AssertionError("No list expected for %s attribute, expected '%s' but received: '%s'" %
#                                              (k, expected_dict[k], result_dict[k]))
#                     self.assertDictEqualExt(result_dict[k][i], expected_dict[k][i], none_allowed)
#             elif result_dict[k] != expected_dict[k]:
#                 if isinstance(result_dict[k], datetime):
#                     if result_dict[k].date() == expected_dict[k].date():
#                         continue
#                 if result_dict[k] is not None or k not in none_allowed:
#                     raise AssertionError("Different value for '%s': %s != %s" % (k, result_dict[k], expected_dict[k]))


import unittest
import logging
    import mysql.connector
    import psycopg2
    from parameterized import parameterized_class
    from psycopg2 import sql
    from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
from bitcoinlib.services.services import *
from bitcoinlib.encoding import to_hexstring
from tests.test_custom import CustomAssertions

    def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, providers=None,
                 timeout=TIMEOUT_TEST, cache_uri=DATABASEFILE_CACHE_UNITTESTS, ignore_priority=True,
                 exclude_providers=None, max_errors=SERVICE_MAX_ERRORS, strict=True):
        super(self.__class__, self).__init__(network, min_providers, max_providers, providers, timeout, cache_uri,
                                             ignore_priority, exclude_providers, max_errors, strict)


class TestService(unittest.TestCase, CustomAssertions):

    def test_service_transaction_get_raw_testnet(self):
        tx_id = 'd3c7fbd3a4ca1cca789560348a86facb3bb21dcd75ed38e85235fb6a32802955'
        raw_tx = '0100000001a3919372c9807d92507289d71bdd38f10682a49c47e50dc0136996b43d8aa54e010000006a47304402201f6e' \
                 '18f4532e14f328bc820cb78c53c57c91b1da9949fecb8cf42318b791fb38022045e78c9e55df1cf3db74bfd52ff2add2b5' \
                 '9ba63e068680f0023e6a80ac9f51f401210239a18d586c34e51238a7c9a27a342abfb35e3e4aa5ac6559889db1dab2816e' \
                 '9dfeffffff023ef59804000000001976a914af8e14a2cecd715c363b3a72b55b59a31e2acac988ac90940d000000000019' \
                 '76a914f0d34949650af161e7cb3f0325a1a8833075165088acb7740f00'
        self.assertEqual(raw_tx, ServiceTest(network='testnet').getrawtransaction(tx_id))

    def test_service_transaction_get_raw_bitcoin(self):
        tx_id = 'b7feea5e7c79d4f6f343b5ca28fa2a1fcacfe9a2b7f44f3d2fd8d6c2d82c4078'
        raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5d0342fe06244d69' \
                 '6e656420627920416e74506f6f6c20626a31312f4542312f4144362f432058d192b6fabe6d6defcf958e3cf9814240e00f' \
                 'a5e36e8cc319cd8141e20890607ccb1954e64843d804000000000000003914000057190200ffffffff013b33b158000000' \
                 '001976a914338c84849423992471bffb1a54a8d9b1d69dc28a88ac00000000'
        self.assertEqual(raw_tx, ServiceTest().getrawtransaction(tx_id))

    def test_service_transaction_get_raw_litecoin(self):
        tx_id = '832518d58e9678bcdb9fe0e417a138daeb880c3a2ee1fb1659f1179efc383c25'
        raw_tx = '01000000018d3a15210548821144e323b9138226926ec66e5f79a3871d4cdefde479a5e076000000006b48304502201952' \

# Path: bitcoinlib/encoding.py
# def to_hexstring(string):
#     """
#     Convert bytes, string to a hexadecimal string. Use instead of built-in hex() method if format
#     of input string is not known.
# 
#     >>> to_hexstring(b'\\x12\\xaa\\xdd')
#     '12aadd'
# 
#     :param string: Variable to convert to hex string
#     :type string: bytes, str
# 
#     :return: hexstring
#     """
#     if not string:
#         return ''
#     try:
#         bytes.fromhex(string)
#         return string
#     except (ValueError, TypeError):
#         pass
# 
#     if not isinstance(string, bytes):
#         string = bytes(string, 'utf8')
#     return string.hex()
# 
# Path: tests/test_custom.py
# class CustomAssertions:
# 
#     def assertDictEqualExt(self, result_dict, expected_dict, none_allowed=None):
#         """
#         Compare dictionaries, skip items not found in expected dictionary.
# 
#         Lists and recursion's in dictionaries are allowed.
# 
#         :param result_dict: First dictionary with results
#         :type result_dict: dict
#         :param expected_dict: Second dictionary with expected values
#         :type expected_dict: dict
#         :param none_allowed: List of fields for which None value in result_dict is allowed
#         :type none_allowed: list
# 
#         :return bool: Dictionaries are identical?
#         """
#         if none_allowed is None:
#             none_allowed = []
#         if not isinstance(expected_dict, dict):
#             if expected_dict == result_dict:
#                 return True
#             else:
#                 raise AssertionError("Different value for %s != %s" % (result_dict, expected_dict))
#         expected_keys = expected_dict.keys()
#         for k in result_dict:
#             if k not in expected_keys:
#                 continue
#             if isinstance(result_dict[k], dict):
#                 self.assertDictEqualExt(result_dict[k], expected_dict[k], none_allowed)
#             elif isinstance(result_dict[k], list):
#                 for i in range(len(result_dict[k])):
#                     if not isinstance(expected_dict[k], list):
#                         raise AssertionError("No list expected for %s attribute, expected '%s' but received: '%s'" %
#                                              (k, expected_dict[k], result_dict[k]))
#                     self.assertDictEqualExt(result_dict[k][i], expected_dict[k][i], none_allowed)
#             elif result_dict[k] != expected_dict[k]:
#                 if isinstance(result_dict[k], datetime):
#                     if result_dict[k].date() == expected_dict[k].date():
#                         continue
#                 if result_dict[k] is not None or k not in none_allowed:
#                     raise AssertionError("Different value for '%s': %s != %s" % (k, result_dict[k], expected_dict[k]))


# Path: tests/test_services.py
import unittest
import logging
    import mysql.connector
    import psycopg2
    from parameterized import parameterized_class
    from psycopg2 import sql
    from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
from bitcoinlib.services.services import *
from bitcoinlib.encoding import to_hexstring
from tests.test_custom import CustomAssertions


    def __init__(self, network=DEFAULT_NETWORK, min_providers=1, max_providers=1, providers=None,
                 timeout=TIMEOUT_TEST, cache_uri=DATABASEFILE_CACHE_UNITTESTS, ignore_priority=True,
                 exclude_providers=None, max_errors=SERVICE_MAX_ERRORS, strict=True):
        super(self.__class__, self).__init__(network, min_providers, max_providers, providers, timeout, cache_uri,
                                             ignore_priority, exclude_providers, max_errors, strict)


class TestService(unittest.TestCase, CustomAssertions):

    def test_service_transaction_get_raw_testnet(self):
        tx_id = 'd3c7fbd3a4ca1cca789560348a86facb3bb21dcd75ed38e85235fb6a32802955'
        raw_tx = '0100000001a3919372c9807d92507289d71bdd38f10682a49c47e50dc0136996b43d8aa54e010000006a47304402201f6e' \
                 '18f4532e14f328bc820cb78c53c57c91b1da9949fecb8cf42318b791fb38022045e78c9e55df1cf3db74bfd52ff2add2b5' \
                 '9ba63e068680f0023e6a80ac9f51f401210239a18d586c34e51238a7c9a27a342abfb35e3e4aa5ac6559889db1dab2816e' \
                 '9dfeffffff023ef59804000000001976a914af8e14a2cecd715c363b3a72b55b59a31e2acac988ac90940d000000000019' \
                 '76a914f0d34949650af161e7cb3f0325a1a8833075165088acb7740f00'
        self.assertEqual(raw_tx, ServiceTest(network='testnet').getrawtransaction(tx_id))

    def test_service_transaction_get_raw_bitcoin(self):
        tx_id = 'b7feea5e7c79d4f6f343b5ca28fa2a1fcacfe9a2b7f44f3d2fd8d6c2d82c4078'
        raw_tx = '01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff5d0342fe06244d69' \
                 '6e656420627920416e74506f6f6c20626a31312f4542312f4144362f432058d192b6fabe6d6defcf958e3cf9814240e00f' \
                 'a5e36e8cc319cd8141e20890607ccb1954e64843d804000000000000003914000057190200ffffffff013b33b158000000' \
                 '001976a914338c84849423992471bffb1a54a8d9b1d69dc28a88ac00000000'
        self.assertEqual(raw_tx, ServiceTest().getrawtransaction(tx_id))

    def test_service_transaction_get_raw_litecoin(self):
        tx_id = '832518d58e9678bcdb9fe0e417a138daeb880c3a2ee1fb1659f1179efc383c25'
        raw_tx = '01000000018d3a15210548821144e323b9138226926ec66e5f79a3871d4cdefde479a5e076000000006b48304502201952' \

                 '093e6082574209150659b294c8e634a30c469fd3dff97a38c8e9ea641d9a022100a9621d0f9d05cbbe274309689bc9086b' \