Skip to content

Commit eec23da

Browse files
committed
test: remove wallet dependency from feature_nulldummy.py
This test can now be run even with the Bitcoin Core wallet disabled.
1 parent 3340d46 commit eec23da

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

test/functional/feature_nulldummy.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
NORMAL_GBT_REQUEST_PARAMS,
2020
add_witness_commitment,
2121
create_block,
22-
create_transaction,
2322
)
24-
from test_framework.messages import CTransaction
23+
from test_framework.messages import (
24+
CTransaction,
25+
tx_from_hex,
26+
)
2527
from test_framework.script import (
2628
OP_0,
2729
OP_TRUE,
@@ -31,6 +33,9 @@
3133
assert_equal,
3234
assert_raises_rpc_error,
3335
)
36+
from test_framework.wallet import getnewdestination
37+
from test_framework.key import ECKey
38+
from test_framework.wallet_util import bytes_to_wif
3439

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

@@ -55,22 +60,26 @@ def set_test_params(self):
5560
'-par=1', # Use only one script thread to get the exact reject reason for testing
5661
]]
5762

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

6172
def run_test(self):
62-
self.nodes[0].createwallet(wallet_name='wmulti', disable_private_keys=True)
63-
wmulti = self.nodes[0].get_wallet_rpc('wmulti')
64-
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
65-
self.address = w0.getnewaddress()
66-
self.pubkey = w0.getaddressinfo(self.address)['pubkey']
67-
self.ms_address = wmulti.addmultisigaddress(1, [self.pubkey])['address']
68-
self.wit_address = w0.getnewaddress(address_type='p2sh-segwit')
69-
self.wit_ms_address = wmulti.addmultisigaddress(1, [self.pubkey], '', 'p2sh-segwit')['address']
70-
if not self.options.descriptors:
71-
# 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
72-
wmulti.importaddress(self.ms_address)
73-
wmulti.importaddress(self.wit_ms_address)
73+
eckey = ECKey()
74+
eckey.generate()
75+
self.privkey = bytes_to_wif(eckey.get_bytes())
76+
self.pubkey = eckey.get_pubkey().get_bytes().hex()
77+
cms = self.nodes[0].createmultisig(1, [self.pubkey])
78+
wms = self.nodes[0].createmultisig(1, [self.pubkey], 'p2sh-segwit')
79+
self.ms_address = cms["address"]
80+
ms_unlock_details = {"scriptPubKey": self.nodes[0].validateaddress(self.ms_address)["scriptPubKey"],
81+
"redeemScript": cms["redeemScript"]}
82+
self.wit_ms_address = wms['address']
7483

7584
self.coinbase_blocks = self.generate(self.nodes[0], 2) # block height = 2
7685
coinbase_txid = []
@@ -82,31 +91,43 @@ def run_test(self):
8291
self.lastblocktime = int(time.time()) + self.lastblockheight
8392

8493
self.log.info(f"Test 1: NULLDUMMY compliant base transactions should be accepted to mempool and mined before activation [{COINBASE_MATURITY + 3}]")
85-
test1txs = [create_transaction(self.nodes[0], coinbase_txid[0], self.ms_address, amount=49)]
94+
test1txs = [self.create_transaction(txid=coinbase_txid[0], addr=self.ms_address, amount=49,
95+
privkey=self.nodes[0].get_deterministic_priv_key().key)]
8696
txid1 = self.nodes[0].sendrawtransaction(test1txs[0].serialize_with_witness().hex(), 0)
87-
test1txs.append(create_transaction(self.nodes[0], txid1, self.ms_address, amount=48))
97+
test1txs.append(self.create_transaction(txid=txid1, input_details=ms_unlock_details,
98+
addr=self.ms_address, amount=48,
99+
privkey=self.privkey))
88100
txid2 = self.nodes[0].sendrawtransaction(test1txs[1].serialize_with_witness().hex(), 0)
89-
test1txs.append(create_transaction(self.nodes[0], coinbase_txid[1], self.wit_ms_address, amount=49))
101+
test1txs.append(self.create_transaction(txid=coinbase_txid[1],
102+
addr=self.wit_ms_address, amount=49,
103+
privkey=self.nodes[0].get_deterministic_priv_key().key))
90104
txid3 = self.nodes[0].sendrawtransaction(test1txs[2].serialize_with_witness().hex(), 0)
91105
self.block_submit(self.nodes[0], test1txs, accept=True)
92106

93107
self.log.info("Test 2: Non-NULLDUMMY base multisig transaction should not be accepted to mempool before activation")
94-
test2tx = create_transaction(self.nodes[0], txid2, self.ms_address, amount=47)
108+
test2tx = self.create_transaction(txid=txid2, input_details=ms_unlock_details,
109+
addr=self.ms_address, amount=47,
110+
privkey=self.privkey)
95111
invalidate_nulldummy_tx(test2tx)
96112
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test2tx.serialize_with_witness().hex(), 0)
97113

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

101117
self.log.info("Test 4: Non-NULLDUMMY base multisig transaction is invalid after activation")
102-
test4tx = create_transaction(self.nodes[0], test2tx.hash, self.address, amount=46)
118+
test4tx = self.create_transaction(txid=test2tx.hash, input_details=ms_unlock_details,
119+
addr=getnewdestination()[2], amount=46,
120+
privkey=self.privkey)
103121
test6txs = [CTransaction(test4tx)]
104122
invalidate_nulldummy_tx(test4tx)
105123
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test4tx.serialize_with_witness().hex(), 0)
106124
self.block_submit(self.nodes[0], [test4tx], accept=False)
107125

108126
self.log.info("Test 5: Non-NULLDUMMY P2WSH multisig transaction invalid after activation")
109-
test5tx = create_transaction(self.nodes[0], txid3, self.wit_address, amount=48)
127+
test5tx = self.create_transaction(txid=txid3, input_details={"scriptPubKey": test1txs[2].vout[0].scriptPubKey.hex(),
128+
"amount": 49, "witnessScript": wms["redeemScript"]},
129+
addr=getnewdestination(address_type='p2sh-segwit')[2], amount=48,
130+
privkey=self.privkey)
110131
test6txs.append(CTransaction(test5tx))
111132
test5tx.wit.vtxinwit[0].scriptWitness.stack[0] = b'\x01'
112133
assert_raises_rpc_error(-26, NULLDUMMY_ERROR, self.nodes[0].sendrawtransaction, test5tx.serialize_with_witness().hex(), 0)

test/functional/test_runner.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,7 @@
244244
'rpc_generate.py',
245245
'wallet_balance.py --legacy-wallet',
246246
'wallet_balance.py --descriptors',
247-
'feature_nulldummy.py --legacy-wallet',
248-
'feature_nulldummy.py --descriptors',
247+
'feature_nulldummy.py',
249248
'mempool_accept.py',
250249
'mempool_expiry.py',
251250
'wallet_import_rescan.py --legacy-wallet',

0 commit comments

Comments
 (0)