@@ -142,6 +142,10 @@ def test_basic(self):
142
142
assert_equal (self .nodes [1 ].getzmqnotifications (), [])
143
143
144
144
def test_reorg (self ):
145
+ if not self .is_wallet_compiled ():
146
+ self .log .info ("Skipping reorg test because wallet is disabled" )
147
+ return
148
+
145
149
import zmq
146
150
address = 'tcp://127.0.0.1:28333'
147
151
@@ -165,34 +169,40 @@ def test_reorg(self):
165
169
# Relax so that the subscriber is ready before publishing zmq messages
166
170
sleep (0.2 )
167
171
168
- # Generate 1 block in nodes[0] and receive all notifications
172
+ # Generate 1 block in nodes[0] with 1 mempool tx and receive all notifications
173
+ payment_txid = self .nodes [0 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 1.0 )
169
174
disconnect_block = self .nodes [0 ].generatetoaddress (1 , ADDRESS_BCRT1_UNSPENDABLE )[0 ]
170
175
disconnect_cb = self .nodes [0 ].getblock (disconnect_block )["tx" ][0 ]
171
176
assert_equal (self .nodes [0 ].getbestblockhash (), hashblock .receive ().hex ())
172
- hashtx .receive () # consume, already tested
177
+ assert_equal (hashtx .receive ().hex (), payment_txid )
178
+ assert_equal (hashtx .receive ().hex (), disconnect_cb )
173
179
174
180
# Generate 2 blocks in nodes[1]
175
181
connect_blocks = self .nodes [1 ].generatetoaddress (2 , ADDRESS_BCRT1_UNSPENDABLE )
176
182
177
183
# nodes[0] will reorg chain after connecting back nodes[1]
178
184
connect_nodes (self .nodes [0 ], 1 )
179
- self .sync_all ()
185
+ self .sync_blocks () # tx in mempool valid but not advertised
180
186
181
187
# Should receive nodes[1] tip
182
188
assert_equal (self .nodes [1 ].getbestblockhash (), hashblock .receive ().hex ())
183
189
184
- # During reorg, should only receive the last coinbase tx from tip
185
- assert_equal (hashtx .receive ().hex (), self .nodes [1 ].getblock (connect_blocks [1 ])["tx" ][0 ])
186
-
187
- # But if we do a simple invalidate we announce the disconnected coinbase
190
+ # During reorg:
191
+ # Get old payment transaction notification from disconnect and disconnected cb
192
+ assert_equal (hashtx .receive ().hex (), payment_txid )
193
+ assert_equal (hashtx .receive ().hex (), disconnect_cb )
194
+ # And the payment transaction again due to mempool entry
195
+ assert_equal (hashtx .receive ().hex (), payment_txid )
196
+ assert_equal (hashtx .receive ().hex (), payment_txid )
197
+ # And the new connected coinbases
198
+ for i in [0 , 1 ]:
199
+ assert_equal (hashtx .receive ().hex (), self .nodes [1 ].getblock (connect_blocks [i ])["tx" ][0 ])
200
+
201
+ # If we do a simple invalidate we announce the disconnected coinbase
188
202
self .nodes [0 ].invalidateblock (connect_blocks [1 ])
189
203
assert_equal (hashtx .receive ().hex (), self .nodes [1 ].getblock (connect_blocks [1 ])["tx" ][0 ])
190
- # And not the current tip
191
- try :
192
- hashtx .receive ()
193
- raise Exception ("Should have failed" )
194
- except zmq .error .Again :
195
- pass
204
+ # And the current tip
205
+ assert_equal (hashtx .receive ().hex (), self .nodes [1 ].getblock (connect_blocks [0 ])["tx" ][0 ])
196
206
197
207
if __name__ == '__main__' :
198
208
ZMQTest ().main ()
0 commit comments