MCPcopy Create free account
hub / github.com/ElementsProject/elements / test_reorg

Method test_reorg

test/functional/interface_zmq.py:248–294  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

246 assert_equal(self.nodes[1].getzmqnotifications(), [])
247
248 def test_reorg(self):
249 if not self.is_wallet_compiled():
250 self.log.info("Skipping reorg test because wallet is disabled")
251 return
252
253 address = 'tcp://127.0.0.1:28333'
254
255 # Should only notify the tip if a reorg occurs
256 hashblock, hashtx = self.setup_zmq_test(
257 [(topic, address) for topic in ["hashblock", "hashtx"]],
258 recv_timeout=2) # 2 second timeout to check end of notifications
259 self.disconnect_nodes(0, 1)
260
261 # Generate 1 block in nodes[0] with 1 mempool tx and receive all notifications
262 payment_txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1.0)
263 disconnect_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]
264 disconnect_cb = self.nodes[0].getblock(disconnect_block)["tx"][0]
265 assert_equal(self.nodes[0].getbestblockhash(), hashblock.receive().hex())
266 assert_equal(hashtx.receive().hex(), payment_txid)
267 assert_equal(hashtx.receive().hex(), disconnect_cb)
268
269 # Generate 2 blocks in nodes[1] to a different address to ensure split
270 connect_blocks = self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE, sync_fun=self.no_op)
271
272 # nodes[0] will reorg chain after connecting back nodes[1]
273 self.connect_nodes(0, 1)
274 self.sync_blocks() # tx in mempool valid but not advertised
275
276 # Should receive nodes[1] tip
277 assert_equal(self.nodes[1].getbestblockhash(), hashblock.receive().hex())
278
279 # During reorg:
280 # Get old payment transaction notification from disconnect and disconnected cb
281 assert_equal(hashtx.receive().hex(), payment_txid)
282 assert_equal(hashtx.receive().hex(), disconnect_cb)
283 # And the payment transaction again due to mempool entry
284 assert_equal(hashtx.receive().hex(), payment_txid)
285 assert_equal(hashtx.receive().hex(), payment_txid)
286 # And the new connected coinbases
287 for i in [0, 1]:
288 assert_equal(hashtx.receive().hex(), self.nodes[1].getblock(connect_blocks[i])["tx"][0])
289
290 # If we do a simple invalidate we announce the disconnected coinbase
291 self.nodes[0].invalidateblock(connect_blocks[1])
292 assert_equal(hashtx.receive().hex(), self.nodes[1].getblock(connect_blocks[1])["tx"][0])
293 # And the current tip
294 assert_equal(hashtx.receive().hex(), self.nodes[1].getblock(connect_blocks[0])["tx"][0])
295
296 def test_sequence(self):
297 """

Callers 1

run_testMethod · 0.95

Calls 10

setup_zmq_testMethod · 0.95
assert_equalFunction · 0.90
infoMethod · 0.80
disconnect_nodesMethod · 0.80
hexMethod · 0.80
connect_nodesMethod · 0.80
is_wallet_compiledMethod · 0.45
generatetoaddressMethod · 0.45
receiveMethod · 0.45
sync_blocksMethod · 0.45

Tested by

no test coverage detected