Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_tx.py
Show All 14 Lines | |||||
from test_framework.txtools import pad_tx | from test_framework.txtools import pad_tx | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COIN, | COIN, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
) | ) | ||||
from test_framework.mininode import network_thread_start, P2PDataStore, network_thread_join | from test_framework.mininode import P2PDataStore | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
class InvalidTxRequestTest(BitcoinTestFramework): | class InvalidTxRequestTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
def bootstrap_p2p(self, *, num_connections=1): | def bootstrap_p2p(self, *, num_connections=1): | ||||
"""Add a P2P connection to the node. | """Add a P2P connection to the node. | ||||
Helper to connect and wait for version handshake.""" | Helper to connect and wait for version handshake.""" | ||||
for _ in range(num_connections): | for _ in range(num_connections): | ||||
self.nodes[0].add_p2p_connection(P2PDataStore()) | self.nodes[0].add_p2p_connection(P2PDataStore()) | ||||
network_thread_start() | |||||
self.nodes[0].p2p.wait_for_verack() | self.nodes[0].p2p.wait_for_verack() | ||||
def reconnect_p2p(self, **kwargs): | def reconnect_p2p(self, **kwargs): | ||||
"""Tear down and bootstrap the P2P connection to the node. | """Tear down and bootstrap the P2P connection to the node. | ||||
The node gets disconnected several times in this test. This helper | The node gets disconnected several times in this test. This helper | ||||
method reconnects the p2p and restarts the network thread.""" | method reconnects the p2p and restarts the network thread.""" | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
network_thread_join() | |||||
self.bootstrap_p2p(**kwargs) | self.bootstrap_p2p(**kwargs) | ||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] # convenience reference to the node | node = self.nodes[0] # convenience reference to the node | ||||
self.bootstrap_p2p() # Add one p2p connection to the node | self.bootstrap_p2p() # Add one p2p connection to the node | ||||
best_block = self.nodes[0].getbestblockhash() | best_block = self.nodes[0].getbestblockhash() | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |