# 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 pickle
from bitcoinlib.blocks import *
from tests.test_custom import CustomAssertions
        self.assertEqual(b.bits.hex(), '1d00ffff')
        self.assertEqual(b.time, 1231006505)
        self.assertEqual(b.nonce.hex(), '7c2bac1d')
        self.assertEqual(b.difficulty, 1)
        self.assertEqual(b.target_hex, '00000000ffff0000000000000000000000000000000000000000000000000000')
        self.assertEqual(b.tx_count, 1)
        self.assertEqual(str(b),
                         '<Block(000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, 0, transactions: 1)>')

    def test_blocks_create_block(self):
        block_hash = '00000000000023b05c9ae15577257daf17029604eba0a58824e93306e44d0c62'
        height = 123123
        version = 1
        merkle_root = '37495012489500f0c7ca8bf5bfa116cc8cf46d34214cfbd3b73f6d84d4e667f0'
        prev_block = '000000000000668a34cfab030cf33b865cf3f5eaac46c70f665b70524528f078'
        bits = 443192243
        time = 1305042430
        nonce = 3568752398
        b = Block(block_hash, version, prev_block, merkle_root, time, bits, nonce, height=height)
        expected_dict = {'block_hash': '00000000000023b05c9ae15577257daf17029604eba0a58824e93306e44d0c62',
                         'height': 123123, 'version': 1,
                         'prev_block': '000000000000668a34cfab030cf33b865cf3f5eaac46c70f665b70524528f078',
                         'merkle_root': '37495012489500f0c7ca8bf5bfa116cc8cf46d34214cfbd3b73f6d84d4e667f0',
                         'timestamp': 1305042430, 'bits': 443192243, 'nonce': 3568752398,
                         'target': '0000000000006a93b30000000000000000000000000000000000000000000000',
                         'difficulty': 157416.40184364893}
        self.assertDictEqualExt(b.as_dict(), expected_dict)

    def test_blocks_parse_block_and_transactions(self):
        b = Block.parse(self.rb250000, parse_transactions=True)

# 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_blocks.py
import unittest
import pickle
from bitcoinlib.blocks import *
from tests.test_custom import CustomAssertions

        self.assertEqual(b.bits.hex(), '1d00ffff')
        self.assertEqual(b.time, 1231006505)
        self.assertEqual(b.nonce.hex(), '7c2bac1d')
        self.assertEqual(b.difficulty, 1)
        self.assertEqual(b.target_hex, '00000000ffff0000000000000000000000000000000000000000000000000000')
        self.assertEqual(b.tx_count, 1)
        self.assertEqual(str(b),
                         '<Block(000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, 0, transactions: 1)>')

    def test_blocks_create_block(self):
        block_hash = '00000000000023b05c9ae15577257daf17029604eba0a58824e93306e44d0c62'
        height = 123123
        version = 1
        merkle_root = '37495012489500f0c7ca8bf5bfa116cc8cf46d34214cfbd3b73f6d84d4e667f0'
        prev_block = '000000000000668a34cfab030cf33b865cf3f5eaac46c70f665b70524528f078'
        bits = 443192243
        time = 1305042430
        nonce = 3568752398
        b = Block(block_hash, version, prev_block, merkle_root, time, bits, nonce, height=height)
        expected_dict = {'block_hash': '00000000000023b05c9ae15577257daf17029604eba0a58824e93306e44d0c62',
                         'height': 123123, 'version': 1,
                         'prev_block': '000000000000668a34cfab030cf33b865cf3f5eaac46c70f665b70524528f078',
                         'merkle_root': '37495012489500f0c7ca8bf5bfa116cc8cf46d34214cfbd3b73f6d84d4e667f0',
                         'timestamp': 1305042430, 'bits': 443192243, 'nonce': 3568752398,
                         'target': '0000000000006a93b30000000000000000000000000000000000000000000000',
                         'difficulty': 157416.40184364893}
        self.assertDictEqualExt(b.as_dict(), expected_dict)

    def test_blocks_parse_block_and_transactions(self):
        b = Block.parse(self.rb250000, parse_transactions=True)

        self.assertEqual(b.block_hash.hex(), '000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214')