mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-24 22:45:41 +01:00
script/verify_flags: make script_verify_flags type safe
`using script_verify_flags = uint32_t` allows implicit conversion to and from int, so replace it with a class to have the compiler ensure we use the correct type. Provide from_int and as_int to allow for explicit conversions when desired. Introduces the type `script_verify_flag_name` for the individual flag name enumeration.
This commit is contained in:
@@ -50,7 +50,7 @@ typedef std::vector<unsigned char> valtype;
|
||||
static CFeeRate g_dust{DUST_RELAY_TX_FEE};
|
||||
static bool g_bare_multi{DEFAULT_PERMIT_BAREMULTISIG};
|
||||
|
||||
static const std::map<std::string, unsigned int>& mapFlagNames = g_verify_flag_names;
|
||||
static const std::map<std::string, script_verify_flag_name>& mapFlagNames = g_verify_flag_names;
|
||||
|
||||
script_verify_flags ParseScriptFlags(std::string strFlags)
|
||||
{
|
||||
@@ -230,9 +230,9 @@ BOOST_AUTO_TEST_CASE(tx_valid)
|
||||
BOOST_ERROR("Tx unexpectedly failed with flag " << name << " unset: " << strTest);
|
||||
}
|
||||
// Removing random combinations of flags
|
||||
flags = TrimFlags(~(verify_flags | (unsigned int)m_rng.randbits(mapFlagNames.size())));
|
||||
flags = TrimFlags(~(verify_flags | script_verify_flags::from_int(m_rng.randbits(MAX_SCRIPT_VERIFY_FLAGS_BITS))));
|
||||
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /*expect_valid=*/true)) {
|
||||
BOOST_ERROR("Tx unexpectedly failed with random flags " << ToString(flags) << ": " << strTest);
|
||||
BOOST_ERROR("Tx unexpectedly failed with random flags " << ToString(flags.as_int()) << ": " << strTest);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
|
||||
BOOST_ERROR("Tx unexpectedly passed with flag " << name << " set: " << strTest);
|
||||
}
|
||||
// Adding random combinations of flags
|
||||
flags = FillFlags(verify_flags | (unsigned int)m_rng.randbits(mapFlagNames.size()));
|
||||
flags = FillFlags(verify_flags | script_verify_flags::from_int(m_rng.randbits(MAX_SCRIPT_VERIFY_FLAGS_BITS)));
|
||||
if (!CheckTxScripts(tx, mapprevOutScriptPubKeys, mapprevOutValues, flags, txdata, strTest, /*expect_valid=*/false)) {
|
||||
BOOST_ERROR("Tx unexpectedly passed with random flags " << name << ": " << strTest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user