Introduce a CChainParameters singleton class and regtest mode.

The new class is accessed via the Params() method and holds
most things that vary between main, test and regtest networks.
The regtest mode has two purposes, one is to run the
bitcoind/bitcoinj comparison tool which compares two separate
implementations of the Bitcoin protocol looking for divergence.

The other is that when run, you get a local node which can mine
a single block instantly, which is highly convenient for testing
apps during development as there's no need to wait 10 minutes for
a block on the testnet.
This commit is contained in:
Mike Hearn
2013-05-07 15:16:25 +02:00
parent 70e7fba06d
commit 0e4b317555
27 changed files with 540 additions and 571 deletions

View File

@@ -108,8 +108,6 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
std::vector<unsigned char> result;
CBitcoinSecret secret;
CBitcoinAddress addr;
// Save global state
bool fTestNet_stored = fTestNet;
BOOST_FOREACH(Value& tv, tests)
{
@@ -125,7 +123,10 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
const Object &metadata = test[2].get_obj();
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
bool isTestnet = find_value(metadata, "isTestnet").get_bool();
fTestNet = isTestnet; // Override testnet flag
if (isTestnet)
SelectParams(CChainParams::TESTNET);
else
SelectParams(CChainParams::MAIN);
if(isPrivkey)
{
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
@@ -156,8 +157,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest);
}
}
// Restore global state
fTestNet = fTestNet_stored;
SelectParams(CChainParams::MAIN);
}
// Goal: check that generated keys match test vectors
@@ -165,9 +165,6 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
{
Array tests = read_json("base58_keys_valid.json");
std::vector<unsigned char> result;
// Save global state
bool fTestNet_stored = fTestNet;
BOOST_FOREACH(Value& tv, tests)
{
Array test = tv.get_array();
@@ -182,7 +179,10 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
const Object &metadata = test[2].get_obj();
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
bool isTestnet = find_value(metadata, "isTestnet").get_bool();
fTestNet = isTestnet; // Override testnet flag
if (isTestnet)
SelectParams(CChainParams::TESTNET);
else
SelectParams(CChainParams::MAIN);
if(isPrivkey)
{
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
@@ -225,8 +225,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
CTxDestination nodest = CNoDestination();
BOOST_CHECK(!boost::apply_visitor(CBitcoinAddressVisitor(&dummyAddr), nodest));
// Restore global state
fTestNet = fTestNet_stored;
SelectParams(CChainParams::MAIN);
}
// Goal: check that base58 parsing code is robust against a variety of corrupted data