Skip to content

Commit 7356292

Browse files
committed
Have zmq reorg test cover mempool txns
1 parent a0f4f9c commit 7356292

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

test/functional/interface_zmq.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def test_basic(self):
142142
assert_equal(self.nodes[1].getzmqnotifications(), [])
143143

144144
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+
145149
import zmq
146150
address = 'tcp://127.0.0.1:28333'
147151

@@ -165,34 +169,40 @@ def test_reorg(self):
165169
# Relax so that the subscriber is ready before publishing zmq messages
166170
sleep(0.2)
167171

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)
169174
disconnect_block = self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)[0]
170175
disconnect_cb = self.nodes[0].getblock(disconnect_block)["tx"][0]
171176
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)
173179

174180
# Generate 2 blocks in nodes[1]
175181
connect_blocks = self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_UNSPENDABLE)
176182

177183
# nodes[0] will reorg chain after connecting back nodes[1]
178184
connect_nodes(self.nodes[0], 1)
179-
self.sync_all()
185+
self.sync_blocks() # tx in mempool valid but not advertised
180186

181187
# Should receive nodes[1] tip
182188
assert_equal(self.nodes[1].getbestblockhash(), hashblock.receive().hex())
183189

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
188202
self.nodes[0].invalidateblock(connect_blocks[1])
189203
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])
196206

197207
if __name__ == '__main__':
198208
ZMQTest().main()

0 commit comments

Comments
 (0)