From a8b2ce557dbcee5e75001be0ec3aecf06165775f Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Wed, 12 Nov 2014 18:59:41 -0500 Subject: [PATCH 1/3] regression test only setmocktime RPC call --- src/rpcclient.cpp | 1 + src/rpcmisc.cpp | 20 ++++++++++++++++++++ src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 4 files changed, 23 insertions(+) diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index a9c491ced..7a1f1918f 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -25,6 +25,7 @@ public: static const CRPCConvertParam vRPCConvertParams[] = { { "stop", 0 }, + { "setmocktime", 0 }, { "getaddednodeinfo", 0 }, { "setgenerate", 0 }, { "setgenerate", 1 }, diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 08e956c96..31eaae616 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -354,3 +354,23 @@ Value verifymessage(const Array& params, bool fHelp) return (pubkey.GetID() == keyID); } + +Value setmocktime(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error( + "setmocktime timestamp\n" + "\nSet the local time to given timestamp (-regtest only)\n" + "\nArguments:\n" + "1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n" + " Pass 0 to go back to using the system time." + ); + + if (!Params().MineBlocksOnDemand()) + throw runtime_error("setmocktime for regression testing (-regtest mode) only"); + + RPCTypeCheck(params, boost::assign::list_of(int_type)); + SetMockTime(params[0].get_int64()); + + return Value::null; +} diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index cc80887ba..709e9e940 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] = { "control", "getinfo", &getinfo, true, false, false }, /* uses wallet if enabled */ { "control", "help", &help, true, true, false }, { "control", "stop", &stop, true, true, false }, + { "control", "setmocktime", &setmocktime, true, false, false }, /* P2P networking */ { "network", "getnetworkinfo", &getnetworkinfo, true, false, false }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 2a258dd89..9a0681bfa 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -194,6 +194,7 @@ extern json_spirit::Value getinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getwalletinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getblockchaininfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getnetworkinfo(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value setmocktime(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); From daf03e7c92c155e3c9c010969192c60872af7bdb Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Thu, 13 Nov 2014 13:27:13 -0500 Subject: [PATCH 2/3] 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. --- qa/rpc-tests/util.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/qa/rpc-tests/util.py b/qa/rpc-tests/util.py index 0d5eeefa7..c6d918a81 100644 --- a/qa/rpc-tests/util.py +++ b/qa/rpc-tests/util.py @@ -103,12 +103,17 @@ def initialize_chain(test_dir): # Create a 200-block-long chain; each of the 4 nodes # gets 25 mature blocks and 25 immature. - for i in range(4): - rpcs[i].setgenerate(True, 25) - sync_blocks(rpcs) - for i in range(4): - rpcs[i].setgenerate(True, 25) - sync_blocks(rpcs) + # blocks are created with timestamps 10 minutes apart, starting + # at 1 Jan 2014 + block_time = 1388534400 + for i in range(2): + for peer in range(4): + for j in range(25): + set_node_times(rpcs, block_time) + rpcs[peer].setgenerate(True, 1) + block_time += 10*60 + # Must sync before next peer starts generating blocks + sync_blocks(rpcs) # Shut them down, and clean up cache directories: stop_nodes(rpcs) @@ -179,10 +184,14 @@ def stop_node(node, i): del bitcoind_processes[i] def stop_nodes(nodes): - for i in range(len(nodes)): - nodes[i].stop() + for node in nodes: + node.stop() del nodes[:] # Emptying array closes connections as a side effect +def set_node_times(nodes, t): + for node in nodes: + node.setmocktime(t) + def wait_bitcoinds(): # Wait for all bitcoinds to cleanly exit for bitcoind in bitcoind_processes.values(): From 3c30f27f342c15af17c6f7e160be5ee60f28194d Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Mon, 17 Nov 2014 14:08:08 -0500 Subject: [PATCH 3/3] travis: disable rpc tests for windows until they're not so flaky --- qa/pull-tester/rpc-tests.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index a0056c141..0b5ad2064 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -8,6 +8,11 @@ CURDIR=$(cd $(dirname "$0"); pwd) export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli export BITCOIND=${REAL_BITCOIND} +if [ "x${EXEEXT}" = "x.exe" ]; then + echo "Win tests currently disabled" + exit 0 +fi + #Run the tests if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then