Merge bitcoin/bitcoin#25525: test: remove wallet dependency from mempool_updatefromblock.py

eac1099e0071bfe11fe664a8a490eee6bbc80c47 test: remove wallet dependency  from mempool_updatefromblock.py (Ayush Sharma)

Pull request description:

  This PR enables one of the non-wallet functional tests(`mempool_updatefromblock.py`) to be run with the wallet disabled.

ACKs for top commit:
  aureleoules:
    tACK eac1099e0071bfe11fe664a8a490eee6bbc80c47.

Tree-SHA512: 9734815f2d2e65e8813bd776cf1d847a55ba4181e218c5e7b066ec69a556261069214f675681d672f5d7b0ba8e06342c4a456619dcc005cbf5618a0527303b7f
This commit is contained in:
MacroFake 2022-07-07 13:55:38 +02:00
commit 67c6b61f96
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

View File

@ -12,6 +12,9 @@ import time
from decimal import Decimal from decimal import Decimal
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.address import key_to_p2pkh
from test_framework.wallet_util import bytes_to_wif
from test_framework.key import ECKey
class MempoolUpdateFromBlockTest(BitcoinTestFramework): class MempoolUpdateFromBlockTest(BitcoinTestFramework):
@ -19,8 +22,13 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework):
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-limitdescendantsize=1000', '-limitancestorsize=1000', '-limitancestorcount=100']] self.extra_args = [['-limitdescendantsize=1000', '-limitancestorsize=1000', '-limitancestorcount=100']]
def skip_test_if_missing_module(self): def get_new_address(self):
self.skip_if_no_wallet() key = ECKey()
key.generate()
pubkey = key.get_pubkey().get_bytes()
address = key_to_p2pkh(pubkey)
self.priv_keys.append(bytes_to_wif(key.get_bytes()))
return address
def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', end_address='', fee=Decimal(0.00100000)): def transaction_graph_test(self, size, n_tx_to_mine=None, start_input_txid='', end_address='', fee=Decimal(0.00100000)):
"""Create an acyclic tournament (a type of directed graph) of transactions and use it for testing. """Create an acyclic tournament (a type of directed graph) of transactions and use it for testing.
@ -38,11 +46,12 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework):
More details: https://en.wikipedia.org/wiki/Tournament_(graph_theory) More details: https://en.wikipedia.org/wiki/Tournament_(graph_theory)
""" """
self.priv_keys = [self.nodes[0].get_deterministic_priv_key().key]
if not start_input_txid: if not start_input_txid:
start_input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0] start_input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(1))['tx'][0]
if not end_address: if not end_address:
end_address = self.nodes[0].getnewaddress() end_address = self.get_new_address()
first_block_hash = '' first_block_hash = ''
tx_id = [] tx_id = []
@ -74,7 +83,7 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework):
output_value = ((inputs_value - fee) / Decimal(n_outputs)).quantize(Decimal('0.00000001')) output_value = ((inputs_value - fee) / Decimal(n_outputs)).quantize(Decimal('0.00000001'))
outputs = {} outputs = {}
for _ in range(n_outputs): for _ in range(n_outputs):
outputs[self.nodes[0].getnewaddress()] = output_value outputs[self.get_new_address()] = output_value
else: else:
output_value = (inputs_value - fee).quantize(Decimal('0.00000001')) output_value = (inputs_value - fee).quantize(Decimal('0.00000001'))
outputs = {end_address: output_value} outputs = {end_address: output_value}
@ -84,7 +93,7 @@ class MempoolUpdateFromBlockTest(BitcoinTestFramework):
# Create a new transaction. # Create a new transaction.
unsigned_raw_tx = self.nodes[0].createrawtransaction(inputs, outputs) unsigned_raw_tx = self.nodes[0].createrawtransaction(inputs, outputs)
signed_raw_tx = self.nodes[0].signrawtransactionwithwallet(unsigned_raw_tx) signed_raw_tx = self.nodes[0].signrawtransactionwithkey(unsigned_raw_tx, self.priv_keys)
tx_id.append(self.nodes[0].sendrawtransaction(signed_raw_tx['hex'])) tx_id.append(self.nodes[0].sendrawtransaction(signed_raw_tx['hex']))
tx_size.append(self.nodes[0].getmempoolentry(tx_id[-1])['vsize']) tx_size.append(self.nodes[0].getmempoolentry(tx_id[-1])['vsize'])