In the first commit, it is possible to generate fake time passage without spending wall clock time of the test. That is, fix the problem and make the test faster:
0 def test_tx_in_block(self):
1 self.log.info("Check that a transaction in the last block is uploaded (beneficial for compact block relay)")
2+ self.gen_node.setmocktime(int(time.time()) - 120) # pause time based activities
3 inbound_peer = self.gen_node.add_p2p_connection(P2PNode())
4
5 self.log.debug("Generate transaction and block")
6 inbound_peer.last_message.pop("inv", None)
7
8- self.gen_node.setmocktime(int(time.time())) # pause time based activities
9 wtxid = self.miniwallet.send_self_transfer(from_node=self.gen_node)["wtxid"]
10 rawmp = self.gen_node.getrawmempool(False, True)
11 pi = self.gen_node.getpeerinfo()[0]
12 assert_equal(rawmp["mempool_sequence"], 2) # our tx cause mempool activity
13 assert_equal(pi["last_inv_sequence"], 1) # that is after the last inv
14 assert_equal(pi["inv_to_send"], 1) # and our tx has been queued
15 self.gen_node.setmocktime(0)
16
17- inbound_peer.wait_until(lambda: "inv" in inbound_peer.last_message and inbound_peer.last_message.get("inv").inv[0].hash == int(wtxid, 16), timeout=120)
18+ inbound_peer.wait_until(lambda: "inv" in inbound_peer.last_message and inbound_peer.last_message.get("inv").inv[0].hash == int(wtxid, 16))
19
20 rawmp = self.gen_node.getrawmempool(False, True)
Edit: to clarify, the first setmocktime()
sets the time to 120s in the past, recording that in m_next_inv_to_inbounds
, then when the time comes for bitcoind
to wait for that delay, the second setmocktime(0)
lets time flow normally and the current time is about 120s more than m_next_inv_to_inbounds
, so there is no waiting.