From bd355b8db9ffaacaafd10eb14f6b74cf00d8fc06 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 20 Sep 2017 00:13:44 -0700 Subject: Add regtest testing to base58_tests --- src/test/base58_tests.cpp | 25 +++---- src/test/data/base58_keys_valid.json | 135 ++++++++++++++++++++++------------- 2 files changed, 94 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index f6613b0b94..65092f593b 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -92,12 +92,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_parse) std::vector exp_payload = ParseHex(test[1].get_str()); const UniValue &metadata = test[2].get_obj(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - bool isTestnet = find_value(metadata, "chain").get_str() == "testnet"; - if (isTestnet) { - SelectParams(CBaseChainParams::TESTNET); - } else { - SelectParams(CBaseChainParams::MAIN); - } + SelectParams(find_value(metadata, "chain").get_str()); if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); // Must be valid private key @@ -141,12 +136,7 @@ BOOST_AUTO_TEST_CASE(base58_keys_valid_gen) std::vector exp_payload = ParseHex(test[1].get_str()); const UniValue &metadata = test[2].get_obj(); bool isPrivkey = find_value(metadata, "isPrivkey").get_bool(); - bool isTestnet = find_value(metadata, "chain").get_str() == "testnet"; - if (isTestnet) { - SelectParams(CBaseChainParams::TESTNET); - } else { - SelectParams(CBaseChainParams::MAIN); - } + SelectParams(find_value(metadata, "chain").get_str()); if (isPrivkey) { bool isCompressed = find_value(metadata, "isCompressed").get_bool(); CKey key; @@ -185,10 +175,13 @@ BOOST_AUTO_TEST_CASE(base58_keys_invalid) std::string exp_base58string = test[0].get_str(); // must be invalid as public and as private key - destination = DecodeDestination(exp_base58string); - BOOST_CHECK_MESSAGE(!IsValidDestination(destination), "IsValid pubkey:" + strTest); - secret.SetString(exp_base58string); - BOOST_CHECK_MESSAGE(!secret.IsValid(), "IsValid privkey:" + strTest); + for (auto chain : { CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::REGTEST }) { + 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); + } } } diff --git a/src/test/data/base58_keys_valid.json b/src/test/data/base58_keys_valid.json index e1e4d0a304..175b297a1c 100644 --- a/src/test/data/base58_keys_valid.json +++ b/src/test/data/base58_keys_valid.json @@ -4,7 +4,7 @@ "76a91465a16059864a2fdbc7c99a4723a8395bc6f188eb88ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -12,7 +12,7 @@ "a91474f209f6ea907e2ea48f74fae05782ae8a66525787", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -20,7 +20,15 @@ "76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" + } + ], + [ + "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", + "76a91453c0307d6851aa0ce7825ba883c6bd9ad242b48688ac", + { + "isPrivkey": false, + "chain": "regtest" } ], [ @@ -28,7 +36,7 @@ "a9146349a418fc4578d10a372b54b45c280cc8c4382f87", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -37,7 +45,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -46,7 +54,16 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" + } + ], + [ + "9213qJab2HNEpMpYNBa7wHGFKKbkDn24jpANDs2huN3yi4J11ko", + "36cb93b9ab1bdabf7fb9f2c04f1b9cc879933530ae7842398eef5a63a56800c2", + { + "isCompressed": false, + "isPrivkey": true, + "chain": "test" } ], [ @@ -55,7 +72,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "regtest" } ], [ @@ -64,7 +81,16 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" + } + ], + [ + "cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH", + "b9f4892c9e8282028fea1d2667c4dc5213564d41fc5783896a0d843fc15089f3", + { + "isCompressed": true, + "isPrivkey": true, + "chain": "regtest" } ], [ @@ -72,7 +98,7 @@ "76a9146d23156cbbdcc82a5a47eee4c2c7c583c18b6bf488ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -80,7 +106,7 @@ "a914fcc5460dd6e2487c7d75b1963625da0e8f4c597587", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -88,7 +114,7 @@ "76a914f1d470f9b02370fdec2e6b708b08ac431bf7a5f788ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -96,7 +122,7 @@ "a914c579342c2c4c9220205e2cdc285617040c924a0a87", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -105,7 +131,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -114,7 +140,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -123,7 +149,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -132,7 +158,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -140,7 +166,7 @@ "76a9147987ccaa53d02c8873487ef919677cd3db7a691288ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -148,7 +174,7 @@ "a91463bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb87", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -156,7 +182,7 @@ "76a914ef66444b5b17f14e8fae6e7e19b045a78c54fd7988ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -164,7 +190,7 @@ "a914c3e55fceceaa4391ed2a9677f4a4d34eacd021a087", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -173,7 +199,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -182,7 +208,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -191,7 +217,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -200,7 +226,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -208,7 +234,7 @@ "76a914adc1cc2081a27206fae25792f28bbc55b831549d88ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -216,7 +242,7 @@ "a914188f91a931947eddd7432d6e614387e32b24470987", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -224,7 +250,7 @@ "76a9141694f5bc1a7295b600f40018a618a6ea48eeb49888ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -232,7 +258,7 @@ "a9143b9b3fd7a50d4f08d1a5b0f62f644fa7115ae2f387", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -241,7 +267,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -250,7 +276,16 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" + } + ], + [ + "92xFEve1Z9N8Z641KQQS7ByCSb8kGjsDzw6fAmjHN1LZGKQXyMq", + "b4204389cef18bbe2b353623cbf93e8678fbc92a475b664ae98ed594e6cf0856", + { + "isCompressed": false, + "isPrivkey": true, + "chain": "test" } ], [ @@ -259,7 +294,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "regtest" } ], [ @@ -268,7 +303,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -276,7 +311,7 @@ "76a914c4c1b72491ede1eedaca00618407ee0b772cad0d88ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -284,7 +319,7 @@ "a914f6fe69bcb548a829cce4c57bf6fff8af3a5981f987", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -292,7 +327,7 @@ "76a914261f83568a098a8638844bd7aeca039d5f2352c088ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -300,7 +335,7 @@ "a914e930e1834a4d234702773951d627cce82fbb5d2e87", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -309,7 +344,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -318,7 +353,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -327,7 +362,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -336,7 +371,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -344,7 +379,7 @@ "76a9145eadaf9bb7121f0f192561a5a62f5e5f5421029288ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -352,7 +387,7 @@ "a9143f210e7277c899c3a155cc1c90f4106cbddeec6e87", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -360,7 +395,7 @@ "76a914c8a3c2a09a298592c3e180f02487cd91ba3400b588ac", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -368,7 +403,7 @@ "a91499b31df7c9068d1481b596578ddbb4d3bd90baeb87", { "isPrivkey": false, - "chain": "testnet" + "chain": "test" } ], [ @@ -377,7 +412,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -386,7 +421,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "mainnet" + "chain": "main" } ], [ @@ -395,7 +430,7 @@ { "isCompressed": false, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -404,7 +439,7 @@ { "isCompressed": true, "isPrivkey": true, - "chain": "testnet" + "chain": "test" } ], [ @@ -412,7 +447,7 @@ "76a9141ed467017f043e91ed4c44b4e8dd674db211c4e688ac", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ], [ @@ -420,7 +455,7 @@ "a9145ece0cadddc415b1980f001785947120acdb36fc87", { "isPrivkey": false, - "chain": "mainnet" + "chain": "main" } ] ] -- cgit v1.2.3