37
37
"""
38
38
from decimal import Decimal
39
39
import os
40
+ import time
40
41
41
42
from test_framework .test_framework import BitcoinTestFramework
42
- from test_framework .util import assert_equal , assert_raises_rpc_error , wait_until
43
+ from test_framework .util import (
44
+ assert_equal ,
45
+ assert_greater_than_or_equal ,
46
+ assert_raises_rpc_error ,
47
+ wait_until ,
48
+ )
43
49
44
50
45
51
class MempoolPersistTest (BitcoinTestFramework ):
@@ -51,18 +57,13 @@ def skip_test_if_missing_module(self):
51
57
self .skip_if_no_wallet ()
52
58
53
59
def run_test (self ):
54
- chain_height = self .nodes [0 ].getblockcount ()
55
- assert_equal (chain_height , 200 )
56
-
57
- self .log .debug ("Mine a single block to get out of IBD" )
58
- self .nodes [0 ].generate (1 )
59
- self .sync_all ()
60
-
61
60
self .log .debug ("Send 5 transactions from node2 (to its own address)" )
61
+ tx_creation_time_lower = int (time .time ())
62
62
for i in range (5 ):
63
63
last_txid = self .nodes [2 ].sendtoaddress (self .nodes [2 ].getnewaddress (), Decimal ("10" ))
64
64
node2_balance = self .nodes [2 ].getbalance ()
65
65
self .sync_all ()
66
+ tx_creation_time_higher = int (time .time ())
66
67
67
68
self .log .debug ("Verify that node0 and node1 have 5 transactions in their mempools" )
68
69
assert_equal (len (self .nodes [0 ].getrawmempool ()), 5 )
@@ -75,6 +76,10 @@ def run_test(self):
75
76
fees = self .nodes [0 ].getmempoolentry (txid = last_txid )['fees' ]
76
77
assert_equal (fees ['base' ] + Decimal ('0.00001000' ), fees ['modified' ])
77
78
79
+ tx_creation_time = self .nodes [0 ].getmempoolentry (txid = last_txid )['time' ]
80
+ assert_greater_than_or_equal (tx_creation_time , tx_creation_time_lower )
81
+ assert_greater_than_or_equal (tx_creation_time_higher , tx_creation_time )
82
+
78
83
self .log .debug ("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions." )
79
84
self .stop_nodes ()
80
85
# Give this node a head-start, so we can be "extra-sure" that it didn't load anything later
@@ -93,6 +98,9 @@ def run_test(self):
93
98
fees = self .nodes [0 ].getmempoolentry (txid = last_txid )['fees' ]
94
99
assert_equal (fees ['base' ] + Decimal ('0.00001000' ), fees ['modified' ])
95
100
101
+ self .log .debug ('Verify time is loaded correctly' )
102
+ assert_equal (tx_creation_time , self .nodes [0 ].getmempoolentry (txid = last_txid )['time' ])
103
+
96
104
# Verify accounting of mempool transactions after restart is correct
97
105
self .nodes [2 ].syncwithvalidationinterfacequeue () # Flush mempool to wallet
98
106
assert_equal (node2_balance , self .nodes [2 ].getbalance ())
0 commit comments