|
6 | 6 |
|
7 | 7 | import struct
|
8 | 8 |
|
9 |
| -from test_framework.blocktools import create_transaction |
10 | 9 | from test_framework.messages import (
|
11 | 10 | CBlock,
|
12 | 11 | COutPoint,
|
|
15 | 14 | from test_framework.muhash import MuHash3072
|
16 | 15 | from test_framework.test_framework import BitcoinTestFramework
|
17 | 16 | from test_framework.util import assert_equal
|
| 17 | +from test_framework.wallet import MiniWallet |
18 | 18 |
|
19 | 19 | class UTXOSetHashTest(BitcoinTestFramework):
|
20 | 20 | def set_test_params(self):
|
21 | 21 | self.num_nodes = 1
|
22 | 22 | self.setup_clean_chain = True
|
23 | 23 |
|
24 |
| - def skip_test_if_missing_module(self): |
25 |
| - self.skip_if_no_wallet() |
26 |
| - |
27 |
| - def test_deterministic_hash_results(self): |
28 |
| - self.log.info("Test deterministic UTXO set hash results") |
29 |
| - |
30 |
| - # These depend on the setup_clean_chain option, the chain loaded from the cache |
31 |
| - assert_equal(self.nodes[0].gettxoutsetinfo()['hash_serialized_2'], "b32ec1dda5a53cd025b95387aad344a801825fe46a60ff952ce26528f01d3be8") |
32 |
| - assert_equal(self.nodes[0].gettxoutsetinfo("muhash")['muhash'], "dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8") |
33 |
| - |
34 | 24 | def test_muhash_implementation(self):
|
35 | 25 | self.log.info("Test MuHash implementation consistency")
|
36 | 26 |
|
37 | 27 | node = self.nodes[0]
|
| 28 | + wallet = MiniWallet(node) |
| 29 | + mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1 |
| 30 | + node.setmocktime(mocktime) |
38 | 31 |
|
39 | 32 | # Generate 100 blocks and remove the first since we plan to spend its
|
40 | 33 | # coinbase
|
41 |
| - block_hashes = node.generate(100) |
| 34 | + block_hashes = wallet.generate(1) + node.generate(99) |
42 | 35 | blocks = list(map(lambda block: FromHex(CBlock(), node.getblock(block, False)), block_hashes))
|
43 |
| - spending = blocks.pop(0) |
| 36 | + blocks.pop(0) |
44 | 37 |
|
45 | 38 | # Create a spending transaction and mine a block which includes it
|
46 |
| - tx = create_transaction(node, spending.vtx[0].rehash(), node.getnewaddress(), amount=49) |
47 |
| - txid = node.sendrawtransaction(hexstring=tx.serialize_with_witness().hex(), maxfeerate=0) |
48 |
| - |
49 |
| - tx_block = node.generateblock(output=node.getnewaddress(), transactions=[txid]) |
| 39 | + txid = wallet.send_self_transfer(from_node=node)['txid'] |
| 40 | + tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid]) |
50 | 41 | blocks.append(FromHex(CBlock(), node.getblock(tx_block['hash'], False)))
|
51 | 42 |
|
52 | 43 | # Serialize the outputs that should be in the UTXO set and add them to
|
@@ -77,8 +68,11 @@ def test_muhash_implementation(self):
|
77 | 68 |
|
78 | 69 | assert_equal(finalized[::-1].hex(), node_muhash)
|
79 | 70 |
|
| 71 | + self.log.info("Test deterministic UTXO set hash results") |
| 72 | + assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "5b1b44097406226c0eb8e1362cd17a1f346522cf9390a8175a57a5262cb1963f") |
| 73 | + assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "4b8803075d7151d06fad3e88b68ba726886794873fbfa841d12aefb2cc2b881b") |
| 74 | + |
80 | 75 | def run_test(self):
|
81 |
| - self.test_deterministic_hash_results() |
82 | 76 | self.test_muhash_implementation()
|
83 | 77 |
|
84 | 78 |
|
|
0 commit comments