Skip to content

Commit 0608a16

Browse files
committed
[tests] Update test for wallet rebroadcasts
Main change is the last `setmocktime` value from `setmocktime(0)` to `setmocktime(time_now + 60 * 29)`.
1 parent f2faae2 commit 0608a16

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

test/functional/wallet_resendwallettransactions.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,43 @@ def skip_test_if_missing_module(self):
3232
self.skip_if_no_wallet()
3333

3434
def run_test(self):
35-
self.nodes[0].add_p2p_connection(P2PStoreTxInvs())
35+
node = self.nodes[0]
36+
node.add_p2p_connection(P2PStoreTxInvs())
3637

3738
# Create a new transaction. Set time to 31 minutes in the past.
38-
time_now = int(time.time())
39-
self.nodes[0].setmocktime(time_now - 60 * 31)
40-
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
39+
node.setmocktime(int(time.time()) - 60 * 31)
40+
txid = node.sendtoaddress(node.getnewaddress(), 1)
4141

42-
# Can take a few seconds due to transaction trickling
43-
wait_until(lambda: self.nodes[0].p2p.tx_invs_received[txid] >= 1)
42+
# Can take a few seconds due to transaction trickling.
43+
wait_until(lambda: node.p2p.tx_invs_received[txid] >= 1)
4444
time_now = int(time.time())
4545

46-
# Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown)
47-
self.nodes[0].add_p2p_connection(P2PStoreTxInvs())
46+
# Add a second peer since txs aren't rebroadcast to the same peer (see filterInventoryKnown).
47+
node.add_p2p_connection(P2PStoreTxInvs())
4848

4949
# Mine a block. Transactions are only rebroadcast if a block has been mined
5050
# since the last time we tried to broadcast. Make sure that the transaction is
5151
# not included in the block.
5252
# The block must be received more than 5 minutes after the transaction timestamp for the
5353
# transaction to be rebroadcast.
54-
self.nodes[0].setmocktime(time_now - 60 * 25)
55-
block = create_block(int(self.nodes[0].getbestblockhash(), 16), create_coinbase(self.nodes[0].getblockchaininfo()['blocks']), time_now)
54+
node.setmocktime(time_now - 60 * 25)
55+
block = create_block(
56+
int(node.getbestblockhash(), 16),
57+
create_coinbase(node.getblockchaininfo()['blocks']),
58+
time_now,
59+
)
5660
block.nVersion = 3
5761
block.rehash()
5862
block.solve()
59-
self.nodes[0].submitblock(ToHex(block))
63+
node.submitblock(ToHex(block))
6064

6165
# Transaction should not be rebroadcast
62-
self.nodes[0].p2ps[1].sync_with_ping()
63-
assert_equal(self.nodes[0].p2ps[1].tx_invs_received[txid], 0)
66+
node.p2ps[1].sync_with_ping()
67+
assert_equal(node.p2ps[1].tx_invs_received[txid], 0)
6468

65-
# Transaction should be broadcast after 30 minutes. Give an extra minute to be sure
66-
self.nodes[0].setmocktime(0)
67-
wait_until(lambda: self.nodes[0].p2ps[1].tx_invs_received[txid] >= 1)
69+
# Transaction should be broadcast after 30 minutes. Give it ~60 (31 + 29) to be sure.
70+
node.setmocktime(time_now + 60 * 29)
71+
wait_until(lambda: node.p2ps[1].tx_invs_received[txid] >= 1)
6872

6973
if __name__ == '__main__':
7074
ResendWalletTransactionsTest().main()

0 commit comments

Comments
 (0)