aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p-acceptblock.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2017-05-02 19:10:23 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2017-05-02 19:11:55 +0200
commit8f3e38477e30abd9dd0e24a4d612126117f7793c (patch)
tree9ed06f54580ac45fda4a0770cf974f28e2e3f77b /test/functional/p2p-acceptblock.py
parent2580ff81f4422e9c2c844bc06f9dc96fd8e4b201 (diff)
parent2a52ae63bfdde948250df1c876dcdd5af99f03b5 (diff)
downloadbitcoin-8f3e38477e30abd9dd0e24a4d612126117f7793c.tar.xz
Merge #10169: [tests] Remove func test code duplication
2a52ae6 Remove duplicate method definitions in NodeConnCB subclasses (John Newbery) 52e15aa Adds helper functions to NodeConnCB (John Newbery) Tree-SHA512: 2d7909eb85b3bde0fc3ebf133798eca21e561f4b2a2880937750820a42856cfb61fc94e30591c14ac13218bcfae0ebe7c5e8662a7b10f5b02470325c44a86cf1
Diffstat (limited to 'test/functional/p2p-acceptblock.py')
-rwxr-xr-xtest/functional/p2p-acceptblock.py42
1 files changed, 4 insertions, 38 deletions
diff --git a/test/functional/p2p-acceptblock.py b/test/functional/p2p-acceptblock.py
index c09945baa6..01d621a53a 100755
--- a/test/functional/p2p-acceptblock.py
+++ b/test/functional/p2p-acceptblock.py
@@ -54,40 +54,6 @@ from test_framework.util import *
import time
from test_framework.blocktools import create_block, create_coinbase
-# TestNode: bare-bones "peer". Used mostly as a conduit for a test to sending
-# p2p messages to a node, generating the messages in the main testing logic.
-class TestNode(NodeConnCB):
- def __init__(self):
- super().__init__()
- self.connection = None
- self.ping_counter = 1
- self.last_pong = msg_pong()
-
- def add_connection(self, conn):
- self.connection = conn
-
- # Track the last getdata message we receive (used in the test)
- def on_getdata(self, conn, message):
- self.last_getdata = message
-
- # Spin until verack message is received from the node.
- # We use this to signal that our test can begin. This
- # is called from the testing thread, so it needs to acquire
- # the global lock.
- def wait_for_verack(self):
- while True:
- with mininode_lock:
- if self.verack_received:
- return
- time.sleep(0.05)
-
- # Wrapper for the NodeConn's send_message function
- def send_message(self, message):
- self.connection.send_message(message)
-
- def on_pong(self, conn, message):
- self.last_pong = message
-
class AcceptBlockTest(BitcoinTestFramework):
def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary",
@@ -112,8 +78,8 @@ class AcceptBlockTest(BitcoinTestFramework):
def run_test(self):
# Setup the p2p connections and start up the network thread.
- test_node = TestNode() # connects to node0 (not whitelisted)
- white_node = TestNode() # connects to node1 (whitelisted)
+ test_node = NodeConnCB() # connects to node0 (not whitelisted)
+ white_node = NodeConnCB() # connects to node1 (whitelisted)
connections = []
connections.append(NodeConn('127.0.0.1', p2p_port(0), self.nodes[0], test_node))
@@ -238,12 +204,12 @@ class AcceptBlockTest(BitcoinTestFramework):
# triggers a getdata on block 2 (it should if block 2 is missing).
with mininode_lock:
# Clear state so we can check the getdata request
- test_node.last_getdata = None
+ test_node.last_message.pop("getdata", None)
test_node.send_message(msg_inv([CInv(2, blocks_h3[0].sha256)]))
test_node.sync_with_ping()
with mininode_lock:
- getdata = test_node.last_getdata
+ getdata = test_node.last_message["getdata"]
# Check that the getdata includes the right block
assert_equal(getdata.inv[0].hash, blocks_h2f[0].sha256)