Skip to content

Commit fd3777b

Browse files
committed
Merge pull request #5280
3c30f27 travis: disable rpc tests for windows until they're not so flaky (Cory Fields) daf03e7 RPC tests: create initial chain with specific timestamps (Gavin Andresen) a8b2ce5 regression test only setmocktime RPC call (Gavin Andresen)
2 parents e356002 + 3c30f27 commit fd3777b

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

qa/pull-tester/rpc-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ CURDIR=$(cd $(dirname "$0"); pwd)
88
export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli
99
export BITCOIND=${REAL_BITCOIND}
1010

11+
if [ "x${EXEEXT}" = "x.exe" ]; then
12+
echo "Win tests currently disabled"
13+
exit 0
14+
fi
15+
1116
#Run the tests
1217

1318
if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then

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():

src/rpcclient.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CRPCConvertParam
2525
static const CRPCConvertParam vRPCConvertParams[] =
2626
{
2727
{ "stop", 0 },
28+
{ "setmocktime", 0 },
2829
{ "getaddednodeinfo", 0 },
2930
{ "setgenerate", 0 },
3031
{ "setgenerate", 1 },

src/rpcmisc.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,23 @@ Value verifymessage(const Array& params, bool fHelp)
354354

355355
return (pubkey.GetID() == keyID);
356356
}
357+
358+
Value setmocktime(const Array& params, bool fHelp)
359+
{
360+
if (fHelp || params.size() != 1)
361+
throw runtime_error(
362+
"setmocktime timestamp\n"
363+
"\nSet the local time to given timestamp (-regtest only)\n"
364+
"\nArguments:\n"
365+
"1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n"
366+
" Pass 0 to go back to using the system time."
367+
);
368+
369+
if (!Params().MineBlocksOnDemand())
370+
throw runtime_error("setmocktime for regression testing (-regtest mode) only");
371+
372+
RPCTypeCheck(params, boost::assign::list_of(int_type));
373+
SetMockTime(params[0].get_int64());
374+
375+
return Value::null;
376+
}

src/rpcserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] =
246246
{ "control", "getinfo", &getinfo, true, false, false }, /* uses wallet if enabled */
247247
{ "control", "help", &help, true, true, false },
248248
{ "control", "stop", &stop, true, true, false },
249+
{ "control", "setmocktime", &setmocktime, true, false, false },
249250

250251
/* P2P networking */
251252
{ "network", "getnetworkinfo", &getnetworkinfo, true, false, false },

src/rpcserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp);
194194
extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp);
195195
extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp);
196196
extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp);
197+
extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp);
197198

198199
extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
199200
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);

0 commit comments

Comments
 (0)