@@ -92,12 +92,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse)
92
92
std::vector<unsigned char > exp_payload = ParseHex (test[1 ].get_str ());
93
93
const UniValue &metadata = test[2 ].get_obj ();
94
94
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 ());
101
96
if (isPrivkey) {
102
97
bool isCompressed = find_value (metadata, " isCompressed" ).get_bool ();
103
98
// Must be valid private key
@@ -141,12 +136,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen)
141
136
std::vector<unsigned char > exp_payload = ParseHex (test[1 ].get_str ());
142
137
const UniValue &metadata = test[2 ].get_obj ();
143
138
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 ());
150
140
if (isPrivkey) {
151
141
bool isCompressed = find_value (metadata, " isCompressed" ).get_bool ();
152
142
CKey key;
@@ -185,10 +175,13 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid)
185
175
std::string exp_base58string = test[0 ].get_str ();
186
176
187
177
// 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
+ }
192
185
}
193
186
}
194
187
0 commit comments