aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorSamuel Dobson <dobsonsa68@gmail.com>2021-09-29 10:07:04 +1300
committerSamuel Dobson <dobsonsa68@gmail.com>2021-09-29 10:41:30 +1300
commitd6492d4ed053e2b9088a9666dc55c7417c7d4c70 (patch)
treeddc54ae8fad598a5034cdd1743df071c201f9fab /src/test
parentf000cdcf0aad9cf58e18bb63094bd8fcef89b372 (diff)
parent43cd6b8af9d613ca033800c5cd8524c3f77e13ec (diff)
downloadbitcoin-d6492d4ed053e2b9088a9666dc55c7417c7d4c70.tar.xz
Merge bitcoin/bitcoin#22650: Remove -deprecatedrpc=addresses flag and corresponding code/logic
43cd6b8af9d613ca033800c5cd8524c3f77e13ec doc: add release notes for removal of the -deprecatedrpc=addresses flag (Michael Dietz) 2b1fdc2c6ce1d0b0e51a3f107e23443c142d57af refactor: minor styling, prefer snake case and same line if (Michael Dietz) d64deac7b823a0eba97ab3a3686054eefe330d3c refactor: share logic between ScriptPubKeyToUniv and ScriptToUniv (Michael Dietz) 8721638daa8502c7f8de5ae24a9393d7290a2ce5 rpc: remove deprecated addresses and reqSigs from rpc outputs (Michael Dietz) Pull request description: Resolves #21797 now that we've branched-off to v23 ("addresses" and "reqSigs" deprecated) "ExtractDestinations" should be removed. `-deprecatedrpc=addresses` was initially added in this PR #20286 (which resolved the original issue #20102). Some chunks of code and logic are no longer used/necessary with the removal of this, and therefore some minor refactoring is done in this PR as well (separated commits) ACKs for top commit: MarcoFalke: re-ACK 43cd6b8af9d613ca033800c5cd8524c3f77e13ec 🐉 meshcollider: Code review ACK 43cd6b8af9d613ca033800c5cd8524c3f77e13ec jonatack: ACK 43cd6b8af9d613ca033800c5cd8524c3f77e13ec per `git range-diff a9d0cec 92dc5e9 43cd6b8`, also rebased to latest master, debug built + quick re-review of each commit to bring back context, and ran tests locally at the final commit Tree-SHA512: fba83495e396d3c06f0dcf49292f14f4aa6b68fa758f0503941fade1a6e7271cda8378e2734af1faea550d1b43c85a36c52ebcc9dec0732936f9233b4b97901c
Diffstat (limited to 'src/test')
-rw-r--r--src/test/fuzz/script.cpp62
-rw-r--r--src/test/fuzz/transaction.cpp4
-rw-r--r--src/test/script_standard_tests.cpp61
3 files changed, 19 insertions, 108 deletions
diff --git a/src/test/fuzz/script.cpp b/src/test/fuzz/script.cpp
index 950ee45d1d..74c576322a 100644
--- a/src/test/fuzz/script.cpp
+++ b/src/test/fuzz/script.cpp
@@ -56,46 +56,8 @@ FUZZ_TARGET_INIT(script, initialize_script)
assert(script == decompressed_script);
}
- CTxDestination address;
- TxoutType type_ret;
- std::vector<CTxDestination> addresses;
- int required_ret;
- bool extract_destinations_ret = ExtractDestinations(script, type_ret, addresses, required_ret);
- bool extract_destination_ret = ExtractDestination(script, address);
- if (!extract_destinations_ret) {
- assert(!extract_destination_ret);
- if (type_ret == TxoutType::MULTISIG) {
- assert(addresses.empty() && required_ret == 0);
- } else {
- assert(type_ret == TxoutType::PUBKEY ||
- type_ret == TxoutType::NONSTANDARD ||
- type_ret == TxoutType::NULL_DATA);
- }
- } else {
- assert(required_ret >= 1 && required_ret <= 16);
- assert((unsigned long)required_ret == addresses.size());
- assert(type_ret == TxoutType::MULTISIG || required_ret == 1);
- }
- if (type_ret == TxoutType::NONSTANDARD || type_ret == TxoutType::NULL_DATA) {
- assert(!extract_destinations_ret);
- }
- if (!extract_destination_ret) {
- assert(type_ret == TxoutType::PUBKEY ||
- type_ret == TxoutType::NONSTANDARD ||
- type_ret == TxoutType::NULL_DATA ||
- type_ret == TxoutType::MULTISIG);
- } else {
- assert(address == addresses[0]);
- }
- if (type_ret == TxoutType::NONSTANDARD ||
- type_ret == TxoutType::NULL_DATA ||
- type_ret == TxoutType::MULTISIG) {
- assert(!extract_destination_ret);
- }
-
TxoutType which_type;
bool is_standard_ret = IsStandard(script, which_type);
- assert(type_ret == which_type);
if (!is_standard_ret) {
assert(which_type == TxoutType::NONSTANDARD ||
which_type == TxoutType::NULL_DATA ||
@@ -112,6 +74,20 @@ FUZZ_TARGET_INIT(script, initialize_script)
which_type == TxoutType::NONSTANDARD);
}
+ CTxDestination address;
+ bool extract_destination_ret = ExtractDestination(script, address);
+ if (!extract_destination_ret) {
+ assert(which_type == TxoutType::PUBKEY ||
+ which_type == TxoutType::NONSTANDARD ||
+ which_type == TxoutType::NULL_DATA ||
+ which_type == TxoutType::MULTISIG);
+ }
+ if (which_type == TxoutType::NONSTANDARD ||
+ which_type == TxoutType::NULL_DATA ||
+ which_type == TxoutType::MULTISIG) {
+ assert(!extract_destination_ret);
+ }
+
const FlatSigningProvider signing_provider;
(void)InferDescriptor(script, signing_provider);
(void)IsSegWitOutput(signing_provider, script);
@@ -133,15 +109,11 @@ FUZZ_TARGET_INIT(script, initialize_script)
(void)ScriptToAsmStr(script, true);
UniValue o1(UniValue::VOBJ);
- ScriptPubKeyToUniv(script, o1, true, true);
- ScriptPubKeyToUniv(script, o1, true, false);
+ ScriptPubKeyToUniv(script, o1, true);
UniValue o2(UniValue::VOBJ);
- ScriptPubKeyToUniv(script, o2, false, true);
- ScriptPubKeyToUniv(script, o2, false, false);
+ ScriptPubKeyToUniv(script, o2, false);
UniValue o3(UniValue::VOBJ);
- ScriptToUniv(script, o3, true);
- UniValue o4(UniValue::VOBJ);
- ScriptToUniv(script, o4, false);
+ ScriptToUniv(script, o3);
{
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
diff --git a/src/test/fuzz/transaction.cpp b/src/test/fuzz/transaction.cpp
index ff34cc87b2..a21e5cea0c 100644
--- a/src/test/fuzz/transaction.cpp
+++ b/src/test/fuzz/transaction.cpp
@@ -103,6 +103,6 @@ FUZZ_TARGET_INIT(transaction, initialize_transaction)
(void)IsWitnessStandard(tx, coins_view_cache);
UniValue u(UniValue::VOBJ);
- TxToUniv(tx, /* hashBlock */ uint256::ZERO, /* include_addresses */ true, u);
- TxToUniv(tx, /* hashBlock */ uint256::ONE, /* include_addresses */ false, u);
+ TxToUniv(tx, /* hashBlock */ uint256::ZERO, u);
+ TxToUniv(tx, /* hashBlock */ uint256::ONE, u);
}
diff --git a/src/test/script_standard_tests.cpp b/src/test/script_standard_tests.cpp
index a01d3fa03a..bf8ff5f5e2 100644
--- a/src/test/script_standard_tests.cpp
+++ b/src/test/script_standard_tests.cpp
@@ -252,67 +252,6 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
BOOST_CHECK(std::get<WitnessUnknown>(address) == unk);
}
-BOOST_AUTO_TEST_CASE(script_standard_ExtractDestinations)
-{
- CKey keys[3];
- CPubKey pubkeys[3];
- for (int i = 0; i < 3; i++) {
- keys[i].MakeNewKey(true);
- pubkeys[i] = keys[i].GetPubKey();
- }
-
- CScript s;
- TxoutType whichType;
- std::vector<CTxDestination> addresses;
- int nRequired;
-
- // TxoutType::PUBKEY
- s.clear();
- s << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
- BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
- BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEY);
- BOOST_CHECK_EQUAL(addresses.size(), 1U);
- BOOST_CHECK_EQUAL(nRequired, 1);
- BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
-
- // TxoutType::PUBKEYHASH
- s.clear();
- s << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
- BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
- BOOST_CHECK_EQUAL(whichType, TxoutType::PUBKEYHASH);
- BOOST_CHECK_EQUAL(addresses.size(), 1U);
- BOOST_CHECK_EQUAL(nRequired, 1);
- BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
-
- // TxoutType::SCRIPTHASH
- CScript redeemScript(s); // initialize with leftover P2PKH script
- s.clear();
- s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
- BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
- BOOST_CHECK_EQUAL(whichType, TxoutType::SCRIPTHASH);
- BOOST_CHECK_EQUAL(addresses.size(), 1U);
- BOOST_CHECK_EQUAL(nRequired, 1);
- BOOST_CHECK(std::get<ScriptHash>(addresses[0]) == ScriptHash(redeemScript));
-
- // TxoutType::MULTISIG
- s.clear();
- s << OP_2 <<
- ToByteVector(pubkeys[0]) <<
- ToByteVector(pubkeys[1]) <<
- OP_2 << OP_CHECKMULTISIG;
- BOOST_CHECK(ExtractDestinations(s, whichType, addresses, nRequired));
- BOOST_CHECK_EQUAL(whichType, TxoutType::MULTISIG);
- BOOST_CHECK_EQUAL(addresses.size(), 2U);
- BOOST_CHECK_EQUAL(nRequired, 2);
- BOOST_CHECK(std::get<PKHash>(addresses[0]) == PKHash(pubkeys[0]));
- BOOST_CHECK(std::get<PKHash>(addresses[1]) == PKHash(pubkeys[1]));
-
- // TxoutType::NULL_DATA
- s.clear();
- s << OP_RETURN << std::vector<unsigned char>({75});
- BOOST_CHECK(!ExtractDestinations(s, whichType, addresses, nRequired));
-}
-
BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
{
CKey keys[3];