diff options
author | Ava Chow <github@achow101.com> | 2024-01-26 15:27:13 -0500 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-06-07 13:55:23 -0400 |
commit | 429ec1aaaaafab150f11e27fcf132a99b57c4fc7 (patch) | |
tree | e09999b341f124bf12712f5111d563a9003f1872 /src/test | |
parent | 27e70f1f5be1f536f2314cd2ea42b4f80d927fbd (diff) | |
download | bitcoin-429ec1aaaaafab150f11e27fcf132a99b57c4fc7.tar.xz |
refactor: Rename CTransaction::nVersion to version
In order to ensure that the change of nVersion to a uint32_t in the
previous commit has no effect, rename nVersion to version in this commit
so that reviewers can easily spot if a spot was missed or if there is a
check somewhere whose semantics have changed.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/data/tx_invalid.json | 2 | ||||
-rw-r--r-- | src/test/fuzz/package_eval.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/tx_pool.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/util.cpp | 2 | ||||
-rw-r--r-- | src/test/hash_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/miner_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/sighash_tests.cpp | 2 | ||||
-rw-r--r-- | src/test/sigopcount_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/transaction_tests.cpp | 20 | ||||
-rw-r--r-- | src/test/txpackage_tests.cpp | 4 | ||||
-rw-r--r-- | src/test/txvalidation_tests.cpp | 8 | ||||
-rw-r--r-- | src/test/txvalidationcache_tests.cpp | 14 | ||||
-rw-r--r-- | src/test/util/transaction_utils.cpp | 4 | ||||
-rw-r--r-- | src/test/util/txmempool.cpp | 6 |
14 files changed, 39 insertions, 39 deletions
diff --git a/src/test/data/tx_invalid.json b/src/test/data/tx_invalid.json index a47bc8f366..486469ddef 100644 --- a/src/test/data/tx_invalid.json +++ b/src/test/data/tx_invalid.json @@ -246,7 +246,7 @@ [[["0000000000000000000000000000000000000000000000000000000000000100", 0, "HASH160 0x14 0x7c17aff532f22beb54069942f9bf567a66133eaf EQUAL"]], "0200000001000100000000000000000000000000000000000000000000000000000000000000000000030251b2000000000100000000000000000000000000", "P2SH,CHECKSEQUENCEVERIFY"], -["Failure due to insufficient tx.nVersion (<2)"], +["Failure due to insufficient tx.version (<2)"], [[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0 CHECKSEQUENCEVERIFY 1"]], "010000000100010000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000", "CHECKSEQUENCEVERIFY"], [[["0000000000000000000000000000000000000000000000000000000000000100", 0, "4194304 CHECKSEQUENCEVERIFY"]], diff --git a/src/test/fuzz/package_eval.cpp b/src/test/fuzz/package_eval.cpp index c13f229463..6ed47a5e5b 100644 --- a/src/test/fuzz/package_eval.cpp +++ b/src/test/fuzz/package_eval.cpp @@ -173,7 +173,7 @@ FUZZ_TARGET(tx_package_eval, .init = initialize_tx_pool) // Create transaction to add to the mempool const CTransactionRef tx = [&] { CMutableTransaction tx_mut; - tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ? TRUC_VERSION : CTransaction::CURRENT_VERSION; + tx_mut.version = fuzzed_data_provider.ConsumeBool() ? TRUC_VERSION : CTransaction::CURRENT_VERSION; tx_mut.nLockTime = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<uint32_t>(); // Last tx will sweep all outpoints in package const auto num_in = last_tx ? package_outpoints.size() : fuzzed_data_provider.ConsumeIntegralInRange<int>(1, mempool_outpoints.size()); diff --git a/src/test/fuzz/tx_pool.cpp b/src/test/fuzz/tx_pool.cpp index 87c1e5a97c..fdad5f802a 100644 --- a/src/test/fuzz/tx_pool.cpp +++ b/src/test/fuzz/tx_pool.cpp @@ -226,7 +226,7 @@ FUZZ_TARGET(tx_pool_standard, .init = initialize_tx_pool) // Create transaction to add to the mempool const CTransactionRef tx = [&] { CMutableTransaction tx_mut; - tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ? TRUC_VERSION : CTransaction::CURRENT_VERSION; + tx_mut.version = fuzzed_data_provider.ConsumeBool() ? TRUC_VERSION : CTransaction::CURRENT_VERSION; tx_mut.nLockTime = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<uint32_t>(); const auto num_in = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size()); const auto num_out = fuzzed_data_provider.ConsumeIntegralInRange<int>(1, outpoints_rbf.size() * 2); diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp index a1119297f4..92ded99917 100644 --- a/src/test/fuzz/util.cpp +++ b/src/test/fuzz/util.cpp @@ -43,7 +43,7 @@ CMutableTransaction ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, { CMutableTransaction tx_mut; const auto p2wsh_op_true = fuzzed_data_provider.ConsumeBool(); - tx_mut.nVersion = fuzzed_data_provider.ConsumeBool() ? + tx_mut.version = fuzzed_data_provider.ConsumeBool() ? CTransaction::CURRENT_VERSION : fuzzed_data_provider.ConsumeIntegral<uint32_t>(); tx_mut.nLockTime = fuzzed_data_provider.ConsumeIntegral<uint32_t>(); diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp index f0d2b9ed72..51f1d4c840 100644 --- a/src/test/hash_tests.cpp +++ b/src/test/hash_tests.cpp @@ -124,9 +124,9 @@ BOOST_AUTO_TEST_CASE(siphash) HashWriter ss{}; CMutableTransaction tx; - // Note these tests were originally written with tx.nVersion=1 + // Note these tests were originally written with tx.version=1 // and the test would be affected by default tx version bumps if not fixed. - tx.nVersion = 1; + tx.version = 1; ss << TX_WITH_WITNESS(tx); BOOST_CHECK_EQUAL(SipHashUint256(1, 2, ss.GetHash()), 0x79751e980c2a0a35ULL); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index d50af4c175..3300269e1b 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -421,7 +421,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: std::vector<int> prevheights; // relative height locked - tx.nVersion = 2; + tx.version = 2; tx.vin.resize(1); prevheights.resize(1); tx.vin[0].prevout.hash = txFirst[0]->GetHash(); // only 1 transaction @@ -622,7 +622,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) pblock->nVersion = VERSIONBITS_TOP_BITS; pblock->nTime = m_node.chainman->ActiveChain().Tip()->GetMedianTimePast()+1; CMutableTransaction txCoinbase(*pblock->vtx[0]); - txCoinbase.nVersion = 1; + txCoinbase.version = 1; txCoinbase.vin[0].scriptSig = CScript{} << (m_node.chainman->ActiveChain().Height() + 1) << bi.extranonce; txCoinbase.vout.resize(1); // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this) txCoinbase.vout[0].scriptPubKey = CScript(); diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index d43c474ae1..70a18835d2 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -92,7 +92,7 @@ void static RandomScript(CScript &script) { void static RandomTransaction(CMutableTransaction& tx, bool fSingle) { - tx.nVersion = InsecureRand32(); + tx.version = InsecureRand32(); tx.vin.clear(); tx.vout.clear(); tx.nLockTime = (InsecureRandBool()) ? InsecureRand32() : 0; diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index 2081acdf4d..aed67d5f3c 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -86,7 +86,7 @@ static ScriptError VerifyWithFlag(const CTransaction& output, const CMutableTran */ static void BuildTxs(CMutableTransaction& spendingTx, CCoinsViewCache& coins, CMutableTransaction& creationTx, const CScript& scriptPubKey, const CScript& scriptSig, const CScriptWitness& witness) { - creationTx.nVersion = 1; + creationTx.version = 1; creationTx.vin.resize(1); creationTx.vin[0].prevout.SetNull(); creationTx.vin[0].scriptSig = CScript(); @@ -94,7 +94,7 @@ static void BuildTxs(CMutableTransaction& spendingTx, CCoinsViewCache& coins, CM creationTx.vout[0].nValue = 1; creationTx.vout[0].scriptPubKey = scriptPubKey; - spendingTx.nVersion = 1; + spendingTx.version = 1; spendingTx.vin.resize(1); spendingTx.vin[0].prevout.hash = creationTx.GetHash(); spendingTx.vin[0].prevout.n = 0; diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index 384babbde1..d872166226 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -412,7 +412,7 @@ BOOST_AUTO_TEST_CASE(test_Get) static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const CScript& outscript, CTransactionRef& output, CMutableTransaction& input, bool success = true) { CMutableTransaction outputm; - outputm.nVersion = 1; + outputm.version = 1; outputm.vin.resize(1); outputm.vin[0].prevout.SetNull(); outputm.vin[0].scriptSig = CScript(); @@ -428,7 +428,7 @@ static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const assert(output->vout[0] == outputm.vout[0]); CMutableTransaction inputm; - inputm.nVersion = 1; + inputm.version = 1; inputm.vin.resize(1); inputm.vin[0].prevout.hash = output->GetHash(); inputm.vin[0].prevout.n = 0; @@ -485,7 +485,7 @@ static void ReplaceRedeemScript(CScript& script, const CScript& redeemScript) BOOST_AUTO_TEST_CASE(test_big_witness_transaction) { CMutableTransaction mtx; - mtx.nVersion = 1; + mtx.version = 1; CKey key = GenerateRandomKey(); // Need to use compressed keys in segwit or the signing will fail FillableSigningProvider keystore; @@ -779,21 +779,21 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) t.vout[0].nValue = nDustThreshold; CheckIsStandard(t); - // Disallowed nVersion - t.nVersion = std::numeric_limits<uint32_t>::max(); + // Disallowed version + t.version = std::numeric_limits<uint32_t>::max(); CheckIsNotStandard(t, "version"); - t.nVersion = 0; + t.version = 0; CheckIsNotStandard(t, "version"); - t.nVersion = TX_MAX_STANDARD_VERSION + 1; + t.version = TX_MAX_STANDARD_VERSION + 1; CheckIsNotStandard(t, "version"); - // Allowed nVersion - t.nVersion = 1; + // Allowed version + t.version = 1; CheckIsStandard(t); - t.nVersion = 2; + t.version = 2; CheckIsStandard(t); // Check dust with odd relay fee to verify rounding: diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp index 55e0c5f285..d5f3412aed 100644 --- a/src/test/txpackage_tests.cpp +++ b/src/test/txpackage_tests.cpp @@ -523,7 +523,7 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) CKey child_key = GenerateRandomKey(); CScript child_locking_script = GetScriptForDestination(WitnessV0KeyHash(child_key.GetPubKey())); CMutableTransaction mtx_child1; - mtx_child1.nVersion = 1; + mtx_child1.version = 1; mtx_child1.vin.resize(1); mtx_child1.vin[0].prevout.hash = ptx_parent->GetHash(); mtx_child1.vin[0].prevout.n = 0; @@ -651,7 +651,7 @@ BOOST_FIXTURE_TEST_CASE(package_witness_swap_tests, TestChain100Setup) CTransactionRef ptx_grandparent2 = MakeTransactionRef(mtx_grandparent2); CMutableTransaction mtx_parent2_v1; - mtx_parent2_v1.nVersion = 1; + mtx_parent2_v1.version = 1; mtx_parent2_v1.vin.resize(1); mtx_parent2_v1.vin[0].prevout.hash = ptx_grandparent2->GetHash(); mtx_parent2_v1.vin[0].prevout.n = 0; diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp index f36c245383..f429f94a2f 100644 --- a/src/test/txvalidation_tests.cpp +++ b/src/test/txvalidation_tests.cpp @@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG; CMutableTransaction coinbaseTx; - coinbaseTx.nVersion = 1; + coinbaseTx.version = 1; coinbaseTx.vin.resize(1); coinbaseTx.vout.resize(1); coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL; @@ -72,11 +72,11 @@ static inline std::vector<CPubKey> random_keys(size_t num_keys) { return keys; } -// Creates a placeholder tx (not valid) with 25 outputs. Specify the nVersion and the inputs. +// Creates a placeholder tx (not valid) with 25 outputs. Specify the version and the inputs. static inline CTransactionRef make_tx(const std::vector<COutPoint>& inputs, int32_t version) { CMutableTransaction mtx = CMutableTransaction{}; - mtx.nVersion = version; + mtx.version = version; mtx.vin.resize(inputs.size()); mtx.vout.resize(25); for (size_t i{0}; i < inputs.size(); ++i) { @@ -286,7 +286,7 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup) script_multisig << OP_2 << OP_CHECKMULTISIG; { CMutableTransaction mtx_many_sigops = CMutableTransaction{}; - mtx_many_sigops.nVersion = TRUC_VERSION; + mtx_many_sigops.version = TRUC_VERSION; for (const auto& outpoint : multisig_outpoints) { mtx_many_sigops.vin.emplace_back(outpoint); mtx_many_sigops.vin.back().scriptWitness.stack.emplace_back(script_multisig.begin(), script_multisig.end()); diff --git a/src/test/txvalidationcache_tests.cpp b/src/test/txvalidationcache_tests.cpp index 790eabc7c1..78ef96a15d 100644 --- a/src/test/txvalidationcache_tests.cpp +++ b/src/test/txvalidationcache_tests.cpp @@ -46,7 +46,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_block_doublespend, Dersig100Setup) spends.resize(2); for (int i = 0; i < 2; i++) { - spends[i].nVersion = 1; + spends[i].version = 1; spends[i].vin.resize(1); spends[i].vin[0].prevout.hash = m_coinbase_txns[0]->GetHash(); spends[i].vin[0].prevout.n = 0; @@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // coinbase tx. CMutableTransaction spend_tx; - spend_tx.nVersion = 1; + spend_tx.version = 1; spend_tx.vin.resize(1); spend_tx.vin[0].prevout.hash = m_coinbase_txns[0]->GetHash(); spend_tx.vin[0].prevout.n = 0; @@ -243,7 +243,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // then test validity with P2SH. { CMutableTransaction invalid_under_p2sh_tx; - invalid_under_p2sh_tx.nVersion = 1; + invalid_under_p2sh_tx.version = 1; invalid_under_p2sh_tx.vin.resize(1); invalid_under_p2sh_tx.vin[0].prevout.hash = spend_tx.GetHash(); invalid_under_p2sh_tx.vin[0].prevout.n = 0; @@ -259,7 +259,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // Test CHECKLOCKTIMEVERIFY { CMutableTransaction invalid_with_cltv_tx; - invalid_with_cltv_tx.nVersion = 1; + invalid_with_cltv_tx.version = 1; invalid_with_cltv_tx.nLockTime = 100; invalid_with_cltv_tx.vin.resize(1); invalid_with_cltv_tx.vin[0].prevout.hash = spend_tx.GetHash(); @@ -288,7 +288,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // TEST CHECKSEQUENCEVERIFY { CMutableTransaction invalid_with_csv_tx; - invalid_with_csv_tx.nVersion = 2; + invalid_with_csv_tx.version = 2; invalid_with_csv_tx.vin.resize(1); invalid_with_csv_tx.vin[0].prevout.hash = spend_tx.GetHash(); invalid_with_csv_tx.vin[0].prevout.n = 3; @@ -319,7 +319,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // for the same tx with a different witness. { CMutableTransaction valid_with_witness_tx; - valid_with_witness_tx.nVersion = 1; + valid_with_witness_tx.version = 1; valid_with_witness_tx.vin.resize(1); valid_with_witness_tx.vin[0].prevout.hash = spend_tx.GetHash(); valid_with_witness_tx.vin[0].prevout.n = 1; @@ -344,7 +344,7 @@ BOOST_FIXTURE_TEST_CASE(checkinputs_test, Dersig100Setup) // Test a transaction with multiple inputs. CMutableTransaction tx; - tx.nVersion = 1; + tx.version = 1; tx.vin.resize(2); tx.vin[0].prevout.hash = spend_tx.GetHash(); tx.vin[0].prevout.n = 0; diff --git a/src/test/util/transaction_utils.cpp b/src/test/util/transaction_utils.cpp index 7e5bb30a2c..300caa577c 100644 --- a/src/test/util/transaction_utils.cpp +++ b/src/test/util/transaction_utils.cpp @@ -9,7 +9,7 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int nValue) { CMutableTransaction txCredit; - txCredit.nVersion = 1; + txCredit.version = 1; txCredit.nLockTime = 0; txCredit.vin.resize(1); txCredit.vout.resize(1); @@ -25,7 +25,7 @@ CMutableTransaction BuildCreditingTransaction(const CScript& scriptPubKey, int n CMutableTransaction BuildSpendingTransaction(const CScript& scriptSig, const CScriptWitness& scriptWitness, const CTransaction& txCredit) { CMutableTransaction txSpend; - txSpend.nVersion = 1; + txSpend.version = 1; txSpend.nLockTime = 0; txSpend.vin.resize(1); txSpend.vout.resize(1); diff --git a/src/test/util/txmempool.cpp b/src/test/util/txmempool.cpp index 4dfc09ef67..249ce9503c 100644 --- a/src/test/util/txmempool.cpp +++ b/src/test/util/txmempool.cpp @@ -118,7 +118,7 @@ void CheckMempoolV3Invariants(const CTxMemPool& tx_pool) LOCK(tx_pool.cs); for (const auto& tx_info : tx_pool.infoAll()) { const auto& entry = *Assert(tx_pool.GetEntry(tx_info.tx->GetHash())); - if (tx_info.tx->nVersion == TRUC_VERSION) { + if (tx_info.tx->version == TRUC_VERSION) { // Check that special maximum virtual size is respected Assert(entry.GetTxSize() <= V3_MAX_VSIZE); @@ -133,12 +133,12 @@ void CheckMempoolV3Invariants(const CTxMemPool& tx_pool) Assert(entry.GetTxSize() <= V3_CHILD_MAX_VSIZE); // All v3 transactions must only have v3 unconfirmed parents. const auto& parents = entry.GetMemPoolParentsConst(); - Assert(parents.begin()->get().GetSharedTx()->nVersion == TRUC_VERSION); + Assert(parents.begin()->get().GetSharedTx()->version == TRUC_VERSION); } } else if (entry.GetCountWithAncestors() > 1) { // All non-v3 transactions must only have non-v3 unconfirmed parents. for (const auto& parent : entry.GetMemPoolParentsConst()) { - Assert(parent.get().GetSharedTx()->nVersion != TRUC_VERSION); + Assert(parent.get().GetSharedTx()->version != TRUC_VERSION); } } } |