Skip to content

Commit c24c9ea

Browse files
committed
merge bitcoin#25364: remove wallet dependency from feature_nulldummy.py
1 parent a118fe1 commit c24c9ea

File tree

3 files changed

+36
-46
lines changed

3 files changed

+36
-46
lines changed

test/functional/feature_nulldummy.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
COINBASE_MATURITY,
1818
NORMAL_GBT_REQUEST_PARAMS,
1919
create_block,
20-
create_transaction,
2120
)
22-
from test_framework.messages import CTransaction
21+
from test_framework.messages import (
22+
CTransaction,
23+
tx_from_hex,
24+
)
2325
from test_framework.script import (
2426
OP_0,
2527
OP_TRUE,
@@ -29,6 +31,9 @@
2931
assert_equal,
3032
assert_raises_rpc_error,
3133
)
34+
from test_framework.wallet import getnewdestination
35+
from test_framework.key import ECKey
36+
from test_framework.wallet_util import bytes_to_wif
3237

3338
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
3439

@@ -52,19 +57,24 @@ def set_test_params(self):
5257
'-par=1', # Use only one script thread to get the exact reject reason for testing
5358
]]
5459

55-
def skip_test_if_missing_module(self):
56-
self.skip_if_no_wallet()
60+
def create_transaction(self, *, txid, input_details=None, addr, amount, privkey):
61+
input = {"txid": txid, "vout": 0}
62+
output = {addr: amount}
63+
rawtx = self.nodes[0].createrawtransaction([input], output)
64+
# Details only needed for scripthash or witness spends
65+
input = None if not input_details else [{**input, **input_details}]
66+
signedtx = self.nodes[0].signrawtransactionwithkey(rawtx, [privkey], input)
67+
return tx_from_hex(signedtx["hex"])
5768

5869
def run_test(self):
59-
self.nodes[0].createwallet(wallet_name='wmulti', disable_private_keys=True)
60-
wmulti = self.nodes[0].get_wallet_rpc('wmulti')
61-
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
62-
self.address = w0.getnewaddress()
63-
self.pubkey = w0.getaddressinfo(self.address)['pubkey']
64-
self.ms_address = wmulti.addmultisigaddress(1, [self.pubkey])['address']
65-
if not self.options.descriptors:
66-
# Legacy wallets need to import these so that they are watched by the wallet. This is unnecessary (and does not need to be tested) for descriptor wallets
67-
wmulti.importaddress(self.ms_address)
70+
eckey = ECKey()
71+
eckey.generate()
72+
self.privkey = bytes_to_wif(eckey.get_bytes())
73+
self.pubkey = eckey.get_pubkey().get_bytes().hex()
74+
cms = self.nodes[0].createmultisig(1, [self.pubkey])
75+
self.ms_address = cms["address"]
76+
ms_unlock_details = {"scriptPubKey": self.nodes[0].validateaddress(self.ms_address)["scriptPubKey"],
77+
"redeemScript": cms["redeemScript"]}
6878

6979
self.coinbase_blocks = self.generate(self.nodes[0], 2) # block height = 2
7080
coinbase_txid = []
@@ -76,23 +86,30 @@ def run_test(self):
7686
self.lastblocktime = self.mocktime + self.lastblockheight
7787

7888
self.log.info(f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{COINBASE_MATURITY + 3}]")
79-
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
89+
test1txs = [self.create_transaction(txid=coinbase_txid[0], addr=self.ms_address, amount=49,
90+
privkey=self.nodes[0].get_deterministic_priv_key().key)]
8091
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize().hex(), 0)
81-
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
92+
test1txs.append(self.create_transaction(txid=txid1, input_details=ms_unlock_details,
93+
addr=self.ms_address, amount=48,
94+
privkey=self.privkey))
8295
txid2 = self.nodes[0].sendrawtransaction(test1txs[1].serialize().hex(), 0)
8396
self.block_submit(self.nodes[0], test1txs, accept=True)
8497

8598
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
86-
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=47)
99+
test2tx = self.create_transaction(txid=txid2, input_details=ms_unlock_details,
100+
addr=self.ms_address, amount=47,
101+
privkey=self.privkey)
87102
invalidate_nulldummy_tx(test2tx)
88103
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize().hex(), 0)
89104

90105
self.log.info(f"Test 3: Non-NULLDUMMY base transactions should be accepted in a block before activation [{COINBASE_MATURITY + 4}]")
91106
self.block_submit(self.nodes[0], [test2tx], accept=True)
92107

93108
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
94-
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=46)
95-
test6txs=[CTransaction(test4tx)]
109+
test4tx = self.create_transaction(txid=test2tx.hash, input_details=ms_unlock_details,
110+
addr=getnewdestination()[2], amount=46,
111+
privkey=self.privkey)
112+
test6txs = [CTransaction(test4tx)]
96113
invalidate_nulldummy_tx(test4tx)
97114
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize().hex(), 0)
98115
self.block_submit(self.nodes[0], [test4tx], accept=False)

test/functional/test_framework/blocktools.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
key_to_p2pk_script,
3434
)
3535
from .util import assert_equal
36-
from io import BytesIO
3736

3837
MAX_BLOCK_SIGOPS = 40000
3938

@@ -214,31 +213,6 @@ def create_tx_with_script(prevtx, n, script_sig=b"", *, amount, script_pub_key=C
214213
tx.calc_sha256()
215214
return tx
216215

217-
def create_transaction(node, txid, to_address, *, amount):
218-
""" Return signed transaction spending the first output of the
219-
input txid. Note that the node must have a wallet that can
220-
sign for the output that is being spent.
221-
"""
222-
raw_tx = create_raw_transaction(node, txid, to_address, amount=amount)
223-
tx = CTransaction()
224-
tx.deserialize(BytesIO(bytes.fromhex(raw_tx)))
225-
return tx
226-
227-
def create_raw_transaction(node, txid, to_address, *, amount):
228-
""" Return raw signed transaction spending the first output of the
229-
input txid. Note that the node must have a wallet that can sign
230-
for the output that is being spent.
231-
"""
232-
psbt = node.createpsbt(inputs=[{"txid": txid, "vout": 0}], outputs={to_address: amount})
233-
for _ in range(2):
234-
for w in node.listwallets():
235-
wrpc = node.get_wallet_rpc(w)
236-
signed_psbt = wrpc.walletprocesspsbt(psbt)
237-
psbt = signed_psbt['psbt']
238-
final_psbt = node.finalizepsbt(psbt)
239-
assert_equal(final_psbt["complete"], True)
240-
return final_psbt['hex']
241-
242216
def get_legacy_sigopcount_block(block, accurate=True):
243217
count = 0
244218
for tx in block.vtx:

test/functional/test_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@
289289
'wallet_balance.py --legacy-wallet',
290290
'wallet_balance.py --descriptors',
291291
'p2p_initial_headers_sync.py',
292-
'feature_nulldummy.py --legacy-wallet',
293-
'feature_nulldummy.py --descriptors',
292+
'feature_nulldummy.py',
294293
'mempool_accept.py',
295294
'mempool_expiry.py',
296295
'wallet_import_rescan.py --legacy-wallet',

0 commit comments

Comments
 (0)