Skip to content

Commit bd355b8

Browse files
committed
Add regtest testing to base58_tests
1 parent 6565c55 commit bd355b8

File tree

2 files changed

+94
-66
lines changed

2 files changed

+94
-66
lines changed

src/test/base58_tests.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
9292
std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str());
9393
const UniValue &metadata = test[2].get_obj();
9494
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
95-
bool isTestnet = find_value(metadata, "chain").get_str() == "testnet";
96-
if (isTestnet) {
97-
SelectParams(CBaseChainParams::TESTNET);
98-
} else {
99-
SelectParams(CBaseChainParams::MAIN);
100-
}
95+
SelectParams(find_value(metadata, "chain").get_str());
10196
if (isPrivkey) {
10297
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
10398
// Must be valid private key
@@ -141,12 +136,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
141136
std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str());
142137
const UniValue &metadata = test[2].get_obj();
143138
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
144-
bool isTestnet = find_value(metadata, "chain").get_str() == "testnet";
145-
if (isTestnet) {
146-
SelectParams(CBaseChainParams::TESTNET);
147-
} else {
148-
SelectParams(CBaseChainParams::MAIN);
149-
}
139+
SelectParams(find_value(metadata, "chain").get_str());
150140
if (isPrivkey) {
151141
bool isCompressed = find_value(metadata, "isCompressed").get_bool();
152142
CKey key;
@@ -185,10 +175,13 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid)
185175
std::string exp_base58string = test[0].get_str();
186176

187177
// must be invalid as public and as private key
188-
destination = DecodeDestination(exp_base58string);
189-
BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey:" + strTest);
190-
secret.SetString(exp_base58string);
191-
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey:" + strTest);
178+
for (auto chain : { CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::REGTEST }) {
179+
SelectParams(chain);
180+
destination = DecodeDestination(exp_base58string);
181+
BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey in mainnet:" + strTest);
182+
secret.SetString(exp_base58string);
183+
BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey in mainnet:" + strTest);
184+
}
192185
}
193186
}
194187

0 commit comments

Comments
 (0)