@@ -48,20 +48,14 @@ def run_test(self):
4848 # Create the cold address
4949 coldstaking_address_staking = self .nodes [1 ].getcoldstakingaddress (staking_address_public_key , spending_address_public_key )
5050
51- # Send funds to the spending address (leave some NAV for fees)
51+ # Send funds to the spending address (leave me NAV for fees)
5252 self .nodes [0 ].sendtoaddress (spending_address_public_key , self .nodes [0 ].getbalance () - 1 )
5353 self .nodes [0 ].generate (1 )
5454 self .sync_all ()
5555
56- # Turn staking on
57- self .nodes [1 ].staking (True )
58-
5956 # Stake a block
6057 self .stake_block (self .nodes [1 ])
6158
62- # Turn staking off again
63- self .nodes [1 ].staking (False )
64-
6559 # Load the last 24h stake amount for the wallets/nodes
6660 merged_address_last_24h = self .nodes [0 ].getstakereport ()['Last 24H' ]
6761 spending_address_last_24h = self .nodes [1 ].getstakereport ()['Last 24H' ]
@@ -83,15 +77,9 @@ def run_test(self):
8377 self .nodes [1 ].generate (1 )
8478 self .sync_all ()
8579
86- # Turn staking on
87- self .nodes [2 ].staking (True )
88-
8980 # Stake a block
9081 self .stake_block (self .nodes [2 ])
9182
92- # Turn staking off again
93- self .nodes [2 ].staking (False )
94-
9583 # Load the last 24h stake amount for the wallets/nodes
9684 merged_address_last_24h = self .nodes [0 ].getstakereport ()['Last 24H' ]
9785 spending_address_last_24h = self .nodes [1 ].getstakereport ()['Last 24H' ]
@@ -108,10 +96,124 @@ def run_test(self):
10896 assert_equal ('4.00' , spending_address_last_24h )
10997 assert_equal ('2.00' , staking_address_last_24h )
11098
99+ # Time travel 2 days in the future
100+ cur_time = int (time .time ())
101+ self .nodes [0 ].setmocktime (cur_time + 172800 )
102+ self .nodes [1 ].setmocktime (cur_time + 172800 )
103+ self .nodes [2 ].setmocktime (cur_time + 172800 )
104+
105+ # Stake a block
106+ self .stake_block (self .nodes [2 ])
107+
108+ # Load the last 24h stake amount for the wallets/nodes
109+ merged_address_last_24h = self .nodes [0 ].getstakereport ()['Last 24H' ]
110+ spending_address_last_24h = self .nodes [1 ].getstakereport ()['Last 24H' ]
111+ staking_address_last_24h = self .nodes [2 ].getstakereport ()['Last 24H' ]
112+
113+ # Check the amounts
114+ assert_equal ('2.00' , merged_address_last_24h )
115+ assert_equal ('2.00' , spending_address_last_24h )
116+ assert_equal ('2.00' , staking_address_last_24h )
117+
118+ # Load the last 7 days stake amount for the wallets/nodes
119+ merged_address_last_7d = self .nodes [0 ].getstakereport ()['Last 7 Days' ]
120+ spending_address_last_7d = self .nodes [1 ].getstakereport ()['Last 7 Days' ]
121+ staking_address_last_7d = self .nodes [2 ].getstakereport ()['Last 7 Days' ]
122+
123+ # Check the amounts
124+ assert_equal ('6.00' , merged_address_last_7d )
125+ assert_equal ('6.00' , spending_address_last_7d )
126+ assert_equal ('4.00' , staking_address_last_7d )
127+
128+ # Load the averages for stake amounts
129+ avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
130+ avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
131+ avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
132+
133+ # Check the amounts
134+ assert_equal ('3.00' , avg_last7d )
135+ assert_equal ('3.00' , avg_last30d )
136+ assert_equal ('3.00' , avg_last365d )
137+
138+ # Time travel 8 days in the future
139+ cur_time = int (time .time ())
140+ self .nodes [0 ].setmocktime (cur_time + 691200 )
141+ self .nodes [1 ].setmocktime (cur_time + 691200 )
142+ self .nodes [2 ].setmocktime (cur_time + 691200 )
143+
144+ # Load the last 24h stake amount for the wallets/nodes
145+ merged_address_last_24h = self .nodes [0 ].getstakereport ()['Last 24H' ]
146+ spending_address_last_24h = self .nodes [1 ].getstakereport ()['Last 24H' ]
147+ staking_address_last_24h = self .nodes [2 ].getstakereport ()['Last 24H' ]
148+
149+ # Check the amounts
150+ assert_equal ('0.00' , merged_address_last_24h )
151+ assert_equal ('0.00' , spending_address_last_24h )
152+ assert_equal ('0.00' , staking_address_last_24h )
153+
154+ # Load the last 7 days stake amount for the wallets/nodes
155+ merged_address_last_7d = self .nodes [0 ].getstakereport ()['Last 7 Days' ]
156+ spending_address_last_7d = self .nodes [1 ].getstakereport ()['Last 7 Days' ]
157+ staking_address_last_7d = self .nodes [2 ].getstakereport ()['Last 7 Days' ]
158+
159+ # Check the amounts
160+ assert_equal ('2.00' , merged_address_last_7d )
161+ assert_equal ('2.00' , spending_address_last_7d )
162+ assert_equal ('2.00' , staking_address_last_7d )
163+
164+ # Load the averages for stake amounts
165+ avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
166+ avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
167+ avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
168+
169+ # Check the amounts
170+ assert_equal ('0.28571428' , avg_last7d )
171+ assert_equal ('0.75' , avg_last30d )
172+ assert_equal ('0.75' , avg_last365d )
173+
174+ # Time travel 31 days in the future
175+ cur_time = int (time .time ())
176+ self .nodes [0 ].setmocktime (cur_time + 2678400 )
177+ self .nodes [1 ].setmocktime (cur_time + 2678400 )
178+ self .nodes [2 ].setmocktime (cur_time + 2678400 )
179+
180+ # Load the last 24h stake amount for the wallets/nodes
181+ merged_address_last_24h = self .nodes [0 ].getstakereport ()['Last 24H' ]
182+ spending_address_last_24h = self .nodes [1 ].getstakereport ()['Last 24H' ]
183+ staking_address_last_24h = self .nodes [2 ].getstakereport ()['Last 24H' ]
184+
185+ # Check the amounts
186+ assert_equal ('0.00' , merged_address_last_24h )
187+ assert_equal ('0.00' , spending_address_last_24h )
188+ assert_equal ('0.00' , staking_address_last_24h )
189+
190+ # Load the last 7 days stake amount for the wallets/nodes
191+ merged_address_last_7d = self .nodes [0 ].getstakereport ()['Last 7 Days' ]
192+ spending_address_last_7d = self .nodes [1 ].getstakereport ()['Last 7 Days' ]
193+ staking_address_last_7d = self .nodes [2 ].getstakereport ()['Last 7 Days' ]
194+
195+ # Check the amounts
196+ assert_equal ('0.00' , merged_address_last_7d )
197+ assert_equal ('0.00' , spending_address_last_7d )
198+ assert_equal ('0.00' , staking_address_last_7d )
199+
200+ # Load the averages for stake amounts
201+ avg_last7d = self .nodes [0 ].getstakereport ()['Last 7 Days Avg' ]
202+ avg_last30d = self .nodes [0 ].getstakereport ()['Last 30 Days Avg' ]
203+ avg_last365d = self .nodes [0 ].getstakereport ()['Last 365 Days Avg' ]
204+
205+ # Check the amounts
206+ assert_equal ('0.00' , avg_last7d )
207+ assert_equal ('0.06666666' , avg_last30d )
208+ assert_equal ('0.19354838' , avg_last365d )
209+
111210 def stake_block (self , node ):
112211 # Get the current block count to check against while we wait for a stake
113212 blockcount = node .getblockcount ()
114213
214+ # Turn staking on
215+ node .staking (True )
216+
115217 # wait for a new block to be mined
116218 while node .getblockcount () == blockcount :
117219 # print("waiting for a new block...")
@@ -120,6 +222,9 @@ def stake_block(self, node):
120222 # We got one
121223 # print("found a new block...")
122224
225+ # Turn staking off
226+ node .staking (False )
227+
123228 # Make sure the blocks are mature before we check the report
124229 slow_gen (node , 5 , 0.5 )
125230 self .sync_all ()
0 commit comments