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)
This commit is contained in:
Gavin Andresen 2014-11-18 14:29:38 -05:00
commit fd3777b0b2
No known key found for this signature in database
GPG Key ID: 7588242FBE38D3A8
6 changed files with 45 additions and 8 deletions

View File

@ -8,6 +8,11 @@ CURDIR=$(cd $(dirname "$0"); pwd)
export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli export BITCOINCLI=${BUILDDIR}/qa/pull-tester/run-bitcoin-cli
export BITCOIND=${REAL_BITCOIND} export BITCOIND=${REAL_BITCOIND}
if [ "x${EXEEXT}" = "x.exe" ]; then
echo "Win tests currently disabled"
exit 0
fi
#Run the tests #Run the tests
if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then if [ "x${ENABLE_BITCOIND}${ENABLE_UTILS}${ENABLE_WALLET}" = "x111" ]; then

View File

@ -103,11 +103,16 @@ def initialize_chain(test_dir):
# Create a 200-block-long chain; each of the 4 nodes # Create a 200-block-long chain; each of the 4 nodes
# gets 25 mature blocks and 25 immature. # gets 25 mature blocks and 25 immature.
for i in range(4): # blocks are created with timestamps 10 minutes apart, starting
rpcs[i].setgenerate(True, 25) # at 1 Jan 2014
sync_blocks(rpcs) block_time = 1388534400
for i in range(4): for i in range(2):
rpcs[i].setgenerate(True, 25) 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) sync_blocks(rpcs)
# Shut them down, and clean up cache directories: # Shut them down, and clean up cache directories:
@ -179,10 +184,14 @@ def stop_node(node, i):
del bitcoind_processes[i] del bitcoind_processes[i]
def stop_nodes(nodes): def stop_nodes(nodes):
for i in range(len(nodes)): for node in nodes:
nodes[i].stop() node.stop()
del nodes[:] # Emptying array closes connections as a side effect 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(): def wait_bitcoinds():
# Wait for all bitcoinds to cleanly exit # Wait for all bitcoinds to cleanly exit
for bitcoind in bitcoind_processes.values(): for bitcoind in bitcoind_processes.values():

View File

@ -25,6 +25,7 @@ public:
static const CRPCConvertParam vRPCConvertParams[] = static const CRPCConvertParam vRPCConvertParams[] =
{ {
{ "stop", 0 }, { "stop", 0 },
{ "setmocktime", 0 },
{ "getaddednodeinfo", 0 }, { "getaddednodeinfo", 0 },
{ "setgenerate", 0 }, { "setgenerate", 0 },
{ "setgenerate", 1 }, { "setgenerate", 1 },

View File

@ -354,3 +354,23 @@ Value verifymessage(const Array& params, bool fHelp)
return (pubkey.GetID() == keyID); 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;
}

View File

@ -246,6 +246,7 @@ static const CRPCCommand vRPCCommands[] =
{ "control", "getinfo", &getinfo, true, false, false }, /* uses wallet if enabled */ { "control", "getinfo", &getinfo, true, false, false }, /* uses wallet if enabled */
{ "control", "help", &help, true, true, false }, { "control", "help", &help, true, true, false },
{ "control", "stop", &stop, true, true, false }, { "control", "stop", &stop, true, true, false },
{ "control", "setmocktime", &setmocktime, true, false, false },
/* P2P networking */ /* P2P networking */
{ "network", "getnetworkinfo", &getnetworkinfo, true, false, false }, { "network", "getnetworkinfo", &getnetworkinfo, true, false, false },

View File

@ -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 getwalletinfo(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getblockchaininfo(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 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 getrawtransaction(const json_spirit::Array& params, bool fHelp); // in rcprawtransaction.cpp
extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listunspent(const json_spirit::Array& params, bool fHelp);