Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
wallet
test
feebumper_tests.cpp
Go to the documentation of this file.
1
// Copyright (c) 2022-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
4
5
#include <
consensus/validation.h
>
6
#include <
policy/policy.h
>
7
#include <
primitives/transaction.h
>
8
#include <
script/script.h
>
9
#include <
util/strencodings.h
>
10
#include <
wallet/feebumper.h
>
11
#include <
wallet/test/util.h
>
12
#include <
wallet/test/wallet_test_fixture.h
>
13
14
#include <boost/test/unit_test.hpp>
15
16
namespace
wallet
{
17
namespace
feebumper
{
18
BOOST_FIXTURE_TEST_SUITE
(feebumper_tests, WalletTestingSetup)
19
20
static
void
CheckMaxWeightComputation
(const
std
::
string
& script_str, const
std
::vector<
std
::
string
>& witness_str_stack, const
std
::
string
& prevout_script_str, int64_t expected_max_weight)
21
{
22
std::vector script_data(
ParseHex
(script_str));
23
CScript
script
(script_data.begin(), script_data.end());
24
CTxIn
input(
Txid
{}, 0,
script
);
25
26
for
(
const
auto
& s : witness_str_stack) {
27
input.scriptWitness.stack.push_back(
ParseHex
(s));
28
}
29
30
std::vector prevout_script_data(
ParseHex
(prevout_script_str));
31
CScript
prevout_script(prevout_script_data.begin(), prevout_script_data.end());
32
33
int64_t weight =
GetTransactionInputWeight
(input);
34
SignatureWeights
weights;
35
SignatureWeightChecker
size_checker(weights,
DUMMY_CHECKER
);
36
bool
script_ok =
VerifyScript
(input.scriptSig, prevout_script, &input.scriptWitness,
STANDARD_SCRIPT_VERIFY_FLAGS
, size_checker);
37
BOOST_CHECK
(script_ok);
38
weight += weights.
GetWeightDiffToMax
();
39
BOOST_CHECK_EQUAL
(weight, expected_max_weight);
40
}
41
42
BOOST_AUTO_TEST_CASE
(external_max_weight_test)
43
{
44
// P2PKH
45
CheckMaxWeightComputation
(
"453042021f03c8957c5ce12940ee6e3333ecc3f633d9a1ac53a55b3ce0351c617fa96abe021f0dccdcce3ef45a63998be9ec748b561baf077b8e862941d0cd5ec08f5afe68012102fccfeb395f0ecd3a77e7bc31c3bc61dc987418b18e395d441057b42ca043f22c"
, {},
"76a914f60dcfd3392b28adc7662669603641f578eed72d88ac"
, 593);
46
// P2SH-P2WPKH
47
CheckMaxWeightComputation
(
"160014001dca1b22c599b5a56a87c78417ad2ff39552f1"
, {
"3042021f5443c58eaf45f3e5ef46f8516f966b334a7d497cedda4edb2b9fad57c90c3b021f63a77cb56cde848e2e2dd20b487eec2f53101f634193786083f60b4d23a82301"
,
"026cfe86116f161057deb240201d6b82ebd4f161e0200d63dc9aca65a1d6b38bb7"
},
"a9147c8ab5ad7708b97ccb6b483d57aba48ee85214df87"
, 364);
48
// P2WPKH
49
CheckMaxWeightComputation
(
""
, {
"3042021f0f8906f0394979d5b737134773e5b88bf036c7d63542301d600ab677ba5a59021f0e9fe07e62c113045fa1c1532e2914720e8854d189c4f5b8c88f57956b704401"
,
"0359edba11ed1a0568094a6296a16c4d5ee4c8cfe2f5e2e6826871b5ecf8188f79"
},
"00149961a78658030cc824af4c54fbf5294bec0cabdd"
, 272);
50
// P2WSH HTLC
51
CheckMaxWeightComputation
(
""
, {
"3042021f5c4c29e6b686aae5b6d0751e90208592ea96d26bc81d78b0d3871a94a21fa8021f74dc2f971e438ccece8699c8fd15704c41df219ab37b63264f2147d15c34d801"
,
"01"
,
"6321024cf55e52ec8af7866617dc4e7ff8433758e98799906d80e066c6f32033f685f967029000b275210214827893e2dcbe4ad6c20bd743288edad21100404eb7f52ccd6062fd0e7808f268ac"
},
"002089e84892873c679b1129edea246e484fd914c2601f776d4f2f4a001eb8059703"
, 318);
52
}
53
54
BOOST_AUTO_TEST_SUITE_END
()
55
}
// namespace feebumper
56
}
// namespace wallet
CScript
Serialized script, used inside transaction inputs and outputs.
Definition
script.h:405
CTxIn
An input of a transaction.
Definition
transaction.h:62
wallet::feebumper::SignatureWeightChecker
Definition
feebumper.h:107
validation.h
GetTransactionInputWeight
static int64_t GetTransactionInputWeight(const CTxIn &txin)
Definition
validation.h:140
BOOST_FIXTURE_TEST_SUITE
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
feebumper.h
VerifyScript
bool VerifyScript(const CScript &scriptSig, const CScript &scriptPubKey, const CScriptWitness *witness, script_verify_flags flags, const BaseSignatureChecker &checker, ScriptError *serror)
Definition
interpreter.cpp:2002
script
Definition
parsing.cpp:13
std
Definition
common.h:29
wallet::feebumper
Definition
feebumper.cpp:146
wallet::feebumper::CheckMaxWeightComputation
static void CheckMaxWeightComputation(const std::string &script_str, const std::vector< std::string > &witness_str_stack, const std::string &prevout_script_str, int64_t expected_max_weight)
Definition
feebumper_tests.cpp:20
wallet::feebumper::BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(external_max_weight_test)
Definition
feebumper_tests.cpp:42
wallet
Definition
wallet_balance.cpp:26
BOOST_CHECK_EQUAL
#define BOOST_CHECK_EQUAL(v1, v2)
Definition
object.cpp:17
BOOST_CHECK
#define BOOST_CHECK(expr)
Definition
object.cpp:16
policy.h
STANDARD_SCRIPT_VERIFY_FLAGS
static constexpr script_verify_flags STANDARD_SCRIPT_VERIFY_FLAGS
Standard script verification flags that standard transactions will comply with.
Definition
policy.h:118
transaction.h
script.h
DUMMY_CHECKER
const BaseSignatureChecker & DUMMY_CHECKER
A signature checker that accepts all signatures.
Definition
sign.cpp:937
strencodings.h
ParseHex
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
Definition
strencodings.h:69
wallet::feebumper::SignatureWeights
Definition
feebumper.h:76
wallet::feebumper::SignatureWeights::GetWeightDiffToMax
int64_t GetWeightDiffToMax() const
Definition
feebumper.h:99
Txid
transaction_identifier< false > Txid
Txid commits to all transaction fields except the witness.
Definition
transaction_identifier.h:71
util.h
wallet_test_fixture.h
Generated on
for Bitcoin Core by
1.17.0