From 32e69fa0df8fc1cfc8ac4f8381bc54b8f33e1c38 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 19 Sep 2017 16:49:52 -0700 Subject: Replace CBitcoinSecret with {Encode,Decode}Secret --- src/test/base58_tests.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'src/test/base58_tests.cpp') diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index a2d4f82695..56a81edfb4 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(base58_DecodeBase58) BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) { UniValue tests = read_json(std::string(json_tests::base58_keys_valid, json_tests::base58_keys_valid + sizeof(json_tests::base58_keys_valid))); - CBitcoinSecret secret; + CKey privkey; CTxDestination destination; SelectParams(CBaseChainParams::MAIN); @@ -97,9 +97,8 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); // Must be valid private key - BOOST_CHECK_MESSAGE(secret.SetString(exp_base58string), "!SetString:"+ strTest); - BOOST_CHECK_MESSAGE(secret.IsValid(), "!IsValid:" + strTest); - CKey privkey = secret.GetKey(); + privkey = DecodeSecret(exp_base58string); + BOOST_CHECK_MESSAGE(privkey.IsValid(), "!IsValid:" + strTest); BOOST_CHECK_MESSAGE(privkey.IsCompressed() == isCompressed, "compressed mismatch:" + strTest); BOOST_CHECK_MESSAGE(privkey.size() == exp_payload.size() && std::equal(privkey.begin(), privkey.end(), exp_payload.begin()), "key mismatch:" + strTest); @@ -129,8 +128,8 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) } // Public key must be invalid private key - secret.SetString(exp_base58string); - BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid pubkey as privkey:" + strTest); + privkey = DecodeSecret(exp_base58string); + BOOST_CHECK_MESSAGE(!privkey.IsValid(), "IsValid pubkey as privkey:" + strTest); } } } @@ -158,9 +157,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen) CKey key; key.Set(exp_payload.begin(), exp_payload.end(), isCompressed); assert(key.IsValid()); - CBitcoinSecret secret; - secret.SetKey(key); - BOOST_CHECK_MESSAGE(secret.ToString() == exp_base58string, "result mismatch: " + strTest); + BOOST_CHECK_MESSAGE(EncodeSecret(key) == exp_base58string, "result mismatch: " + strTest); } else { CTxDestination dest; CScript exp_script(exp_payload.begin(), exp_payload.end()); @@ -179,7 +176,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen) BOOST_AUTO_TEST_CASE(base58_keys_invalid) { UniValue tests = read_json(std::string(json_tests::base58_keys_invalid, json_tests::base58_keys_invalid + sizeof(json_tests::base58_keys_invalid))); // Negative testcases - CBitcoinSecret secret; + CKey privkey; CTxDestination destination; for (unsigned int idx = 0; idx < tests.size(); idx++) { @@ -197,8 +194,8 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid) SelectParams(chain); destination = DecodeDestination(exp_base58string); BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey in mainnet:" + strTest); - secret.SetString(exp_base58string); - BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey in mainnet:" + strTest); + privkey = DecodeSecret(exp_base58string); + BOOST_CHECK_MESSAGE(!privkey.IsValid(), "IsValid privkey in mainnet:" + strTest); } } } -- cgit v1.2.3 From 119b0f85e2c8b9729228aad5d946144d57ad0f5b Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 19 Sep 2017 18:12:25 -0700 Subject: Split key_io (address/key encodings) off from base58 --- src/test/base58_tests.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/test/base58_tests.cpp') diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 56a81edfb4..63885a7aff 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -9,6 +9,7 @@ #include #include +#include #include