@@ -54,14 +54,12 @@ def set_test_params(self):
5454 self .setup_clean_chain = True
5555
5656 def run_test (self ):
57- node0 = NodeConnCB ()
58- connections = []
59- connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], node0 ))
60- node0 .add_connection (connections [0 ])
57+ self .nodes [0 ].add_p2p_connection (NodeConnCB ())
58+
6159 NetworkThread ().start () # Start up network handling in another thread
6260
6361 # wait_for_verack ensures that the P2P connection is fully up.
64- node0 .wait_for_verack ()
62+ self . nodes [ 0 ]. p2p .wait_for_verack ()
6563
6664 self .log .info ("Mining %d blocks" , DERSIG_HEIGHT - 2 )
6765 self .coinbase_blocks = self .nodes [0 ].generate (DERSIG_HEIGHT - 2 )
@@ -83,7 +81,7 @@ def run_test(self):
8381 block .rehash ()
8482 block .solve ()
8583
86- node0 .send_and_ping (msg_block (block ))
84+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
8785 assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
8886
8987 self .log .info ("Test that blocks must now be at least version 3" )
@@ -93,15 +91,15 @@ def run_test(self):
9391 block .nVersion = 2
9492 block .rehash ()
9593 block .solve ()
96- node0 .send_and_ping (msg_block (block ))
94+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
9795 assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
9896
99- wait_until (lambda : "reject" in node0 .last_message .keys (), lock = mininode_lock )
97+ wait_until (lambda : "reject" in self . nodes [ 0 ]. p2p .last_message .keys (), lock = mininode_lock )
10098 with mininode_lock :
101- assert_equal (node0 .last_message ["reject" ].code , REJECT_OBSOLETE )
102- assert_equal (node0 .last_message ["reject" ].reason , b'bad-version(0x00000002)' )
103- assert_equal (node0 .last_message ["reject" ].data , block .sha256 )
104- del node0 .last_message ["reject" ]
99+ assert_equal (self . nodes [ 0 ]. p2p .last_message ["reject" ].code , REJECT_OBSOLETE )
100+ assert_equal (self . nodes [ 0 ]. p2p .last_message ["reject" ].reason , b'bad-version(0x00000002)' )
101+ assert_equal (self . nodes [ 0 ]. p2p .last_message ["reject" ].data , block .sha256 )
102+ del self . nodes [ 0 ]. p2p .last_message ["reject" ]
105103
106104 self .log .info ("Test that transactions with non-DER signatures cannot appear in a block" )
107105 block .nVersion = 3
@@ -114,7 +112,7 @@ def run_test(self):
114112 # First we show that this tx is valid except for DERSIG by getting it
115113 # accepted to the mempool (which we can achieve with
116114 # -promiscuousmempoolflags).
117- node0 .send_and_ping (msg_tx (spendtx ))
115+ self . nodes [ 0 ]. p2p .send_and_ping (msg_tx (spendtx ))
118116 assert spendtx .hash in self .nodes [0 ].getrawmempool ()
119117
120118 # Now we verify that a block with this transaction is invalid.
@@ -123,23 +121,23 @@ def run_test(self):
123121 block .rehash ()
124122 block .solve ()
125123
126- node0 .send_and_ping (msg_block (block ))
124+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
127125 assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
128126
129- wait_until (lambda : "reject" in node0 .last_message .keys (), lock = mininode_lock )
127+ wait_until (lambda : "reject" in self . nodes [ 0 ]. p2p .last_message .keys (), lock = mininode_lock )
130128 with mininode_lock :
131129 # We can receive different reject messages depending on whether
132130 # bitcoind is running with multiple script check threads. If script
133131 # check threads are not in use, then transaction script validation
134132 # happens sequentially, and bitcoind produces more specific reject
135133 # reasons.
136- assert node0 .last_message ["reject" ].code in [REJECT_INVALID , REJECT_NONSTANDARD ]
137- assert_equal (node0 .last_message ["reject" ].data , block .sha256 )
138- if node0 .last_message ["reject" ].code == REJECT_INVALID :
134+ assert self . nodes [ 0 ]. p2p .last_message ["reject" ].code in [REJECT_INVALID , REJECT_NONSTANDARD ]
135+ assert_equal (self . nodes [ 0 ]. p2p .last_message ["reject" ].data , block .sha256 )
136+ if self . nodes [ 0 ]. p2p .last_message ["reject" ].code == REJECT_INVALID :
139137 # Generic rejection when a block is invalid
140- assert_equal (node0 .last_message ["reject" ].reason , b'block-validation-failed' )
138+ assert_equal (self . nodes [ 0 ]. p2p .last_message ["reject" ].reason , b'block-validation-failed' )
141139 else :
142- assert b'Non-canonical DER signature' in node0 .last_message ["reject" ].reason
140+ assert b'Non-canonical DER signature' in self . nodes [ 0 ]. p2p .last_message ["reject" ].reason
143141
144142 self .log .info ("Test that a version 3 block with a DERSIG-compliant transaction is accepted" )
145143 block .vtx [1 ] = create_transaction (self .nodes [0 ],
@@ -148,7 +146,7 @@ def run_test(self):
148146 block .rehash ()
149147 block .solve ()
150148
151- node0 .send_and_ping (msg_block (block ))
149+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
152150 assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), block .sha256 )
153151
154152if __name__ == '__main__' :
0 commit comments