Skip to content

Commit daf03e7

Browse files
committed
RPC tests: create initial chain with specific timestamps
Use setmocktime to create the initial block chain with 10-minute-apart-blocks starting 1 Jan 2014.
1 parent a8b2ce5 commit daf03e7

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

qa/rpc-tests/util.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,17 @@ def initialize_chain(test_dir):
103103

104104
# Create a 200-block-long chain; each of the 4 nodes
105105
# gets 25 mature blocks and 25 immature.
106-
for i in range(4):
107-
rpcs[i].setgenerate(True, 25)
108-
sync_blocks(rpcs)
109-
for i in range(4):
110-
rpcs[i].setgenerate(True, 25)
111-
sync_blocks(rpcs)
106+
# blocks are created with timestamps 10 minutes apart, starting
107+
# at 1 Jan 2014
108+
block_time = 1388534400
109+
for i in range(2):
110+
for peer in range(4):
111+
for j in range(25):
112+
set_node_times(rpcs, block_time)
113+
rpcs[peer].setgenerate(True, 1)
114+
block_time += 10*60
115+
# Must sync before next peer starts generating blocks
116+
sync_blocks(rpcs)
112117

113118
# Shut them down, and clean up cache directories:
114119
stop_nodes(rpcs)
@@ -179,10 +184,14 @@ def stop_node(node, i):
179184
del bitcoind_processes[i]
180185

181186
def stop_nodes(nodes):
182-
for i in range(len(nodes)):
183-
nodes[i].stop()
187+
for node in nodes:
188+
node.stop()
184189
del nodes[:] # Emptying array closes connections as a side effect
185190

191+
def set_node_times(nodes, t):
192+
for node in nodes:
193+
node.setmocktime(t)
194+
186195
def wait_bitcoinds():
187196
# Wait for all bitcoinds to cleanly exit
188197
for bitcoind in bitcoind_processes.values():

0 commit comments

Comments
 (0)