Mercurial > public > bitcaviar-plus
comparison tests/test_implementation.py @ 28:30535f42d0ff
refactor code
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Wed, 02 Feb 2022 21:16:10 +0100 |
parents | tests/test_block.py@6a0a8cce058e |
children |
comparison
equal
deleted
inserted
replaced
27:348a07008703 | 28:30535f42d0ff |
---|---|
1 from unittest import TestCase | |
2 from bitcaviar_plus.block import deserialize_block | |
3 from bitcaviar_plus.errors import InvalidMagicBytes | |
4 from bitcaviar_plus.search import search_block_with | |
5 | |
6 | |
7 class TestBlockImplementation(TestCase): | |
8 expected_genesis_block = { | |
9 'magic_number': 'f9beb4d9', | |
10 'size': '0000011d', | |
11 'id': '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', | |
12 'transaction_count': '01', | |
13 'header': { | |
14 'version': '00000001', | |
15 'previous_block_id': '0000000000000000000000000000000000000000000000000000000000000000', | |
16 'merkle_root': '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', | |
17 'time': '495fab29', | |
18 'bits': '1d00ffff', | |
19 'nonce': '7c2bac1d' | |
20 }, | |
21 'transactions': [{ | |
22 'version': '00000001', | |
23 'input_count': '01', | |
24 'output_count': '01', | |
25 'lock_time': '00000000', | |
26 'id': '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', | |
27 'inputs': [{ | |
28 'id': '0000000000000000000000000000000000000000000000000000000000000000', | |
29 'vout': 'ffffffff', | |
30 'script_sig_size': '4d', | |
31 'script_sig': '04ffff001d0104455468652054696d65732030332f4a616e' | |
32 '2f32303039204368616e63656c6c6f72206f6e206272696e' | |
33 '6b206f66207365636f6e64206261696c6f757420666f722062616e6b73', | |
34 'sequence': 'ffffffff' | |
35 }], | |
36 'outputs': [{ | |
37 'value': '000000012a05f200', | |
38 'script_pub_key_size': '43', | |
39 'script_pub_key': '4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f' | |
40 '6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac' | |
41 }] | |
42 }] | |
43 } | |
44 | |
45 def test_parse_genesis_block(self): | |
46 blk_path = '/bitcoin-node/.bitcoin/blocks/blk00000.dat' | |
47 | |
48 with open(blk_path, 'rb') as f: | |
49 try: | |
50 block = deserialize_block(f) | |
51 self.assertEqual( | |
52 block, self.expected_genesis_block, 'Genesis block is not equal to expected genesis block' | |
53 ) | |
54 except InvalidMagicBytes as e: | |
55 self.fail(e) | |
56 | |
57 | |
58 class TestSearchImplementation(TestCase): | |
59 def test_search_block(self): | |
60 genesis_block_hash = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f' | |
61 genesis_block = search_block_with(genesis_block_hash) | |
62 print('---- Genesis block ----') | |
63 print(genesis_block) | |
64 | |
65 first_block_hash = '00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048' | |
66 first_block = search_block_with(first_block_hash) | |
67 print('---- First block ----') | |
68 print(first_block) |