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

Method test_sequence

test/functional/interface_zmq.py:296–442  ·  view source on GitHub ↗

Sequence zmq notifications give every blockhash and txhash in order of processing, regardless of IBD, re-orgs, etc. Format of messages: <32-byte hash>C : Blockhash connected <32-byte hash>D : Blockhash disconnected <32-

(self)

Source from the content-addressed store, hash-verified

294 assert_equal(hashtx.receive().hex(), self.nodes[1].getblock(connect_blocks[0])["tx"][0])
295
296 def test_sequence(self):
297 """
298 Sequence zmq notifications give every blockhash and txhash in order
299 of processing, regardless of IBD, re-orgs, etc.
300 Format of messages:
301 <32-byte hash>C : Blockhash connected
302 <32-byte hash>D : Blockhash disconnected
303 <32-byte hash>R<8-byte LE uint> : Transactionhash removed from mempool for non-block inclusion reason
304 <32-byte hash>A<8-byte LE uint> : Transactionhash added mempool
305 """
306 self.log.info("Testing 'sequence' publisher")
307 [seq] = self.setup_zmq_test([("sequence", "tcp://127.0.0.1:28333")])
308 self.disconnect_nodes(0, 1)
309
310 # Mempool sequence number starts at 1
311 seq_num = 1
312
313 # Generate 1 block in nodes[0] and receive all notifications
314 dc_block = self.generatetoaddress(self.nodes[0], 1, ADDRESS_BCRT1_UNSPENDABLE, sync_fun=self.no_op)[0]
315
316 # Note: We are not notified of any block transactions, coinbase or mined
317 assert_equal((self.nodes[0].getbestblockhash(), "C", None), seq.receive_sequence())
318
319 # Generate 2 blocks in nodes[1] to a different address to ensure a chain split
320 self.generatetoaddress(self.nodes[1], 2, ADDRESS_BCRT1_P2WSH_OP_TRUE, sync_fun=self.no_op)
321
322 # nodes[0] will reorg chain after connecting back nodes[1]
323 self.connect_nodes(0, 1)
324
325 # Then we receive all block (dis)connect notifications for the 2 block reorg
326 assert_equal((dc_block, "D", None), seq.receive_sequence())
327 block_count = self.nodes[1].getblockcount()
328 assert_equal((self.nodes[1].getblockhash(block_count-1), "C", None), seq.receive_sequence())
329 assert_equal((self.nodes[1].getblockhash(block_count), "C", None), seq.receive_sequence())
330
331 # Rest of test requires wallet functionality
332 if self.is_wallet_compiled():
333 self.log.info("Wait for tx from second node")
334 payment_txid = self.nodes[1].sendtoaddress(address=self.nodes[0].getnewaddress(), amount=5.0, replaceable=True)
335 self.sync_all()
336 self.log.info("Testing sequence notifications with mempool sequence values")
337
338 # Should receive the broadcasted txid.
339 assert_equal((payment_txid, "A", seq_num), seq.receive_sequence())
340 seq_num += 1
341
342 self.log.info("Testing RBF notification")
343 # Replace it to test eviction/addition notification
344 rbf_info = self.nodes[1].bumpfee(payment_txid)
345 self.sync_all()
346 assert_equal((payment_txid, "R", seq_num), seq.receive_sequence())
347 seq_num += 1
348 assert_equal((rbf_info["txid"], "A", seq_num), seq.receive_sequence())
349 seq_num += 1
350
351 # Doesn't get published when mined, make a block and tx to "flush" the possibility
352 # though the mempool sequence number does go up by the number of transactions
353 # removed from the mempool by the block mining it.

Callers 1

run_testMethod · 0.95

Calls 15

setup_zmq_testMethod · 0.95
assert_equalFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
create_blockFunction · 0.90
create_coinbaseFunction · 0.90
add_witness_commitmentFunction · 0.90
infoMethod · 0.80
disconnect_nodesMethod · 0.80
receive_sequenceMethod · 0.80
connect_nodesMethod · 0.80
hexMethod · 0.80
typeClass · 0.50

Tested by

no test coverage detected