Skip to content

Commit ac4c79a

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#26892: test: refactor: simplify p2p_permissions.py by using MiniWallet
8cbd926 test: refactor: simplify p2p_permissions.py by using MiniWallet (Sebastian Falbesoner) Pull request description: This PR simplies the functional test p2p_permissions.py by using MiniWallet in order to avoid manual low-level tx creation. Also, rather than mining 100 blocks manually, the pre-mined chain of the test framework is used, which speeds up the test a little (~2-3 seconds faster on my machine). ACKs for top commit: MarcoFalke: ACK 8cbd926 Tree-SHA512: 36cbc2a0f6fb0251c8696cd017163ed30529690736bafd36e80b53007bd02b9030b68fe93b90dc50323526c8b7d8e0abd8f20890d46ff6015d5c632b64a08535
2 parents 53ae102 + 8cbd926 commit ac4c79a

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

test/functional/p2p_permissions.py

+6-22
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,27 @@
77
Test that permissions are correctly calculated and applied
88
"""
99

10-
from test_framework.address import ADDRESS_BCRT1_P2WSH_OP_TRUE
1110
from test_framework.messages import (
12-
CTxInWitness,
13-
tx_from_hex,
11+
SEQUENCE_FINAL,
1412
)
1513
from test_framework.p2p import P2PDataStore
16-
from test_framework.script import (
17-
CScript,
18-
OP_TRUE,
19-
)
2014
from test_framework.test_node import ErrorMatch
2115
from test_framework.test_framework import BitcoinTestFramework
2216
from test_framework.util import (
2317
assert_equal,
2418
p2p_port,
2519
)
20+
from test_framework.wallet import MiniWallet
2621

2722

2823
class P2PPermissionsTests(BitcoinTestFramework):
2924
def set_test_params(self):
3025
self.num_nodes = 2
31-
self.setup_clean_chain = True
3226

3327
def run_test(self):
28+
self.wallet = MiniWallet(self.nodes[0])
29+
self.wallet.rescan_utxos()
30+
3431
self.check_tx_relay()
3532

3633
self.checkpermission(
@@ -94,8 +91,6 @@ def run_test(self):
9491
self.nodes[1].assert_start_raises_init_error(["[email protected]", "-bind=127.0.0.1", "-listen=0"], "Cannot set -bind or -whitebind together with -listen=0", match=ErrorMatch.PARTIAL_REGEX)
9592

9693
def check_tx_relay(self):
97-
block_op_true = self.nodes[0].getblock(self.generatetoaddress(self.nodes[0], 100, ADDRESS_BCRT1_P2WSH_OP_TRUE)[0])
98-
9994
self.log.debug("Create a connection from a forcerelay peer that rebroadcasts raw txs")
10095
# A test framework p2p connection is needed to send the raw transaction directly. If a full node was used, it could only
10196
# rebroadcast via the inv-getdata mechanism. However, even for forcerelay connections, a full node would
@@ -104,18 +99,7 @@ def check_tx_relay(self):
10499
p2p_rebroadcast_wallet = self.nodes[1].add_p2p_connection(P2PDataStore())
105100

106101
self.log.debug("Send a tx from the wallet initially")
107-
tx = tx_from_hex(
108-
self.nodes[0].createrawtransaction(
109-
inputs=[{
110-
'txid': block_op_true['tx'][0],
111-
'vout': 0,
112-
}], outputs=[{
113-
ADDRESS_BCRT1_P2WSH_OP_TRUE: 5,
114-
}],
115-
replaceable=False),
116-
)
117-
tx.wit.vtxinwit = [CTxInWitness()]
118-
tx.wit.vtxinwit[0].scriptWitness.stack = [CScript([OP_TRUE])]
102+
tx = self.wallet.create_self_transfer(sequence=SEQUENCE_FINAL)['tx']
119103
txid = tx.rehash()
120104

121105
self.log.debug("Wait until tx is in node[1]'s mempool")

0 commit comments

Comments
 (0)