Skip to content

Commit cacd852

Browse files
fjahrsdaftuar
authored andcommitted
test: Use wtxid relay generally in functional tests
1 parent 8d8099e commit cacd852

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

test/functional/mempool_packages.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ def run_test(self):
6969
fee = Decimal("0.0001")
7070
# MAX_ANCESTORS transactions off a confirmed tx should be fine
7171
chain = []
72+
witness_chain = []
7273
for i in range(MAX_ANCESTORS):
7374
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, 0, value, fee, 1)
7475
value = sent_value
7576
chain.append(txid)
77+
# We need the wtxids to check P2P announcements
78+
fulltx = self.nodes[0].getrawtransaction(txid)
79+
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
80+
witness_chain.append(witnesstx['hash'])
7681

7782
# Wait until mempool transactions have passed initial broadcast (sent inv and received getdata)
7883
# Otherwise, getrawmempool may be inconsistent with getmempoolentry if unbroadcast changes in between
79-
self.nodes[0].p2p.wait_for_broadcast(chain)
84+
self.nodes[0].p2p.wait_for_broadcast(witness_chain)
8085

8186
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
8287
# count and fees should look correct

test/functional/p2p_blocksonly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def run_test(self):
5252
self.log.info('Check that txs from rpc are not rejected and relayed to other peers')
5353
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True)
5454
txid = self.nodes[0].testmempoolaccept([sigtx])[0]['txid']
55-
with self.nodes[0].assert_debug_log(['received getdata for: tx {} peer=1'.format(txid)]):
55+
with self.nodes[0].assert_debug_log(['received getdata for: wtx {} peer=1'.format(txid)]):
5656
self.nodes[0].sendrawtransaction(sigtx)
5757
self.nodes[0].p2p.wait_for_tx(txid)
5858
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)

test/functional/p2p_feefilter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from decimal import Decimal
88
import time
99

10-
from test_framework.messages import MSG_TX, msg_feefilter
10+
from test_framework.messages import MSG_TX, MSG_WTX, msg_feefilter
1111
from test_framework.mininode import mininode_lock, P2PInterface
1212
from test_framework.test_framework import BitcoinTestFramework
1313
from test_framework.util import assert_equal
@@ -45,7 +45,7 @@ def __init__(self):
4545

4646
def on_inv(self, message):
4747
for i in message.inv:
48-
if (i.type == MSG_TX):
48+
if (i.type == MSG_TX) or (i.type == MSG_WTX):
4949
self.txinvs.append(hashToHex(i.hash))
5050

5151
def clear_invs(self):

test/functional/p2p_segwit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
msg_block,
3737
msg_no_witness_tx,
3838
msg_verack,
39-
msg_wtxidrelay,
4039
ser_uint256,
4140
ser_vector,
4241
sha256,
@@ -161,8 +160,10 @@ def on_inv(self, message):
161160

162161
def on_version(self, message):
163162
if self.wtxidrelay:
164-
self.send_message(msg_wtxidrelay())
165-
super().on_version(message)
163+
super().on_version(message)
164+
else:
165+
self.send_message(msg_verack())
166+
self.nServices = message.nServices
166167

167168
def on_getdata(self, message):
168169
self.lastgetdata = message.inv

test/functional/p2p_tx_download.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
FromHex,
1313
MSG_TX,
1414
MSG_TYPE_MASK,
15+
MSG_WTX,
1516
msg_inv,
1617
msg_notfound,
1718
)
@@ -36,7 +37,7 @@ def __init__(self):
3637

3738
def on_getdata(self, message):
3839
for i in message.inv:
39-
if i.type & MSG_TYPE_MASK == MSG_TX:
40+
if i.type & MSG_TYPE_MASK == MSG_TX or i.type & MSG_TYPE_MASK == MSG_WTX:
4041
self.tx_getdata_count += 1
4142

4243

@@ -64,7 +65,7 @@ def test_tx_requests(self):
6465
txid = 0xdeadbeef
6566

6667
self.log.info("Announce the txid from each incoming peer to node 0")
67-
msg = msg_inv([CInv(t=MSG_TX, h=txid)])
68+
msg = msg_inv([CInv(t=MSG_WTX, h=txid)])
6869
for p in self.nodes[0].p2ps:
6970
p.send_and_ping(msg)
7071

@@ -136,13 +137,13 @@ def test_in_flight_max(self):
136137
with mininode_lock:
137138
p.tx_getdata_count = 0
138139

139-
p.send_message(msg_inv([CInv(t=MSG_TX, h=i) for i in txids]))
140+
p.send_message(msg_inv([CInv(t=MSG_WTX, h=i) for i in txids]))
140141
wait_until(lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT, lock=mininode_lock)
141142
with mininode_lock:
142143
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT)
143144

144145
self.log.info("Now check that if we send a NOTFOUND for a transaction, we'll get one more request")
145-
p.send_message(msg_notfound(vec=[CInv(t=MSG_TX, h=txids[0])]))
146+
p.send_message(msg_notfound(vec=[CInv(t=MSG_WTX, h=txids[0])]))
146147
wait_until(lambda: p.tx_getdata_count >= MAX_GETDATA_IN_FLIGHT + 1, timeout=10, lock=mininode_lock)
147148
with mininode_lock:
148149
assert_equal(p.tx_getdata_count, MAX_GETDATA_IN_FLIGHT + 1)

test/functional/test_framework/mininode.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ def on_verack(self, message):
377377

378378
def on_version(self, message):
379379
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)
380+
if message.nVersion >= 70016:
381+
self.send_message(msg_wtxidrelay())
380382
self.send_message(msg_verack())
381383
self.nServices = message.nServices
382384

0 commit comments

Comments
 (0)