Skip to content

Commit 22effa5

Browse files
fjahrjnewbery
authored andcommitted
test: Use wtxid relay generally in functional tests
1 parent e481681 commit 22effa5

File tree

7 files changed

+31
-16
lines changed

7 files changed

+31
-16
lines changed

test/functional/mempool_packages.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ def run_test(self):
6767
fee = Decimal("0.0001")
6868
# MAX_ANCESTORS transactions off a confirmed tx should be fine
6969
chain = []
70+
witness_chain = []
7071
for i in range(MAX_ANCESTORS):
7172
(txid, sent_value) = self.chain_transaction(self.nodes[0], txid, 0, value, fee, 1)
7273
value = sent_value
7374
chain.append(txid)
75+
# We need the wtxids to check P2P announcements
76+
fulltx = self.nodes[0].getrawtransaction(txid)
77+
witnesstx = self.nodes[0].decoderawtransaction(fulltx, True)
78+
witness_chain.append(witnesstx['hash'])
7479

7580
# Check mempool has MAX_ANCESTORS transactions in it, and descendant and ancestor
7681
# 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_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

@@ -31,7 +31,7 @@ def __init__(self):
3131

3232
def on_inv(self, message):
3333
for i in message.inv:
34-
if (i.type == 1):
34+
if (i.type == MSG_TX) or (i.type == MSG_WTX):
3535
self.txinvs.append(hashToHex(i.hash))
3636

3737
def clear_invs(self):

test/functional/p2p_segwit.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
msg_tx,
3535
msg_block,
3636
msg_no_witness_tx,
37-
msg_wtxidrelay,
37+
msg_verack,
3838
ser_uint256,
3939
ser_vector,
4040
sha256,
@@ -159,8 +159,10 @@ def on_inv(self, message):
159159

160160
def on_version(self, message):
161161
if self.wtxidrelay:
162-
self.send_message(msg_wtxidrelay())
163-
super().on_version(message)
162+
super().on_version(message)
163+
else:
164+
self.send_message(msg_verack())
165+
self.nServices = message.nServices
164166

165167
def on_getdata(self, message):
166168
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=1, 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=1, 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=1, 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
@@ -363,6 +363,8 @@ def on_verack(self, message):
363363

364364
def on_version(self, message):
365365
assert message.nVersion >= MIN_VERSION_SUPPORTED, "Version {} received. Test framework only supports versions greater than {}".format(message.nVersion, MIN_VERSION_SUPPORTED)
366+
if message.nVersion >= 70016:
367+
self.send_message(msg_wtxidrelay())
366368
self.send_message(msg_verack())
367369
self.nServices = message.nServices
368370

test/functional/wallet_resendwallettransactions.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import time
88

99
from test_framework.blocktools import create_block, create_coinbase
10-
from test_framework.messages import ToHex
10+
from test_framework.messages import (
11+
MSG_TX,
12+
MSG_WTX,
13+
ToHex,
14+
)
1115
from test_framework.mininode import P2PInterface, mininode_lock
1216
from test_framework.test_framework import BitcoinTestFramework
1317
from test_framework.util import assert_equal, wait_until
@@ -21,7 +25,7 @@ def __init__(self):
2125
def on_inv(self, message):
2226
# Store how many times invs have been received for each tx.
2327
for i in message.inv:
24-
if i.type == 1:
28+
if i.type == MSG_TX or i.type == MSG_WTX:
2529
# save txid
2630
self.tx_invs_received[i.hash] += 1
2731

@@ -39,7 +43,8 @@ def run_test(self):
3943
node.add_p2p_connection(P2PStoreTxInvs())
4044

4145
self.log.info("Create a new transaction and wait until it's broadcast")
42-
txid = int(node.sendtoaddress(node.getnewaddress(), 1), 16)
46+
txid = node.sendtoaddress(node.getnewaddress(), 1)
47+
wtxid = int(node.getrawtransaction(txid, 1)['hash'], 16)
4348

4449
# Wallet rebroadcast is first scheduled 1 sec after startup (see
4550
# nNextResend in ResendWalletTransactions()). Sleep for just over a
@@ -48,7 +53,7 @@ def run_test(self):
4853
time.sleep(1.1)
4954

5055
# Can take a few seconds due to transaction trickling
51-
wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1, lock=mininode_lock)
56+
wait_until(lambda: node.p2p.tx_invs_received[wtxid] >= 1, lock=mininode_lock)
5257

5358
# Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown)
5459
node.add_p2p_connection(P2PStoreTxInvs())
@@ -67,13 +72,13 @@ def run_test(self):
6772
# Transaction should not be rebroadcast
6873
node.syncwithvalidationinterfacequeue()
6974
node.p2ps[1].sync_with_ping()
70-
assert_equal(node.p2ps[1].tx_invs_received[txid], 0)
75+
assert_equal(node.p2ps[1].tx_invs_received[wtxid], 0)
7176

7277
self.log.info("Transaction should be rebroadcast after 30 minutes")
7378
# Use mocktime and give an extra 5 minutes to be sure.
7479
rebroadcast_time = int(time.time()) + 41 * 60
7580
node.setmocktime(rebroadcast_time)
76-
wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1, lock=mininode_lock)
81+
wait_until(lambda: node.p2ps[1].tx_invs_received[wtxid] >= 1, lock=mininode_lock)
7782

7883

7984
if __name__ == '__main__':

0 commit comments

Comments
 (0)