mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 13:03:17 +01:00
6674ee85ab
4f2653a89018fa4d24bd2a551832a7410b682600 test: Use deterministic chain in utxo set hash test (Fabian Jahr) 4973c5175c5fd1f4791ea26e8ddefd6fb11ac1c3 test: Remove wallet dependency of utxo set hash test (Fabian Jahr) 1a27af1d7b5ec18b4248ead1eaf0f381047b4b24 rpc: Improve gettxoutsetinfo help (Fabian Jahr) Pull request description: Follow-ups to #19145: - Small improvement on the help text of RPC gettxoutsetinfo - Using deterministic blockchain in the test `functional/feature_utxo_set_hash.py` - Removing wallet dependency in the test `functional/feature_utxo_set_hash.py` Split out of #19521. ACKs for top commit: MarcoFalke: review ACK 4f2653a89018fa4d24bd2a551832a7410b682600 👲 Tree-SHA512: 92927b3aa22b6324eb4fc9d346755313dec44d973aa69a0ebf80a8569b5f3a7cf3539721ebdba183737534b9e29b3e33f412515890f0d0b819878032a3bba8f9
81 lines
3.0 KiB
Python
Executable File
81 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# Copyright (c) 2020-2021 The Bitcoin Core developers
|
|
# Distributed under the MIT software license, see the accompanying
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
"""Test UTXO set hash value calculation in gettxoutsetinfo."""
|
|
|
|
import struct
|
|
|
|
from test_framework.messages import (
|
|
CBlock,
|
|
COutPoint,
|
|
from_hex,
|
|
)
|
|
from test_framework.crypto.muhash import MuHash3072
|
|
from test_framework.test_framework import BitcoinTestFramework
|
|
from test_framework.util import assert_equal
|
|
from test_framework.wallet import MiniWallet
|
|
|
|
class UTXOSetHashTest(BitcoinTestFramework):
|
|
def set_test_params(self):
|
|
self.num_nodes = 1
|
|
self.setup_clean_chain = True
|
|
|
|
def test_muhash_implementation(self):
|
|
self.log.info("Test MuHash implementation consistency")
|
|
|
|
node = self.nodes[0]
|
|
wallet = MiniWallet(node)
|
|
mocktime = node.getblockheader(node.getblockhash(0))['time'] + 1
|
|
node.setmocktime(mocktime)
|
|
|
|
# Generate 100 blocks and remove the first since we plan to spend its
|
|
# coinbase
|
|
block_hashes = wallet.generate(1) + node.generate(99)
|
|
blocks = list(map(lambda block: from_hex(CBlock(), node.getblock(block, False)), block_hashes))
|
|
blocks.pop(0)
|
|
|
|
# Create a spending transaction and mine a block which includes it
|
|
txid = wallet.send_self_transfer(from_node=node)['txid']
|
|
tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid])['hash']
|
|
blocks.append(from_hex(CBlock(), node.getblock(tx_block, False)))
|
|
|
|
# Serialize the outputs that should be in the UTXO set and add them to
|
|
# a MuHash object
|
|
muhash = MuHash3072()
|
|
|
|
for height, block in enumerate(blocks):
|
|
# The Genesis block coinbase is not part of the UTXO set and we
|
|
# spent the first mined block
|
|
height += 2
|
|
|
|
for tx in block.vtx:
|
|
for n, tx_out in enumerate(tx.vout):
|
|
coinbase = 1 if not tx.vin[0].prevout.hash else 0
|
|
|
|
# Skip witness commitment
|
|
if (coinbase and n > 0):
|
|
continue
|
|
|
|
data = COutPoint(int(tx.rehash(), 16), n).serialize()
|
|
data += struct.pack("<i", height * 2 + coinbase)
|
|
data += tx_out.serialize()
|
|
|
|
muhash.insert(data)
|
|
|
|
finalized = muhash.digest()
|
|
node_muhash = node.gettxoutsetinfo("muhash")['muhash']
|
|
|
|
assert_equal(finalized[::-1].hex(), node_muhash)
|
|
|
|
self.log.info("Test deterministic UTXO set hash results")
|
|
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "4eb23b9673b7472e33ebf6e6aefee849fe5bc5e598fd387c2f9222070cc2f711")
|
|
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "dd74d7f1fb047577915d490e82d063e843f7853ae7543c9980a28c67326e1a2c")
|
|
|
|
def run_test(self):
|
|
self.test_muhash_implementation()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
UTXOSetHashTest().main()
|