mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-29 10:19:26 +02:00
test: add tests for miniscript GetWitnessSize
This commit is contained in:
@ -70,6 +70,7 @@ struct TestData {
|
|||||||
sig.push_back(1); // SIGHASH_ALL
|
sig.push_back(1); // SIGHASH_ALL
|
||||||
dummy_sigs.insert({pubkey, {sig, i & 1}});
|
dummy_sigs.insert({pubkey, {sig, i & 1}});
|
||||||
assert(privkey.SignSchnorr(MESSAGE_HASH, schnorr_sig, nullptr, EMPTY_AUX));
|
assert(privkey.SignSchnorr(MESSAGE_HASH, schnorr_sig, nullptr, EMPTY_AUX));
|
||||||
|
schnorr_sig.push_back(1); // Maximally-sized signature has sighash byte
|
||||||
schnorr_sigs.emplace(XOnlyPubKey{pubkey}, std::make_pair(std::move(schnorr_sig), i & 1));
|
schnorr_sigs.emplace(XOnlyPubKey{pubkey}, std::make_pair(std::move(schnorr_sig), i & 1));
|
||||||
|
|
||||||
std::vector<unsigned char> hash;
|
std::vector<unsigned char> hash;
|
||||||
@ -1119,6 +1120,9 @@ void TestNode(const MsCtx script_ctx, const NodeRef& node, FuzzedDataProvider& p
|
|||||||
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
|
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
|
||||||
assert(mal_success);
|
assert(mal_success);
|
||||||
assert(stack_nonmal == stack_mal);
|
assert(stack_nonmal == stack_mal);
|
||||||
|
// Compute witness size (excluding script push, control block, and witness count encoding).
|
||||||
|
const size_t wit_size = GetSerializeSize(stack_nonmal, PROTOCOL_VERSION) - GetSizeOfCompactSize(stack_nonmal.size());
|
||||||
|
assert(wit_size <= *node->GetWitnessSize());
|
||||||
|
|
||||||
// Test non-malleable satisfaction.
|
// Test non-malleable satisfaction.
|
||||||
witness_nonmal.stack.insert(witness_nonmal.stack.end(), std::make_move_iterator(stack_nonmal.begin()), std::make_move_iterator(stack_nonmal.end()));
|
witness_nonmal.stack.insert(witness_nonmal.stack.end(), std::make_move_iterator(stack_nonmal.begin()), std::make_move_iterator(stack_nonmal.end()));
|
||||||
|
@ -77,6 +77,7 @@ struct TestData {
|
|||||||
sig.push_back(1); // sighash byte
|
sig.push_back(1); // sighash byte
|
||||||
signatures.emplace(pubkey, sig);
|
signatures.emplace(pubkey, sig);
|
||||||
BOOST_CHECK(key.SignSchnorr(MESSAGE_HASH, schnorr_sig, nullptr, EMPTY_AUX));
|
BOOST_CHECK(key.SignSchnorr(MESSAGE_HASH, schnorr_sig, nullptr, EMPTY_AUX));
|
||||||
|
schnorr_sig.push_back(1); // Maximally sized Schnorr sigs have a sighash byte.
|
||||||
schnorr_signatures.emplace(XOnlyPubKey{pubkey}, schnorr_sig);
|
schnorr_signatures.emplace(XOnlyPubKey{pubkey}, schnorr_sig);
|
||||||
|
|
||||||
// Compute various hashes
|
// Compute various hashes
|
||||||
@ -367,6 +368,8 @@ void TestSatisfy(const KeyConverter& converter, const std::string& testcase, con
|
|||||||
// Run non-malleable satisfaction algorithm.
|
// Run non-malleable satisfaction algorithm.
|
||||||
CScriptWitness witness_nonmal;
|
CScriptWitness witness_nonmal;
|
||||||
const bool nonmal_success = node->Satisfy(satisfier, witness_nonmal.stack, true) == miniscript::Availability::YES;
|
const bool nonmal_success = node->Satisfy(satisfier, witness_nonmal.stack, true) == miniscript::Availability::YES;
|
||||||
|
// Compute witness size (excluding script push, control block, and witness count encoding).
|
||||||
|
const size_t wit_size = GetSerializeSize(witness_nonmal.stack, PROTOCOL_VERSION) - GetSizeOfCompactSize(witness_nonmal.stack.size());
|
||||||
SatisfactionToWitness(converter.MsContext(), witness_nonmal, script, builder);
|
SatisfactionToWitness(converter.MsContext(), witness_nonmal, script, builder);
|
||||||
|
|
||||||
if (nonmal_success) {
|
if (nonmal_success) {
|
||||||
@ -378,6 +381,7 @@ void TestSatisfy(const KeyConverter& converter, const std::string& testcase, con
|
|||||||
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
|
// If a non-malleable satisfaction exists, the malleable one must also exist, and be identical to it.
|
||||||
BOOST_CHECK(mal_success);
|
BOOST_CHECK(mal_success);
|
||||||
BOOST_CHECK(witness_nonmal.stack == witness_mal.stack);
|
BOOST_CHECK(witness_nonmal.stack == witness_mal.stack);
|
||||||
|
assert(wit_size <= *node->GetWitnessSize());
|
||||||
|
|
||||||
// Test non-malleable satisfaction.
|
// Test non-malleable satisfaction.
|
||||||
ScriptError serror;
|
ScriptError serror;
|
||||||
|
Reference in New Issue
Block a user