Skip to content

Commit 8d3743a

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24896: test: use MiniWallet for p2p_segwit.py
917a89a test: use MiniWallet for p2p_segwit.py (Sebastian Falbesoner) Pull request description: This PR enables one more of the non-wallet functional tests (p2p_segwit.py) to be run even with the Bitcoin Code wallet by using the MiniWallet instead, as proposed in bitcoin/bitcoin#20078. This change only affects the subtest `test_superfluous_witness`. Note that instead of creating a raw transaction first and then signing it, we go the other direction here: MiniWallet creates a transaction spending a segwit v1 output (i.e. including a witness), then we turn it into a raw transaction by dropping the witness. Therefore, the debug log asserts are swapped. Top commit has no ACKs. Tree-SHA512: 163a93a527f60100487f0aff49a9d7baf392ceb4417c54521157b2678685f5728dd751a9747c6cf51666aae78252dd3bc44130e659f7a1262ec1c86e30225622
2 parents b297b94 + 917a89a commit 8d3743a

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

test/functional/p2p_segwit.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
ser_uint256,
4444
ser_vector,
4545
sha256,
46-
tx_from_hex,
4746
)
4847
from test_framework.p2p import (
4948
P2PInterface,
@@ -89,6 +88,8 @@
8988
softfork_active,
9089
assert_raises_rpc_error,
9190
)
91+
from test_framework.wallet import MiniWallet
92+
9293

9394
MAX_SIGOP_COST = 80000
9495

@@ -221,9 +222,6 @@ def set_test_params(self):
221222
]
222223
self.supports_cli = False
223224

224-
def skip_test_if_missing_module(self):
225-
self.skip_if_no_wallet()
226-
227225
# Helper functions
228226

229227
def build_next_block(self):
@@ -259,6 +257,7 @@ def run_test(self):
259257

260258
self.log.info("Starting tests before segwit activation")
261259
self.segwit_active = False
260+
self.wallet = MiniWallet(self.nodes[0])
262261

263262
self.test_non_witness_transaction()
264263
self.test_v0_outputs_arent_spendable()
@@ -307,7 +306,7 @@ def test_non_witness_transaction(self):
307306
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
308307
txid = block.vtx[0].sha256
309308

310-
self.generate(self.nodes[0], 99) # let the block mature
309+
self.generate(self.wallet, 99) # let the block mature
311310

312311
# Create a transaction that spends the coinbase
313312
tx = CTransaction()
@@ -1999,21 +1998,13 @@ class msg_bogus_tx(msg_tx):
19991998
def serialize(self):
20001999
return serialize_with_bogus_witness(self.tx)
20012000

2002-
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(address_type='bech32'), 5)
2003-
self.generate(self.nodes[0], 1)
2004-
unspent = next(u for u in self.nodes[0].listunspent() if u['spendable'] and u['address'].startswith('bcrt'))
2005-
2006-
raw = self.nodes[0].createrawtransaction([{"txid": unspent['txid'], "vout": unspent['vout']}], {self.nodes[0].getnewaddress(): 1})
2007-
tx = tx_from_hex(raw)
2001+
tx = self.wallet.create_self_transfer(from_node=self.nodes[0])['tx']
20082002
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
2009-
with self.nodes[0].assert_debug_log(['Superfluous witness record']):
2003+
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
20102004
self.test_node.send_and_ping(msg_bogus_tx(tx))
2011-
raw = self.nodes[0].signrawtransactionwithwallet(raw)
2012-
assert raw['complete']
2013-
raw = raw['hex']
2014-
tx = tx_from_hex(raw)
2005+
tx.wit.vtxinwit = [] # drop witness
20152006
assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)
2016-
with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):
2007+
with self.nodes[0].assert_debug_log(['Superfluous witness record']):
20172008
self.test_node.send_and_ping(msg_bogus_tx(tx))
20182009

20192010
@subtest

0 commit comments

Comments
 (0)