Skip to content

Commit dca7394

Browse files
committed
scripted-diff: rename node to peer for mininodes
-BEGIN VERIFY SCRIPT- sed -i 's/FilterNode/P2PBloomFilter/g' test/functional/p2p_filter.py; sed -i 's/filter_node/filter_peer/g' test/functional/p2p_filter.py; -END VERIFY SCRIPT-
1 parent 0474ea2 commit dca7394

File tree

1 file changed

+41
-41
lines changed

1 file changed

+41
-41
lines changed

test/functional/p2p_filter.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from test_framework.test_framework import BitcoinTestFramework
2525

2626

27-
class FilterNode(P2PInterface):
27+
class P2PBloomFilter(P2PInterface):
2828
# This is a P2SH watch-only wallet
2929
watch_script_pubkey = 'a914ffffffffffffffffffffffffffffffffffffffff87'
3030
# The initial filter (n=10, fp=0.000001) with just the above scriptPubKey added
@@ -91,38 +91,38 @@ def set_test_params(self):
9191
def skip_test_if_missing_module(self):
9292
self.skip_if_no_wallet()
9393

94-
def test_size_limits(self, filter_node):
94+
def test_size_limits(self, filter_peer):
9595
self.log.info('Check that too large filter is rejected')
9696
with self.nodes[0].assert_debug_log(['Misbehaving']):
97-
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE+1)))
97+
filter_peer.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE+1)))
9898

9999
self.log.info('Check that max size filter is accepted')
100100
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
101-
filter_node.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE)))
102-
filter_node.send_and_ping(msg_filterclear())
101+
filter_peer.send_and_ping(msg_filterload(data=b'\xbb'*(MAX_BLOOM_FILTER_SIZE)))
102+
filter_peer.send_and_ping(msg_filterclear())
103103

104104
self.log.info('Check that filter with too many hash functions is rejected')
105105
with self.nodes[0].assert_debug_log(['Misbehaving']):
106-
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
106+
filter_peer.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS+1))
107107

108108
self.log.info('Check that filter with max hash functions is accepted')
109109
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
110-
filter_node.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS))
110+
filter_peer.send_and_ping(msg_filterload(data=b'\xaa', nHashFuncs=MAX_BLOOM_HASH_FUNCS))
111111
# Don't send filterclear until next two filteradd checks are done
112112

113113
self.log.info('Check that max size data element to add to the filter is accepted')
114114
with self.nodes[0].assert_debug_log([], unexpected_msgs=['Misbehaving']):
115-
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE)))
115+
filter_peer.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE)))
116116

117117
self.log.info('Check that too large data element to add to the filter is rejected')
118118
with self.nodes[0].assert_debug_log(['Misbehaving']):
119-
filter_node.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE+1)))
119+
filter_peer.send_and_ping(msg_filteradd(data=b'\xcc'*(MAX_SCRIPT_ELEMENT_SIZE+1)))
120120

121-
filter_node.send_and_ping(msg_filterclear())
121+
filter_peer.send_and_ping(msg_filterclear())
122122

123123
def test_msg_mempool(self):
124124
self.log.info("Check that a node with bloom filters enabled services p2p mempool messages")
125-
filter_peer = FilterNode()
125+
filter_peer = P2PBloomFilter()
126126

127127
self.log.info("Create a tx relevant to the peer before connecting")
128128
filter_address = self.nodes[0].decodescript(filter_peer.watch_script_pubkey)['addresses'][0]
@@ -146,67 +146,67 @@ def test_frelay_false(self, filter_peer):
146146
# Clear the mempool so that this transaction does not impact subsequent tests
147147
self.nodes[0].generate(1)
148148

149-
def test_filter(self, filter_node):
149+
def test_filter(self, filter_peer):
150150
# Set the bloomfilter using filterload
151-
filter_node.send_and_ping(filter_node.watch_filter_init)
151+
filter_peer.send_and_ping(filter_peer.watch_filter_init)
152152
# If fRelay is not already True, sending filterload sets it to True
153153
assert self.nodes[0].getpeerinfo()[0]['relaytxes']
154-
filter_address = self.nodes[0].decodescript(filter_node.watch_script_pubkey)['addresses'][0]
154+
filter_address = self.nodes[0].decodescript(filter_peer.watch_script_pubkey)['addresses'][0]
155155

156156
self.log.info('Check that we receive merkleblock and tx if the filter matches a tx in a block')
157157
block_hash = self.nodes[0].generatetoaddress(1, filter_address)[0]
158158
txid = self.nodes[0].getblock(block_hash)['tx'][0]
159-
filter_node.wait_for_merkleblock(block_hash)
160-
filter_node.wait_for_tx(txid)
159+
filter_peer.wait_for_merkleblock(block_hash)
160+
filter_peer.wait_for_tx(txid)
161161

162162
self.log.info('Check that we only receive a merkleblock if the filter does not match a tx in a block')
163-
filter_node.tx_received = False
163+
filter_peer.tx_received = False
164164
block_hash = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
165-
filter_node.wait_for_merkleblock(block_hash)
166-
assert not filter_node.tx_received
165+
filter_peer.wait_for_merkleblock(block_hash)
166+
assert not filter_peer.tx_received
167167

168168
self.log.info('Check that we not receive a tx if the filter does not match a mempool tx')
169-
filter_node.merkleblock_received = False
170-
filter_node.tx_received = False
169+
filter_peer.merkleblock_received = False
170+
filter_peer.tx_received = False
171171
self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 90)
172-
filter_node.sync_with_ping()
173-
filter_node.sync_with_ping()
174-
assert not filter_node.merkleblock_received
175-
assert not filter_node.tx_received
172+
filter_peer.sync_with_ping()
173+
filter_peer.sync_with_ping()
174+
assert not filter_peer.merkleblock_received
175+
assert not filter_peer.tx_received
176176

177177
self.log.info('Check that we receive a tx if the filter matches a mempool tx')
178-
filter_node.merkleblock_received = False
178+
filter_peer.merkleblock_received = False
179179
txid = self.nodes[0].sendtoaddress(filter_address, 90)
180-
filter_node.wait_for_tx(txid)
181-
assert not filter_node.merkleblock_received
180+
filter_peer.wait_for_tx(txid)
181+
assert not filter_peer.merkleblock_received
182182

183183
self.log.info('Check that after deleting filter all txs get relayed again')
184-
filter_node.send_and_ping(msg_filterclear())
184+
filter_peer.send_and_ping(msg_filterclear())
185185
for _ in range(5):
186186
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 7)
187-
filter_node.wait_for_tx(txid)
187+
filter_peer.wait_for_tx(txid)
188188

189189
self.log.info('Check that request for filtered blocks is ignored if no filter is set')
190-
filter_node.merkleblock_received = False
191-
filter_node.tx_received = False
190+
filter_peer.merkleblock_received = False
191+
filter_peer.tx_received = False
192192
with self.nodes[0].assert_debug_log(expected_msgs=['received getdata']):
193193
block_hash = self.nodes[0].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
194-
filter_node.wait_for_inv([CInv(MSG_BLOCK, int(block_hash, 16))])
195-
filter_node.sync_with_ping()
196-
assert not filter_node.merkleblock_received
197-
assert not filter_node.tx_received
194+
filter_peer.wait_for_inv([CInv(MSG_BLOCK, int(block_hash, 16))])
195+
filter_peer.sync_with_ping()
196+
assert not filter_peer.merkleblock_received
197+
assert not filter_peer.tx_received
198198

199199
self.log.info('Check that sending "filteradd" if no filter is set is treated as misbehavior')
200200
with self.nodes[0].assert_debug_log(['Misbehaving']):
201-
filter_node.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
201+
filter_peer.send_and_ping(msg_filteradd(data=b'letsmisbehave'))
202202

203203
self.log.info("Check that division-by-zero remote crash bug [CVE-2013-5700] is fixed")
204-
filter_node.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
205-
filter_node.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
204+
filter_peer.send_and_ping(msg_filterload(data=b'', nHashFuncs=1))
205+
filter_peer.send_and_ping(msg_filteradd(data=b'letstrytocrashthisnode'))
206206
self.nodes[0].disconnect_p2ps()
207207

208208
def run_test(self):
209-
filter_peer = self.nodes[0].add_p2p_connection(FilterNode())
209+
filter_peer = self.nodes[0].add_p2p_connection(P2PBloomFilter())
210210
self.log.info('Test filter size limits')
211211
self.test_size_limits(filter_peer)
212212

@@ -216,7 +216,7 @@ def run_test(self):
216216

217217
self.log.info('Test BIP 37 for a node with fRelay = False')
218218
# Add peer but do not send version yet
219-
filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(FilterNode(), send_version=False, wait_for_verack=False)
219+
filter_peer_without_nrelay = self.nodes[0].add_p2p_connection(P2PBloomFilter(), send_version=False, wait_for_verack=False)
220220
# Send version with fRelay=False
221221
filter_peer_without_nrelay.wait_until(lambda: filter_peer_without_nrelay.is_connected, timeout=10)
222222
version_without_fRelay = msg_version()

0 commit comments

Comments
 (0)