@@ -54,14 +54,12 @@ def set_test_params(self):
54
54
self .setup_clean_chain = True
55
55
56
56
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
+
61
59
NetworkThread ().start () # Start up network handling in another thread
62
60
63
61
# wait_for_verack ensures that the P2P connection is fully up.
64
- node0 .wait_for_verack ()
62
+ self . nodes [ 0 ]. p2p .wait_for_verack ()
65
63
66
64
self .log .info ("Mining %d blocks" , DERSIG_HEIGHT - 2 )
67
65
self .coinbase_blocks = self .nodes [0 ].generate (DERSIG_HEIGHT - 2 )
@@ -83,7 +81,7 @@ def run_test(self):
83
81
block .rehash ()
84
82
block .solve ()
85
83
86
- node0 .send_and_ping (msg_block (block ))
84
+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
87
85
assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
88
86
89
87
self .log .info ("Test that blocks must now be at least version 3" )
@@ -93,15 +91,15 @@ def run_test(self):
93
91
block .nVersion = 2
94
92
block .rehash ()
95
93
block .solve ()
96
- node0 .send_and_ping (msg_block (block ))
94
+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
97
95
assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
98
96
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 )
100
98
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" ]
105
103
106
104
self .log .info ("Test that transactions with non-DER signatures cannot appear in a block" )
107
105
block .nVersion = 3
@@ -114,7 +112,7 @@ def run_test(self):
114
112
# First we show that this tx is valid except for DERSIG by getting it
115
113
# accepted to the mempool (which we can achieve with
116
114
# -promiscuousmempoolflags).
117
- node0 .send_and_ping (msg_tx (spendtx ))
115
+ self . nodes [ 0 ]. p2p .send_and_ping (msg_tx (spendtx ))
118
116
assert spendtx .hash in self .nodes [0 ].getrawmempool ()
119
117
120
118
# Now we verify that a block with this transaction is invalid.
@@ -123,23 +121,23 @@ def run_test(self):
123
121
block .rehash ()
124
122
block .solve ()
125
123
126
- node0 .send_and_ping (msg_block (block ))
124
+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
127
125
assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), tip )
128
126
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 )
130
128
with mininode_lock :
131
129
# We can receive different reject messages depending on whether
132
130
# bitcoind is running with multiple script check threads. If script
133
131
# check threads are not in use, then transaction script validation
134
132
# happens sequentially, and bitcoind produces more specific reject
135
133
# 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 :
139
137
# 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' )
141
139
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
143
141
144
142
self .log .info ("Test that a version 3 block with a DERSIG-compliant transaction is accepted" )
145
143
block .vtx [1 ] = create_transaction (self .nodes [0 ],
@@ -148,7 +146,7 @@ def run_test(self):
148
146
block .rehash ()
149
147
block .solve ()
150
148
151
- node0 .send_and_ping (msg_block (block ))
149
+ self . nodes [ 0 ]. p2p .send_and_ping (msg_block (block ))
152
150
assert_equal (int (self .nodes [0 ].getbestblockhash (), 16 ), block .sha256 )
153
151
154
152
if __name__ == '__main__' :
0 commit comments