mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
Merge #21390: test: Test improvements for UTXO set hash tests
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
This commit is contained in:
parent
e10eec249b
commit
6674ee85ab
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
// Database-independent metric indicating the UTXO set size
|
||||||
uint64_t GetBogoSize(const CScript& script_pub_key)
|
uint64_t GetBogoSize(const CScript& script_pub_key)
|
||||||
{
|
{
|
||||||
return 32 /* txid */ +
|
return 32 /* txid */ +
|
||||||
|
@ -1360,15 +1360,15 @@ static RPCHelpMan gettxoutsetinfo()
|
|||||||
RPCResult{
|
RPCResult{
|
||||||
RPCResult::Type::OBJ, "", "",
|
RPCResult::Type::OBJ, "", "",
|
||||||
{
|
{
|
||||||
{RPCResult::Type::NUM, "height", "The current block height (index)"},
|
{RPCResult::Type::NUM, "height", "The block height (index) of the returned statistics"},
|
||||||
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"},
|
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at which these statistics are calculated"},
|
||||||
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"},
|
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs"},
|
||||||
{RPCResult::Type::NUM, "bogosize", "Database-independent, meaningless metric indicating the UTXO set size"},
|
{RPCResult::Type::NUM, "bogosize", "Database-independent, meaningless metric indicating the UTXO set size"},
|
||||||
{RPCResult::Type::STR_HEX, "hash_serialized_2", /* optional */ true, "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"},
|
{RPCResult::Type::STR_HEX, "hash_serialized_2", /* optional */ true, "The serialized hash (only present if 'hash_serialized_2' hash_type is chosen)"},
|
||||||
{RPCResult::Type::STR_HEX, "muhash", /* optional */ true, "The serialized hash (only present if 'muhash' hash_type is chosen)"},
|
{RPCResult::Type::STR_HEX, "muhash", /* optional */ true, "The serialized hash (only present if 'muhash' hash_type is chosen)"},
|
||||||
{RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs (not available when coinstatsindex is used)"},
|
{RPCResult::Type::NUM, "transactions", "The number of transactions with unspent outputs (not available when coinstatsindex is used)"},
|
||||||
{RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk (not available when coinstatsindex is used)"},
|
{RPCResult::Type::NUM, "disk_size", "The estimated size of the chainstate on disk (not available when coinstatsindex is used)"},
|
||||||
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount"},
|
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of coins in the UTXO set"},
|
||||||
{RPCResult::Type::STR_AMOUNT, "total_unspendable_amount", "The total amount of coins permanently excluded from the UTXO set (only available if coinstatsindex is used)"},
|
{RPCResult::Type::STR_AMOUNT, "total_unspendable_amount", "The total amount of coins permanently excluded from the UTXO set (only available if coinstatsindex is used)"},
|
||||||
{RPCResult::Type::OBJ, "block_info", "Info on amounts in the block at this block height (only available if coinstatsindex is used)",
|
{RPCResult::Type::OBJ, "block_info", "Info on amounts in the block at this block height (only available if coinstatsindex is used)",
|
||||||
{
|
{
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
from test_framework.blocktools import create_transaction
|
|
||||||
from test_framework.messages import (
|
from test_framework.messages import (
|
||||||
CBlock,
|
CBlock,
|
||||||
COutPoint,
|
COutPoint,
|
||||||
@ -15,38 +14,30 @@ from test_framework.messages import (
|
|||||||
from test_framework.crypto.muhash import MuHash3072
|
from test_framework.crypto.muhash import MuHash3072
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
from test_framework.test_framework import BitcoinTestFramework
|
||||||
from test_framework.util import assert_equal
|
from test_framework.util import assert_equal
|
||||||
|
from test_framework.wallet import MiniWallet
|
||||||
|
|
||||||
class UTXOSetHashTest(BitcoinTestFramework):
|
class UTXOSetHashTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
self.setup_clean_chain = True
|
self.setup_clean_chain = True
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
|
||||||
self.skip_if_no_wallet()
|
|
||||||
|
|
||||||
def test_deterministic_hash_results(self):
|
|
||||||
self.log.info("Test deterministic UTXO set hash results")
|
|
||||||
|
|
||||||
# These depend on the setup_clean_chain option, the chain loaded from the cache
|
|
||||||
assert_equal(self.nodes[0].gettxoutsetinfo()['hash_serialized_2'], "b61ee2cb582d2f4f94493f3d480e9a59d064706e98a12be0f335a3eeadd5678a")
|
|
||||||
assert_equal(self.nodes[0].gettxoutsetinfo("muhash")['muhash'], "dd5ad2a105c2d29495f577245c357409002329b9f4d6182c0af3dc2f462555c8")
|
|
||||||
|
|
||||||
def test_muhash_implementation(self):
|
def test_muhash_implementation(self):
|
||||||
self.log.info("Test MuHash implementation consistency")
|
self.log.info("Test MuHash implementation consistency")
|
||||||
|
|
||||||
node = self.nodes[0]
|
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
|
# Generate 100 blocks and remove the first since we plan to spend its
|
||||||
# coinbase
|
# coinbase
|
||||||
block_hashes = node.generate(100)
|
block_hashes = wallet.generate(1) + node.generate(99)
|
||||||
blocks = list(map(lambda block: from_hex(CBlock(), node.getblock(block, False)), block_hashes))
|
blocks = list(map(lambda block: from_hex(CBlock(), node.getblock(block, False)), block_hashes))
|
||||||
spending = blocks.pop(0)
|
blocks.pop(0)
|
||||||
|
|
||||||
# Create a spending transaction and mine a block which includes it
|
# Create a spending transaction and mine a block which includes it
|
||||||
tx = create_transaction(node, spending.vtx[0].rehash(), node.getnewaddress(), amount=49)
|
txid = wallet.send_self_transfer(from_node=node)['txid']
|
||||||
txid = node.sendrawtransaction(hexstring=tx.serialize().hex(), maxfeerate=0)
|
tx_block = node.generateblock(output=wallet.get_address(), transactions=[txid])['hash']
|
||||||
|
|
||||||
tx_block = node.generateblock(node.getnewaddress(), [txid])['hash']
|
|
||||||
blocks.append(from_hex(CBlock(), node.getblock(tx_block, False)))
|
blocks.append(from_hex(CBlock(), node.getblock(tx_block, False)))
|
||||||
|
|
||||||
# Serialize the outputs that should be in the UTXO set and add them to
|
# Serialize the outputs that should be in the UTXO set and add them to
|
||||||
@ -77,8 +68,11 @@ class UTXOSetHashTest(BitcoinTestFramework):
|
|||||||
|
|
||||||
assert_equal(finalized[::-1].hex(), node_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):
|
def run_test(self):
|
||||||
self.test_deterministic_hash_results()
|
|
||||||
self.test_muhash_implementation()
|
self.test_muhash_implementation()
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ class MiniWallet:
|
|||||||
self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']})
|
self._utxos.append({'txid': cb_tx['txid'], 'vout': 0, 'value': cb_tx['vout'][0]['value']})
|
||||||
return blocks
|
return blocks
|
||||||
|
|
||||||
|
def get_address(self):
|
||||||
|
return self._address
|
||||||
|
|
||||||
def get_utxo(self, *, txid=''):
|
def get_utxo(self, *, txid=''):
|
||||||
"""
|
"""
|
||||||
Returns a utxo and marks it as spent (pops it from the internal list)
|
Returns a utxo and marks it as spent (pops it from the internal list)
|
||||||
|
Loading…
Reference in New Issue
Block a user