test, bench: construct inputs/outputs declaratively in descriptor, bip352, group_outputs and ephemeral spends #36950

Open
yuvicc wants to merge 0 commits from test-declarative-descriptor-bip352 into master AGit
yuvicc commented 2026-11-23 07:01:48 +00:00 (Migrated from github.com)

Part of #36692.

  • descriptor_tests: DoCheck built the spending transaction with vin.resize(1) / vout.resize(1) and then wrote nSequence through vin[0]. It now uses literal vin/vout lists, which also makes the default input and the empty output visible.
  • bip352_tests: bip352_p2pkh_pubkey_extraction_with_checksig_in_scriptsig signed a transaction and then wrote the malleated scriptSig into its existing input. It is now split into an unsigned transaction used for signing and the final transaction built with the malleated scriptSig. The legacy sighash replaces the scriptSig being signed with the scriptCode, so the signature does not depend on the scriptSig.
  • group_outputs_tests: the addCoin helper used vout.resize(1) followed by writes to nValue and scriptPubKey. It now uses a literal vout list.
  • bench/mempool_ephemeral_spends: tx2 was built with vin.resize() followed by writes to each input's prevout. Its inputs are now constructed from their outpoints, and the single default input of tx1 and the single empty output of tx2 are literal lists. The transactions are unchanged.

No change in test or benchmark behavior.

Part of #36692. - `descriptor_tests`: `DoCheck` built the spending transaction with `vin.resize(1)` / `vout.resize(1)` and then wrote `nSequence` through `vin[0]`. It now uses literal `vin`/`vout` lists, which also makes the default input and the empty output visible. - `bip352_tests`: `bip352_p2pkh_pubkey_extraction_with_checksig_in_scriptsig` signed a transaction and then wrote the malleated scriptSig into its existing input. It is now split into an unsigned transaction used for signing and the final transaction built with the malleated scriptSig. The legacy sighash replaces the scriptSig being signed with the scriptCode, so the signature does not depend on the scriptSig. - `group_outputs_tests`: the `addCoin` helper used `vout.resize(1)` followed by writes to `nValue` and `scriptPubKey`. It now uses a literal `vout` list. - `bench/mempool_ephemeral_spends`: `tx2` was built with `vin.resize()` followed by writes to each input's `prevout`. Its inputs are now constructed from their outpoints, and the single default input of `tx1` and the single empty output of `tx2` are literal lists. The transactions are unchanged. No change in test or benchmark behavior.
DrahtBot commented 2026-11-23 07:01:57 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK maflcko, janb84

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36950 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36950.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36950#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [maflcko](https://github.com/bitcoin/bitcoin/pull/36950#issuecomment-7156175711), [janb84](https://github.com/bitcoin/bitcoin/pull/36950#pullrequestreview-6058009351) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🔵 Suggestion · The advertised bip352_tests refactor is absent

The title and description promise a bip352_tests restructuring that the series does not contain, leaving reviewers with a signing-equivalence claim but no corresponding change to assess.

Location: src/test/descriptor_tests.cpp:460 (commit).

Review coverage was incomplete.


Reviewed: 5b4baa8dada1 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:806938d40e279b6d701b2e78128bb1a09b55193a0b697245a1dce6241d3081c1:3607c760b63c01fb7f1f349adfc3fd0614b148a7df02e42f2f0edc2d448925a1 --> <!-- ralph-base:3e4c803da8b5b63eda5791be869cff4bc18f1c2c --> <!-- ralph-head:5b4baa8dada19ceac2b2f882cf6ca3d071c87f87 --> <!-- ralph-case:73913d8416284efed85132fc3e7f9f49f91df8177ff6df410df6e3b919f2619f --> **🔵 Suggestion · The advertised `bip352_tests` refactor is absent** The title and description promise a `bip352_tests` restructuring that the series does not contain, leaving reviewers with a signing-equivalence claim but no corresponding change to assess. Location: src/test/descriptor_tests.cpp:460 (commit). Review coverage was incomplete. <!-- Review tier: routine --> --- Reviewed: [`5b4baa8dada1`](<https://git.fish.foo/bitcoin/bitcoin/commit/5b4baa8dada19ceac2b2f882cf6ca3d071c87f87>) · [Review report](<https://review.fish.foo/report/36950-5b4baa8dada19ceac2b2f882cf6ca3d071c87f87-3103-3.html>) · [Previous reports](<https://review.fish.foo/traces/36950/>) [permalink](<https://review.fish.foo/report/36950-5b4baa8dada19ceac2b2f882cf6ca3d071c87f87-3103-3.html>)
janb84 (Migrated from github.com) reviewed 2026-11-24 12:37:01 +00:00
janb84 (Migrated from github.com) left a comment

ACK 3fb26984f8

No remarks on this one, LGTM.

ACK 3fb26984f85967e2a7206a16b193d0dd72f3a4a9 No remarks on this one, LGTM.
maflcko commented 2026-11-24 16:59:03 +00:00 (Migrated from github.com)

review ACK 3fb26984f8 🥐

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 3fb26984f85967e2a7206a16b193d0dd72f3a4a9 🥐
HynZvXxLhmIAuXus9HBKPZBag26bGG01NiGLfKZ57BB4bTaSelCmi1eNuEmwAKUjUPhM1TeMho/WuCLK2ieTCA==
review ACK 3fb26984f85967e2a7206a16b193d0dd72f3a4a9 🥐 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 3fb26984f85967e2a7206a16b193d0dd72f3a4a9 🥐 HynZvXxLhmIAuXus9HBKPZBag26bGG01NiGLfKZ57BB4bTaSelCmi1eNuEmwAKUjUPhM1TeMho/WuCLK2ieTCA== ``` </details>
maflcko (Migrated from github.com) reviewed 2026-11-24 18:19:16 +00:00
maflcko (Migrated from github.com) commented 2026-11-24 18:19:16 +00:00

after reviewing another pull, I don't really see the point of the second commit. It is pretty normal that signing a transaction mutates its signature. There is no need to create a full copy of it. Also 07540640aa, leaves this as-is as well.

after reviewing another pull, I don't really see the point of the second commit. It is pretty normal that signing a transaction mutates its signature. There is no need to create a full copy of it. Also 07540640aa49e357b78523efc4f6c13c3a51a5cc, leaves this as-is as well.
yuvicc (Migrated from github.com) reviewed 2026-11-25 05:17:35 +00:00
yuvicc (Migrated from github.com) commented 2026-11-25 05:17:35 +00:00

Hmm, makes sense.

Hmm, makes sense.
yuvicc commented 2026-11-25 05:21:00 +00:00 (Migrated from github.com)

Removed second commit (d6464b3) as signing a txn can mutate the signature. comment

Removed second commit ([d6464b3](https://github.com/bitcoin/bitcoin/pull/36950/commits/d6464b35b97ec5ea93253ab3958c4692405365d1)) as signing a txn can mutate the signature. [comment](https://github.com/bitcoin/bitcoin/pull/36950#discussion_r4684567100)
maflcko (Migrated from github.com) reviewed 2026-11-25 07:41:54 +00:00
maflcko (Migrated from github.com) commented 2026-11-25 07:41:54 +00:00

I think it would be good to wrap up this project in a few pull requests and just focus on the important ones:

  • Fixup the places that do a vin/vout resize() in combination with immediately following field-assignment: E.g. tx.vout.resize(1); tx.vout[0].nValue=.... Everything else is probably best left as-is style-wise for now to avoid code and review churn.

So I think the diff would be something like this: (unreviewed slop, need to drop the changes that are already in reviewed pulls, also should use multi-line initializer lists with trailing comma):

a diff
diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp
index ffb9058..9d2c7ca 100644
--- a/src/test/blockencodings_tests.cpp
+++ b/src/test/blockencodings_tests.cpp
@@ -23,6 +23,6 @@ static CMutableTransaction BuildTransactionTestCase() {
     CMutableTransaction tx;
-    tx.vin.resize(1);
-    tx.vin[0].scriptSig.resize(10);
-    tx.vout.resize(1);
-    tx.vout[0].nValue = 42;
+    CScript script_sig;
+    script_sig.resize(10);
+    tx.vin = {CTxIn{COutPoint{}, script_sig}};
+    tx.vout = {CTxOut{42, CScript{}}};
     return tx;
diff --git a/src/test/blockpolicyestimator_tests.cpp b/src/test/blockpolicyestimator_tests.cpp
index 0c2cec6..2784479 100644
--- a/src/test/blockpolicyestimator_tests.cpp
+++ b/src/test/blockpolicyestimator_tests.cpp
@@ -43,6 +43,4 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
     CMutableTransaction tx;
-    tx.vin.resize(1);
-    tx.vin[0].scriptSig = garbage;
-    tx.vout.resize(1);
-    tx.vout[0].nValue=0LL;
+    tx.vin = {CTxIn{COutPoint{}, garbage}};
+    tx.vout = {CTxOut{0LL, CScript{}}};
     CFeeRate baseRate(basefee, GetVirtualTransactionSize(CTransaction(tx)));
diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp
index 6656e9a..58bb719 100644
--- a/src/test/coins_tests.cpp
+++ b/src/test/coins_tests.cpp
@@ -349,5 +349,4 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest)
             CMutableTransaction tx;
-            tx.vin.resize(1);
-            tx.vout.resize(1);
-            tx.vout[0].nValue = i; //Keep txs unique unless intended to duplicate
+            tx.vin = {CTxIn{}};
+            tx.vout = {CTxOut{i, CScript{}}};                         // Keep txs unique unless intended to duplicate
             tx.vout[0].scriptPubKey.assign(m_rng.rand32() & 0x3F, 0); // Random sizes so we can test memory usage accounting
diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp
index c54f355..e89b9b6 100644
--- a/src/test/descriptor_tests.cpp
+++ b/src/test/descriptor_tests.cpp
@@ -459,5 +459,4 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
                     spend.nLockTime = spender_nlocktime;
-                    spend.vin.resize(1);
-                    spend.vin[0].nSequence = spender_nsequence;
-                    spend.vout.resize(1);
+                    spend.vin = {CTxIn{COutPoint{}, CScript{}, spender_nsequence}};
+                    spend.vout = {CTxOut{}};
                     std::vector<CTxOut> utxos(1);
diff --git a/src/test/fuzz/cmpctblock.cpp b/src/test/fuzz/cmpctblock.cpp
index c4e9b5e..81ad694 100644
--- a/src/test/fuzz/cmpctblock.cpp
+++ b/src/test/fuzz/cmpctblock.cpp
@@ -245,8 +245,4 @@ FUZZ_TARGET(cmpctblock, .init = initialize_cmpctblock)
         CMutableTransaction coinbase_tx;
-        coinbase_tx.vin.resize(1);
-        coinbase_tx.vin[0].prevout.SetNull();
-        coinbase_tx.vin[0].scriptSig = CScript() << height << OP_0;
-        coinbase_tx.vout.resize(1);
-        coinbase_tx.vout[0].scriptPubKey = CScript() << OP_TRUE;
-        coinbase_tx.vout[0].nValue = COIN;
+        coinbase_tx.vin = {CTxIn{COutPoint{}, CScript{} << height << OP_0}};
+        coinbase_tx.vout = {CTxOut{COIN, CScript{} << OP_TRUE}};
         block->vtx.push_back(MakeTransactionRef(coinbase_tx));
diff --git a/src/test/fuzz/connect_block.cpp b/src/test/fuzz/connect_block.cpp
index 9aef9d2..97986a7 100644
--- a/src/test/fuzz/connect_block.cpp
+++ b/src/test/fuzz/connect_block.cpp
@@ -196,20 +196,12 @@ void AddExtraTxsToMempool(TestingSetup& setup)
         ctx.version = CTransaction::CURRENT_VERSION;
-        ctx.vin.resize(1);
         // CTxIn is spendable as g_spend_candidate_txins comes from early blocks whose
         // coinbases are mature.
-        ctx.vin[0] = g_spend_candidate_txins[i];
-        ctx.vout.resize(4);
+        ctx.vin = {g_spend_candidate_txins[i]};
         // Arbitrarily create various outputs of different kinds in the same tx.
-        // P2WSH
-        ctx.vout[0].nValue = CAmount(15 * COIN);
-        ctx.vout[0].scriptPubKey = P2WSH_OP_TRUE;
-        // P2SH
-        ctx.vout[1].nValue = CAmount(15 * COIN);
-        ctx.vout[1].scriptPubKey = P2SH_OP_TRUE;
-        // Taproot
-        ctx.vout[2].nValue = CAmount(10 * COIN);
-        ctx.vout[2].scriptPubKey = TAPROOT_OP_TRUE;
-        // Empty script
-        ctx.vout[3].nValue = CAmount(10 * COIN);
-        ctx.vout[3].scriptPubKey = CScript();
+        ctx.vout = {
+            CTxOut{CAmount(15 * COIN), P2WSH_OP_TRUE},
+            CTxOut{CAmount(15 * COIN), P2SH_OP_TRUE},
+            CTxOut{CAmount(10 * COIN), TAPROOT_OP_TRUE},
+            CTxOut{CAmount(10 * COIN), CScript{}},
+        };
 
@@ -286,13 +278,12 @@ CTransactionRef ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider,
     if (coinbase) {
-        // vin size is hardcoded.
-        tx.vin.resize(1);
-        tx.vin[0].prevout.SetNull();
+        CScript script_sig;
         if (fuzzed_data_provider.ConsumeBool()) {
             // 1/2 probability of a valid vin.
-            tx.vin[0].scriptSig = CScript() << target_height;
+            script_sig = CScript() << target_height;
         } else {
             // Read arbitrary data from input as scriptSig.
-            auto script_sig = ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100);
-            tx.vin[0].scriptSig.assign(script_sig.begin(), script_sig.end());
+            const auto script_bytes = ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100);
+            script_sig.assign(script_bytes.begin(), script_bytes.end());
         }
+        tx.vin = {CTxIn{COutPoint{}, std::move(script_sig)}};
     } else {
diff --git a/src/test/fuzz/p2p_headers_presync.cpp b/src/test/fuzz/p2p_headers_presync.cpp
index b57b864..bb4e2e5 100644
--- a/src/test/fuzz/p2p_headers_presync.cpp
+++ b/src/test/fuzz/p2p_headers_presync.cpp
@@ -136,6 +136,5 @@ CBlock ConsumeBlock(FuzzedDataProvider& fuzzed_data_provider, const uint256& pre
     CMutableTransaction tx;
-    tx.vin.resize(1);
-    tx.vout.resize(1);
-    tx.vout[0].nValue = 0;
-    tx.vin[0].scriptSig.resize(2);
+    const std::vector<unsigned char> script_sig_data(2, 0);
+    tx.vin = {CTxIn{COutPoint{}, CScript{script_sig_data.begin(), script_sig_data.end()}}};
+    tx.vout = {CTxOut{0, CScript{}}};
     block.vtx.push_back(MakeTransactionRef(tx));
diff --git a/src/test/fuzz/rbf.cpp b/src/test/fuzz/rbf.cpp
index 107a70a..68e31ef 100644
--- a/src/test/fuzz/rbf.cpp
+++ b/src/test/fuzz/rbf.cpp
@@ -133,5 +133,4 @@ FUZZ_TARGET(package_rbf, .init = initialize_package_rbf)
         CMutableTransaction parent;
-        parent.vin.resize(1);
-        parent.vin[0].prevout = g_outpoints.at(iter++);
-        parent.vout.emplace_back(0, CScript());
+        parent.vin = {CTxIn{g_outpoints.at(iter++)}};
+        parent.vout = {CTxOut{0, CScript{}}};
 
diff --git a/src/test/mempool_fee_estimator_tests.cpp b/src/test/mempool_fee_estimator_tests.cpp
index d35ea41..9fe1f29 100644
--- a/src/test/mempool_fee_estimator_tests.cpp
+++ b/src/test/mempool_fee_estimator_tests.cpp
@@ -30,9 +30,4 @@ static inline CTransactionRef MakeRandomTx()
     auto tx = CMutableTransaction();
-    tx.vin.resize(1);
-    tx.vout.resize(1);
-    tx.vin[0].prevout.hash = Txid::FromUint256(rng.rand256());
-    tx.vin[0].prevout.n = 0;
-    tx.vin[0].scriptSig << OP_TRUE;
-    tx.vout[0].scriptPubKey = CScript() << OP_TRUE;
-    tx.vout[0].nValue = COIN;
+    tx.vin = {CTxIn{Txid::FromUint256(rng.rand256()), 0, CScript{} << OP_TRUE}};
+    tx.vout = {CTxOut{COIN, CScript{} << OP_TRUE}};
     return MakeTransactionRef(tx);
diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp
index ae2006d..aa0df02 100644
--- a/src/test/miner_tests.cpp
+++ b/src/test/miner_tests.cpp
@@ -467,5 +467,4 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
         // block size > limit
-        tx.vin.resize(1);
-        tx.vout.resize(1);
-        tx.vout[0].nValue = BLOCKSUBSIDY;
+        tx.vin = {CTxIn{}};
+        tx.vout = {CTxOut{BLOCKSUBSIDY, CScript{}}};
         // 36 * (520char + DROP) + OP_1 = 18757 bytes
@@ -513,6 +512,6 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
         tx.vin[0].prevout.hash = hash;
-        tx.vin.resize(2);
-        tx.vin[1].scriptSig = CScript() << OP_1;
-        tx.vin[1].prevout.hash = txFirst[0]->GetHash();
-        tx.vin[1].prevout.n = 0;
+        tx.vin = {
+            tx.vin[0],
+            CTxIn{COutPoint{txFirst[0]->GetHash(), 0}, CScript{} << OP_1},
+        };
         tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; // First txn output + fresh coinbase - new txn fee
@@ -528,5 +527,3 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
         // coinbase in tx_mempool, template creation fails
-        tx.vin.resize(1);
-        tx.vin[0].prevout.SetNull();
-        tx.vin[0].scriptSig = CScript() << OP_0 << OP_1;
+        tx.vin = {CTxIn{COutPoint{}, CScript{} << OP_0 << OP_1}};
         tx.vout[0].nValue = 0;
@@ -625,12 +622,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std::
     tx.version = 2;
-    tx.vin.resize(1);
+    tx.vin = {CTxIn{COutPoint{txFirst[0]->GetHash(), 0}, CScript{} << OP_1,
+                    static_cast<uint32_t>(m_node.chainman->ActiveChain().Tip()->nHeight + 1)}};
     prevheights.resize(1);
-    tx.vin[0].prevout.hash = txFirst[0]->GetHash(); // only 1 transaction
-    tx.vin[0].prevout.n = 0;
-    tx.vin[0].scriptSig = CScript() << OP_1;
-    tx.vin[0].nSequence = m_node.chainman->ActiveChain().Tip()->nHeight + 1; // txFirst[0] is the 2nd block
     prevheights[0] = baseheight + 1;
-    tx.vout.resize(1);
-    tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
-    tx.vout[0].scriptPubKey = CScript() << OP_1;
+    tx.vout = {CTxOut{BLOCKSUBSIDY - HIGHFEE, CScript{} << OP_1}};
     tx.nLockTime = 0;
@@ -888,4 +880,3 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
             txCoinbase.vin[0].scriptSig = CScript{} << (current_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();
+            txCoinbase.vout = {CTxOut{txCoinbase.vout[0].nValue, CScript{}}}; // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this)
             block.vtx[0] = MakeTransactionRef(txCoinbase);
diff --git a/src/test/orphanage_tests.cpp b/src/test/orphanage_tests.cpp
index c09f987..cdedec7 100644
--- a/src/test/orphanage_tests.cpp
+++ b/src/test/orphanage_tests.cpp
@@ -49,7 +49,6 @@ static CTransactionRef MakeTransactionSpending(const std::vector<COutPoint>& out
     tx.vin[0].scriptWitness.stack.push_back({1});
-    tx.vout.resize(2);
-    tx.vout[0].nValue = CENT;
-    tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
-    tx.vout[1].nValue = 3 * CENT;
-    tx.vout[1].scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(key.GetPubKey()));
+    tx.vout = {
+        CTxOut{CENT, GetScriptForDestination(PKHash(key.GetPubKey()))},
+        CTxOut{3 * CENT, GetScriptForDestination(WitnessV0KeyHash(key.GetPubKey()))},
+    };
     return MakeTransactionRef(tx);
@@ -442,9 +441,4 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
         CMutableTransaction tx;
-        tx.vin.resize(1);
-        tx.vin[0].prevout.n = 0;
-        tx.vin[0].prevout.hash = Txid::FromUint256(m_rng.rand256());
-        tx.vin[0].scriptSig << OP_1;
-        tx.vout.resize(1);
-        tx.vout[0].nValue = i*CENT;
-        tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
+        tx.vin = {CTxIn{Txid::FromUint256(m_rng.rand256()), 0, CScript{} << OP_1}};
+        tx.vout = {CTxOut{i * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}};
 
@@ -461,8 +455,4 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
         CMutableTransaction tx;
-        tx.vin.resize(1);
-        tx.vin[0].prevout.n = 0;
-        tx.vin[0].prevout.hash = txPrev->GetHash();
-        tx.vout.resize(1);
-        tx.vout[0].nValue = i*CENT;
-        tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
+        tx.vin = {CTxIn{txPrev->GetHash(), 0}};
+        tx.vout = {CTxOut{i * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}};
         SignatureData empty;
@@ -481,5 +471,3 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans)
         CMutableTransaction tx;
-        tx.vout.resize(1);
-        tx.vout[0].nValue = 1*CENT;
-        tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
+        tx.vout = {CTxOut{1 * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}};
         tx.vin.resize(2777);
diff --git a/src/test/private_broadcast_tests.cpp b/src/test/private_broadcast_tests.cpp
index cf1c7d0..6c5bd3f 100644
--- a/src/test/private_broadcast_tests.cpp
+++ b/src/test/private_broadcast_tests.cpp
@@ -31,4 +31,3 @@ static CTransactionRef MakeDummyTx(uint32_t id, size_t num_witness)
     CMutableTransaction mtx;
-    mtx.vin.resize(1);
-    mtx.vin[0].nSequence = id;
+    mtx.vin = {CTxIn{COutPoint{}, CScript{}, id}};
     if (num_witness > 0) {
diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp
index a0d222e..598edbc 100644
--- a/src/test/transaction_tests.cpp
+++ b/src/test/transaction_tests.cpp
@@ -419,8 +419,4 @@ static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const
     outputm.version = 1;
-    outputm.vin.resize(1);
-    outputm.vin[0].prevout.SetNull();
-    outputm.vin[0].scriptSig = CScript();
-    outputm.vout.resize(1);
-    outputm.vout[0].nValue = 1;
-    outputm.vout[0].scriptPubKey = outscript;
+    outputm.vin = {CTxIn{COutPoint{}, CScript{}}};
+    outputm.vout = {CTxOut{1, outscript}};
     DataStream ssout;
@@ -435,8 +431,4 @@ static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const
     inputm.version = 1;
-    inputm.vin.resize(1);
-    inputm.vin[0].prevout.hash = output->GetHash();
-    inputm.vin[0].prevout.n = 0;
-    inputm.vout.resize(1);
-    inputm.vout[0].nValue = 1;
-    inputm.vout[0].scriptPubKey = CScript();
+    inputm.vin = {CTxIn{output->GetHash(), 0}};
+    inputm.vout = {CTxOut{1, CScript{}}};
     SignatureData empty;
@@ -754,10 +746,5 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     CMutableTransaction t;
-    t.vin.resize(1);
-    t.vin[0].prevout.hash = dummyTransactions[0].GetHash();
-    t.vin[0].prevout.n = 1;
-    t.vin[0].scriptSig << std::vector<unsigned char>(65, 0);
-    t.vout.resize(1);
-    t.vout[0].nValue = 90*CENT;
     CKey key = GenerateRandomKey();
-    t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
+    t.vin = {CTxIn{COutPoint{dummyTransactions[0].GetHash(), 1}, CScript{} << std::vector<unsigned char>(65, 0)}};
+    t.vout = {CTxOut{90 * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}};
 
@@ -848,4 +835,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     // TxoutType::NULL_DATA w/o PUSHDATA
-    t.vout.resize(1);
-    t.vout[0].scriptPubKey = CScript() << OP_RETURN;
+    t.vout = {CTxOut{0, CScript{} << OP_RETURN}};
     CheckIsStandard(t);
@@ -853,19 +839,14 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     // Multiple TxoutType::NULL_DATA are permitted
-    t.vout.resize(2);
-    t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
-    t.vout[0].nValue = 0;
-    t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
-    t.vout[1].nValue = 0;
+    const CScript null_data_script{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex};
+    t.vout = {CTxOut{0, null_data_script}, CTxOut{0, null_data_script}};
     CheckIsStandard(t);
 
-    t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
-    t.vout[1].scriptPubKey = CScript() << OP_RETURN;
+    t.vout = {CTxOut{0, null_data_script}, CTxOut{0, CScript{} << OP_RETURN}};
     CheckIsStandard(t);
 
-    t.vout[0].scriptPubKey = CScript() << OP_RETURN;
-    t.vout[1].scriptPubKey = CScript() << OP_RETURN;
+    t.vout = {CTxOut{0, CScript{} << OP_RETURN}, CTxOut{0, CScript{} << OP_RETURN}};
     CheckIsStandard(t);
 
-    t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
-    t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex;
+    const CScript datacarrier_script{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex};
+    t.vout = {CTxOut{0, datacarrier_script}, CTxOut{0, datacarrier_script}};
     const auto datacarrier_size = t.vout[0].scriptPubKey.size() + t.vout[1].scriptPubKey.size();
@@ -876,5 +857,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     // Check large scriptSig (non-standard if size is >1650 bytes)
-    t.vout.resize(1);
-    t.vout[0].nValue = MAX_MONEY;
-    t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey()));
+    t.vout = {CTxOut{MAX_MONEY, GetScriptForDestination(PKHash(key.GetPubKey()))}};
     // OP_PUSHDATA2 with len (3 bytes) + data (1647 bytes) = 1650 bytes
@@ -920,4 +899,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     // Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT)
-    t.vin.clear();
-    t.vin.resize(2438); // size per input (empty scriptSig): 41 bytes
+    t.vin = std::vector<CTxIn>(2438);                                                     // size per input (empty scriptSig): 41 bytes
     t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(19, 0); // output size: 30 bytes
@@ -939,4 +917,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
     t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1
-    t.vin.resize(1);
-    t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0);
+    t.vin = {CTxIn{COutPoint{}, CScript{} << std::vector<unsigned char>(65, 0)}};
     CheckIsStandard(t);
diff --git a/src/test/txospenderindex_tests.cpp b/src/test/txospenderindex_tests.cpp
index 368b456..7436358 100644
--- a/src/test/txospenderindex_tests.cpp
+++ b/src/test/txospenderindex_tests.cpp
@@ -31,8 +31,4 @@ BOOST_FIXTURE_TEST_CASE(txospenderindex_initial_sync, TestChain100Setup)
         spender[i].version = 1;
-        spender[i].vin.resize(1);
-        spender[i].vin[0].prevout.hash = spent[i].hash;
-        spender[i].vin[0].prevout.n = spent[i].n;
-        spender[i].vout.resize(1);
-        spender[i].vout[0].nValue = coinbase_tx->GetValueOut();
-        spender[i].vout[0].scriptPubKey = coinbase_script;
+        spender[i].vin = {CTxIn{spent[i]}};
+        spender[i].vout = {CTxOut{coinbase_tx->GetValueOut(), coinbase_script}};
 
diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp
index 2a4f213..4b63e79 100644
--- a/src/test/txvalidation_tests.cpp
+++ b/src/test/txvalidation_tests.cpp
@@ -32,7 +32,4 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup)
     coinbaseTx.version = 1;
-    coinbaseTx.vin.resize(1);
-    coinbaseTx.vout.resize(1);
-    coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL;
-    coinbaseTx.vout[0].nValue = 1 * CENT;
-    coinbaseTx.vout[0].scriptPubKey = scriptPubKey;
+    coinbaseTx.vin = {CTxIn{COutPoint{}, CScript{} << OP_11 << OP_EQUAL}};
+    coinbaseTx.vout = {CTxOut{1 * CENT, scriptPubKey}};
 
@@ -472,5 +469,3 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup)
         }
-        mtx_many_sigops.vout.resize(1);
-        mtx_many_sigops.vout.back().scriptPubKey = CScript() << OP_TRUE;
-        mtx_many_sigops.vout.back().nValue = 10000;
+        mtx_many_sigops.vout = {CTxOut{10000, CScript{} << OP_TRUE}};
         auto tx_many_sigops{MakeTransactionRef(mtx_many_sigops)};
diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp
index 6757f39..32180cb 100644
--- a/src/test/validation_block_tests.cpp
+++ b/src/test/validation_block_tests.cpp
@@ -95,6 +95,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash)
     CMutableTransaction txCoinbase(*pblock->vtx[0]);
-    txCoinbase.vout.resize(2);
-    txCoinbase.vout[1].scriptPubKey = P2WSH_OP_TRUE;
-    txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue;
-    txCoinbase.vout[0].nValue = 0;
+    const CTxOut original_coinbase_output{txCoinbase.vout[0]};
+    txCoinbase.vout = {
+        CTxOut{0, original_coinbase_output.scriptPubKey},
+        CTxOut{original_coinbase_output.nValue, P2WSH_OP_TRUE},
+    };
     txCoinbase.vin[0].scriptWitness.SetNull();
@@ -375,7 +376,3 @@ BOOST_AUTO_TEST_CASE(witness_commitment_index)
     CMutableTransaction txCoinbase(*pblock.vtx[0]);
-    txCoinbase.vout.resize(4);
-    txCoinbase.vout[0] = witness;
-    txCoinbase.vout[1] = witness;
-    txCoinbase.vout[2] = min_plus_one;
-    txCoinbase.vout[3] = invalid;
+    txCoinbase.vout = {witness, witness, min_plus_one, invalid};
     pblock.vtx[0] = MakeTransactionRef(std::move(txCoinbase));
diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp
index 268529f..1537756 100644
--- a/src/test/validation_tests.cpp
+++ b/src/test/validation_tests.cpp
@@ -174,4 +174,12 @@ BOOST_AUTO_TEST_CASE(block_malleation)
     auto create_coinbase_tx = [](bool include_witness = false) {
+        CScript commitment;
+        commitment.resize(MINIMUM_WITNESS_COMMITMENT);
+        commitment[0] = OP_RETURN;
+        commitment[1] = 0x24;
+        commitment[2] = 0xaa;
+        commitment[3] = 0x21;
+        commitment[4] = 0xa9;
+        commitment[5] = 0xed;
         CMutableTransaction coinbase;
-        coinbase.vin.resize(1);
+        coinbase.vin = {CTxIn{}};
         if (include_witness) {
@@ -180,11 +188,3 @@ BOOST_AUTO_TEST_CASE(block_malleation)
         }
-
-        coinbase.vout.resize(1);
-        coinbase.vout[0].scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
-        coinbase.vout[0].scriptPubKey[0] = OP_RETURN;
-        coinbase.vout[0].scriptPubKey[1] = 0x24;
-        coinbase.vout[0].scriptPubKey[2] = 0xaa;
-        coinbase.vout[0].scriptPubKey[3] = 0x21;
-        coinbase.vout[0].scriptPubKey[4] = 0xa9;
-        coinbase.vout[0].scriptPubKey[5] = 0xed;
+        coinbase.vout = {CTxOut{-1, commitment}};
 
@@ -246,5 +246,6 @@ BOOST_AUTO_TEST_CASE(block_malleation)
             CMutableTransaction mtx;
-            mtx.vin.resize(1);
-            mtx.vout.resize(1);
-            mtx.vout[0].scriptPubKey.resize(4);
+            CScript script_pub_key;
+            script_pub_key.resize(4);
+            mtx.vin = {CTxIn{}};
+            mtx.vout = {CTxOut{-1, script_pub_key}};
             block.vtx.push_back(MakeTransactionRef(mtx));
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index fdce22a..c14119c 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -915,4 +915,3 @@ BOOST_AUTO_TEST_CASE(effective_value_test)
     CMutableTransaction tx;
-    tx.vout.resize(1);
-    tx.vout[nInput].nValue = nValue;
+    tx.vout = {CTxOut{nValue, CScript{}}};
 
diff --git a/src/wallet/test/fuzz/spend.cpp b/src/wallet/test/fuzz/spend.cpp
index 395ba3d..7c783f4 100644
--- a/src/wallet/test/fuzz/spend.cpp
+++ b/src/wallet/test/fuzz/spend.cpp
@@ -80,3 +80,2 @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup)
         tx.nLockTime = next_locktime++;
-        tx.vout.resize(1);
         CAmount n_value{ConsumeMoney(fuzzed_data_provider)};
@@ -84,4 +83,3 @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup)
         if (all_values > MAX_MONEY) return;
-        tx.vout[0].nValue = n_value;
-        tx.vout[0].scriptPubKey = GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider));
+        tx.vout = {CTxOut{n_value, GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider))}};
         LOCK(fuzzed_wallet.wallet->cs_wallet);
diff --git a/src/wallet/test/group_outputs_tests.cpp b/src/wallet/test/group_outputs_tests.cpp
index c1fe72b..767ef9b 100644
--- a/src/wallet/test/group_outputs_tests.cpp
+++ b/src/wallet/test/group_outputs_tests.cpp
@@ -37,5 +37,3 @@ static void addCoin(CoinsResult& coins,
     tx.nLockTime = nextLockTime++;        // so all transactions get different hashes
-    tx.vout.resize(1);
-    tx.vout[0].nValue = nValue;
-    tx.vout[0].scriptPubKey = GetScriptForDestination(dest);
+    tx.vout = {CTxOut{nValue, GetScriptForDestination(dest)}};
 
I think it would be good to wrap up this project in a few pull requests and just focus on the important ones: * Fixup the places that do a vin/vout `resize()` in combination with immediately following field-assignment: E.g. `tx.vout.resize(1); tx.vout[0].nValue=...`. Everything else is probably best left as-is style-wise for now to avoid code and review churn. So I think the diff would be something like this: (unreviewed slop, need to drop the changes that are already in reviewed pulls, also should use multi-line initializer lists with trailing comma): <details><summary>a diff</summary> ```diff diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index ffb9058..9d2c7ca 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -23,6 +23,6 @@ static CMutableTransaction BuildTransactionTestCase() { CMutableTransaction tx; - tx.vin.resize(1); - tx.vin[0].scriptSig.resize(10); - tx.vout.resize(1); - tx.vout[0].nValue = 42; + CScript script_sig; + script_sig.resize(10); + tx.vin = {CTxIn{COutPoint{}, script_sig}}; + tx.vout = {CTxOut{42, CScript{}}}; return tx; diff --git a/src/test/blockpolicyestimator_tests.cpp b/src/test/blockpolicyestimator_tests.cpp index 0c2cec6..2784479 100644 --- a/src/test/blockpolicyestimator_tests.cpp +++ b/src/test/blockpolicyestimator_tests.cpp @@ -43,6 +43,4 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates) CMutableTransaction tx; - tx.vin.resize(1); - tx.vin[0].scriptSig = garbage; - tx.vout.resize(1); - tx.vout[0].nValue=0LL; + tx.vin = {CTxIn{COutPoint{}, garbage}}; + tx.vout = {CTxOut{0LL, CScript{}}}; CFeeRate baseRate(basefee, GetVirtualTransactionSize(CTransaction(tx))); diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 6656e9a..58bb719 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -349,5 +349,4 @@ BOOST_FIXTURE_TEST_CASE(updatecoins_simulation_test, UpdateTest) CMutableTransaction tx; - tx.vin.resize(1); - tx.vout.resize(1); - tx.vout[0].nValue = i; //Keep txs unique unless intended to duplicate + tx.vin = {CTxIn{}}; + tx.vout = {CTxOut{i, CScript{}}}; // Keep txs unique unless intended to duplicate tx.vout[0].scriptPubKey.assign(m_rng.rand32() & 0x3F, 0); // Random sizes so we can test memory usage accounting diff --git a/src/test/descriptor_tests.cpp b/src/test/descriptor_tests.cpp index c54f355..e89b9b6 100644 --- a/src/test/descriptor_tests.cpp +++ b/src/test/descriptor_tests.cpp @@ -459,5 +459,4 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int spend.nLockTime = spender_nlocktime; - spend.vin.resize(1); - spend.vin[0].nSequence = spender_nsequence; - spend.vout.resize(1); + spend.vin = {CTxIn{COutPoint{}, CScript{}, spender_nsequence}}; + spend.vout = {CTxOut{}}; std::vector<CTxOut> utxos(1); diff --git a/src/test/fuzz/cmpctblock.cpp b/src/test/fuzz/cmpctblock.cpp index c4e9b5e..81ad694 100644 --- a/src/test/fuzz/cmpctblock.cpp +++ b/src/test/fuzz/cmpctblock.cpp @@ -245,8 +245,4 @@ FUZZ_TARGET(cmpctblock, .init = initialize_cmpctblock) CMutableTransaction coinbase_tx; - coinbase_tx.vin.resize(1); - coinbase_tx.vin[0].prevout.SetNull(); - coinbase_tx.vin[0].scriptSig = CScript() << height << OP_0; - coinbase_tx.vout.resize(1); - coinbase_tx.vout[0].scriptPubKey = CScript() << OP_TRUE; - coinbase_tx.vout[0].nValue = COIN; + coinbase_tx.vin = {CTxIn{COutPoint{}, CScript{} << height << OP_0}}; + coinbase_tx.vout = {CTxOut{COIN, CScript{} << OP_TRUE}}; block->vtx.push_back(MakeTransactionRef(coinbase_tx)); diff --git a/src/test/fuzz/connect_block.cpp b/src/test/fuzz/connect_block.cpp index 9aef9d2..97986a7 100644 --- a/src/test/fuzz/connect_block.cpp +++ b/src/test/fuzz/connect_block.cpp @@ -196,20 +196,12 @@ void AddExtraTxsToMempool(TestingSetup& setup) ctx.version = CTransaction::CURRENT_VERSION; - ctx.vin.resize(1); // CTxIn is spendable as g_spend_candidate_txins comes from early blocks whose // coinbases are mature. - ctx.vin[0] = g_spend_candidate_txins[i]; - ctx.vout.resize(4); + ctx.vin = {g_spend_candidate_txins[i]}; // Arbitrarily create various outputs of different kinds in the same tx. - // P2WSH - ctx.vout[0].nValue = CAmount(15 * COIN); - ctx.vout[0].scriptPubKey = P2WSH_OP_TRUE; - // P2SH - ctx.vout[1].nValue = CAmount(15 * COIN); - ctx.vout[1].scriptPubKey = P2SH_OP_TRUE; - // Taproot - ctx.vout[2].nValue = CAmount(10 * COIN); - ctx.vout[2].scriptPubKey = TAPROOT_OP_TRUE; - // Empty script - ctx.vout[3].nValue = CAmount(10 * COIN); - ctx.vout[3].scriptPubKey = CScript(); + ctx.vout = { + CTxOut{CAmount(15 * COIN), P2WSH_OP_TRUE}, + CTxOut{CAmount(15 * COIN), P2SH_OP_TRUE}, + CTxOut{CAmount(10 * COIN), TAPROOT_OP_TRUE}, + CTxOut{CAmount(10 * COIN), CScript{}}, + }; @@ -286,13 +278,12 @@ CTransactionRef ConsumeTransaction(FuzzedDataProvider& fuzzed_data_provider, if (coinbase) { - // vin size is hardcoded. - tx.vin.resize(1); - tx.vin[0].prevout.SetNull(); + CScript script_sig; if (fuzzed_data_provider.ConsumeBool()) { // 1/2 probability of a valid vin. - tx.vin[0].scriptSig = CScript() << target_height; + script_sig = CScript() << target_height; } else { // Read arbitrary data from input as scriptSig. - auto script_sig = ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100); - tx.vin[0].scriptSig.assign(script_sig.begin(), script_sig.end()); + const auto script_bytes = ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100); + script_sig.assign(script_bytes.begin(), script_bytes.end()); } + tx.vin = {CTxIn{COutPoint{}, std::move(script_sig)}}; } else { diff --git a/src/test/fuzz/p2p_headers_presync.cpp b/src/test/fuzz/p2p_headers_presync.cpp index b57b864..bb4e2e5 100644 --- a/src/test/fuzz/p2p_headers_presync.cpp +++ b/src/test/fuzz/p2p_headers_presync.cpp @@ -136,6 +136,5 @@ CBlock ConsumeBlock(FuzzedDataProvider& fuzzed_data_provider, const uint256& pre CMutableTransaction tx; - tx.vin.resize(1); - tx.vout.resize(1); - tx.vout[0].nValue = 0; - tx.vin[0].scriptSig.resize(2); + const std::vector<unsigned char> script_sig_data(2, 0); + tx.vin = {CTxIn{COutPoint{}, CScript{script_sig_data.begin(), script_sig_data.end()}}}; + tx.vout = {CTxOut{0, CScript{}}}; block.vtx.push_back(MakeTransactionRef(tx)); diff --git a/src/test/fuzz/rbf.cpp b/src/test/fuzz/rbf.cpp index 107a70a..68e31ef 100644 --- a/src/test/fuzz/rbf.cpp +++ b/src/test/fuzz/rbf.cpp @@ -133,5 +133,4 @@ FUZZ_TARGET(package_rbf, .init = initialize_package_rbf) CMutableTransaction parent; - parent.vin.resize(1); - parent.vin[0].prevout = g_outpoints.at(iter++); - parent.vout.emplace_back(0, CScript()); + parent.vin = {CTxIn{g_outpoints.at(iter++)}}; + parent.vout = {CTxOut{0, CScript{}}}; diff --git a/src/test/mempool_fee_estimator_tests.cpp b/src/test/mempool_fee_estimator_tests.cpp index d35ea41..9fe1f29 100644 --- a/src/test/mempool_fee_estimator_tests.cpp +++ b/src/test/mempool_fee_estimator_tests.cpp @@ -30,9 +30,4 @@ static inline CTransactionRef MakeRandomTx() auto tx = CMutableTransaction(); - tx.vin.resize(1); - tx.vout.resize(1); - tx.vin[0].prevout.hash = Txid::FromUint256(rng.rand256()); - tx.vin[0].prevout.n = 0; - tx.vin[0].scriptSig << OP_TRUE; - tx.vout[0].scriptPubKey = CScript() << OP_TRUE; - tx.vout[0].nValue = COIN; + tx.vin = {CTxIn{Txid::FromUint256(rng.rand256()), 0, CScript{} << OP_TRUE}}; + tx.vout = {CTxOut{COIN, CScript{} << OP_TRUE}}; return MakeTransactionRef(tx); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index ae2006d..aa0df02 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -467,5 +467,4 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: // block size > limit - tx.vin.resize(1); - tx.vout.resize(1); - tx.vout[0].nValue = BLOCKSUBSIDY; + tx.vin = {CTxIn{}}; + tx.vout = {CTxOut{BLOCKSUBSIDY, CScript{}}}; // 36 * (520char + DROP) + OP_1 = 18757 bytes @@ -513,6 +512,6 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: tx.vin[0].prevout.hash = hash; - tx.vin.resize(2); - tx.vin[1].scriptSig = CScript() << OP_1; - tx.vin[1].prevout.hash = txFirst[0]->GetHash(); - tx.vin[1].prevout.n = 0; + tx.vin = { + tx.vin[0], + CTxIn{COutPoint{txFirst[0]->GetHash(), 0}, CScript{} << OP_1}, + }; tx.vout[0].nValue = tx.vout[0].nValue + BLOCKSUBSIDY - HIGHERFEE; // First txn output + fresh coinbase - new txn fee @@ -528,5 +527,3 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: // coinbase in tx_mempool, template creation fails - tx.vin.resize(1); - tx.vin[0].prevout.SetNull(); - tx.vin[0].scriptSig = CScript() << OP_0 << OP_1; + tx.vin = {CTxIn{COutPoint{}, CScript{} << OP_0 << OP_1}}; tx.vout[0].nValue = 0; @@ -625,12 +622,7 @@ void MinerTestingSetup::TestBasicMining(const CScript& scriptPubKey, const std:: tx.version = 2; - tx.vin.resize(1); + tx.vin = {CTxIn{COutPoint{txFirst[0]->GetHash(), 0}, CScript{} << OP_1, + static_cast<uint32_t>(m_node.chainman->ActiveChain().Tip()->nHeight + 1)}}; prevheights.resize(1); - tx.vin[0].prevout.hash = txFirst[0]->GetHash(); // only 1 transaction - tx.vin[0].prevout.n = 0; - tx.vin[0].scriptSig = CScript() << OP_1; - tx.vin[0].nSequence = m_node.chainman->ActiveChain().Tip()->nHeight + 1; // txFirst[0] is the 2nd block prevheights[0] = baseheight + 1; - tx.vout.resize(1); - tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE; - tx.vout[0].scriptPubKey = CScript() << OP_1; + tx.vout = {CTxOut{BLOCKSUBSIDY - HIGHFEE, CScript{} << OP_1}}; tx.nLockTime = 0; @@ -888,4 +880,3 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) txCoinbase.vin[0].scriptSig = CScript{} << (current_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(); + txCoinbase.vout = {CTxOut{txCoinbase.vout[0].nValue, CScript{}}}; // Ignore the (optional) segwit commitment added by CreateNewBlock (as the hardcoded nonces don't account for this) block.vtx[0] = MakeTransactionRef(txCoinbase); diff --git a/src/test/orphanage_tests.cpp b/src/test/orphanage_tests.cpp index c09f987..cdedec7 100644 --- a/src/test/orphanage_tests.cpp +++ b/src/test/orphanage_tests.cpp @@ -49,7 +49,6 @@ static CTransactionRef MakeTransactionSpending(const std::vector<COutPoint>& out tx.vin[0].scriptWitness.stack.push_back({1}); - tx.vout.resize(2); - tx.vout[0].nValue = CENT; - tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); - tx.vout[1].nValue = 3 * CENT; - tx.vout[1].scriptPubKey = GetScriptForDestination(WitnessV0KeyHash(key.GetPubKey())); + tx.vout = { + CTxOut{CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}, + CTxOut{3 * CENT, GetScriptForDestination(WitnessV0KeyHash(key.GetPubKey()))}, + }; return MakeTransactionRef(tx); @@ -442,9 +441,4 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) CMutableTransaction tx; - tx.vin.resize(1); - tx.vin[0].prevout.n = 0; - tx.vin[0].prevout.hash = Txid::FromUint256(m_rng.rand256()); - tx.vin[0].scriptSig << OP_1; - tx.vout.resize(1); - tx.vout[0].nValue = i*CENT; - tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); + tx.vin = {CTxIn{Txid::FromUint256(m_rng.rand256()), 0, CScript{} << OP_1}}; + tx.vout = {CTxOut{i * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}}; @@ -461,8 +455,4 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) CMutableTransaction tx; - tx.vin.resize(1); - tx.vin[0].prevout.n = 0; - tx.vin[0].prevout.hash = txPrev->GetHash(); - tx.vout.resize(1); - tx.vout[0].nValue = i*CENT; - tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); + tx.vin = {CTxIn{txPrev->GetHash(), 0}}; + tx.vout = {CTxOut{i * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}}; SignatureData empty; @@ -481,5 +471,3 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) CMutableTransaction tx; - tx.vout.resize(1); - tx.vout[0].nValue = 1*CENT; - tx.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); + tx.vout = {CTxOut{1 * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}}; tx.vin.resize(2777); diff --git a/src/test/private_broadcast_tests.cpp b/src/test/private_broadcast_tests.cpp index cf1c7d0..6c5bd3f 100644 --- a/src/test/private_broadcast_tests.cpp +++ b/src/test/private_broadcast_tests.cpp @@ -31,4 +31,3 @@ static CTransactionRef MakeDummyTx(uint32_t id, size_t num_witness) CMutableTransaction mtx; - mtx.vin.resize(1); - mtx.vin[0].nSequence = id; + mtx.vin = {CTxIn{COutPoint{}, CScript{}, id}}; if (num_witness > 0) { diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index a0d222e..598edbc 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -419,8 +419,4 @@ static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const outputm.version = 1; - outputm.vin.resize(1); - outputm.vin[0].prevout.SetNull(); - outputm.vin[0].scriptSig = CScript(); - outputm.vout.resize(1); - outputm.vout[0].nValue = 1; - outputm.vout[0].scriptPubKey = outscript; + outputm.vin = {CTxIn{COutPoint{}, CScript{}}}; + outputm.vout = {CTxOut{1, outscript}}; DataStream ssout; @@ -435,8 +431,4 @@ static void CreateCreditAndSpend(const FillableSigningProvider& keystore, const inputm.version = 1; - inputm.vin.resize(1); - inputm.vin[0].prevout.hash = output->GetHash(); - inputm.vin[0].prevout.n = 0; - inputm.vout.resize(1); - inputm.vout[0].nValue = 1; - inputm.vout[0].scriptPubKey = CScript(); + inputm.vin = {CTxIn{output->GetHash(), 0}}; + inputm.vout = {CTxOut{1, CScript{}}}; SignatureData empty; @@ -754,10 +746,5 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) CMutableTransaction t; - t.vin.resize(1); - t.vin[0].prevout.hash = dummyTransactions[0].GetHash(); - t.vin[0].prevout.n = 1; - t.vin[0].scriptSig << std::vector<unsigned char>(65, 0); - t.vout.resize(1); - t.vout[0].nValue = 90*CENT; CKey key = GenerateRandomKey(); - t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); + t.vin = {CTxIn{COutPoint{dummyTransactions[0].GetHash(), 1}, CScript{} << std::vector<unsigned char>(65, 0)}}; + t.vout = {CTxOut{90 * CENT, GetScriptForDestination(PKHash(key.GetPubKey()))}}; @@ -848,4 +835,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // TxoutType::NULL_DATA w/o PUSHDATA - t.vout.resize(1); - t.vout[0].scriptPubKey = CScript() << OP_RETURN; + t.vout = {CTxOut{0, CScript{} << OP_RETURN}}; CheckIsStandard(t); @@ -853,19 +839,14 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // Multiple TxoutType::NULL_DATA are permitted - t.vout.resize(2); - t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex; - t.vout[0].nValue = 0; - t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex; - t.vout[1].nValue = 0; + const CScript null_data_script{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex}; + t.vout = {CTxOut{0, null_data_script}, CTxOut{0, null_data_script}}; CheckIsStandard(t); - t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex; - t.vout[1].scriptPubKey = CScript() << OP_RETURN; + t.vout = {CTxOut{0, null_data_script}, CTxOut{0, CScript{} << OP_RETURN}}; CheckIsStandard(t); - t.vout[0].scriptPubKey = CScript() << OP_RETURN; - t.vout[1].scriptPubKey = CScript() << OP_RETURN; + t.vout = {CTxOut{0, CScript{} << OP_RETURN}, CTxOut{0, CScript{} << OP_RETURN}}; CheckIsStandard(t); - t.vout[0].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex; - t.vout[1].scriptPubKey = CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex; + const CScript datacarrier_script{CScript() << OP_RETURN << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef3804678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38"_hex}; + t.vout = {CTxOut{0, datacarrier_script}, CTxOut{0, datacarrier_script}}; const auto datacarrier_size = t.vout[0].scriptPubKey.size() + t.vout[1].scriptPubKey.size(); @@ -876,5 +857,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // Check large scriptSig (non-standard if size is >1650 bytes) - t.vout.resize(1); - t.vout[0].nValue = MAX_MONEY; - t.vout[0].scriptPubKey = GetScriptForDestination(PKHash(key.GetPubKey())); + t.vout = {CTxOut{MAX_MONEY, GetScriptForDestination(PKHash(key.GetPubKey()))}}; // OP_PUSHDATA2 with len (3 bytes) + data (1647 bytes) = 1650 bytes @@ -920,4 +899,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) // Check tx-size (non-standard if transaction weight is > MAX_STANDARD_TX_WEIGHT) - t.vin.clear(); - t.vin.resize(2438); // size per input (empty scriptSig): 41 bytes + t.vin = std::vector<CTxIn>(2438); // size per input (empty scriptSig): 41 bytes t.vout[0].scriptPubKey = CScript() << OP_RETURN << std::vector<unsigned char>(19, 0); // output size: 30 bytes @@ -939,4 +917,3 @@ BOOST_AUTO_TEST_CASE(test_IsStandard) t.vout[0].scriptPubKey = GetScriptForMultisig(1, {key.GetPubKey()}); // simple 1-of-1 - t.vin.resize(1); - t.vin[0].scriptSig = CScript() << std::vector<unsigned char>(65, 0); + t.vin = {CTxIn{COutPoint{}, CScript{} << std::vector<unsigned char>(65, 0)}}; CheckIsStandard(t); diff --git a/src/test/txospenderindex_tests.cpp b/src/test/txospenderindex_tests.cpp index 368b456..7436358 100644 --- a/src/test/txospenderindex_tests.cpp +++ b/src/test/txospenderindex_tests.cpp @@ -31,8 +31,4 @@ BOOST_FIXTURE_TEST_CASE(txospenderindex_initial_sync, TestChain100Setup) spender[i].version = 1; - spender[i].vin.resize(1); - spender[i].vin[0].prevout.hash = spent[i].hash; - spender[i].vin[0].prevout.n = spent[i].n; - spender[i].vout.resize(1); - spender[i].vout[0].nValue = coinbase_tx->GetValueOut(); - spender[i].vout[0].scriptPubKey = coinbase_script; + spender[i].vin = {CTxIn{spent[i]}}; + spender[i].vout = {CTxOut{coinbase_tx->GetValueOut(), coinbase_script}}; diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp index 2a4f213..4b63e79 100644 --- a/src/test/txvalidation_tests.cpp +++ b/src/test/txvalidation_tests.cpp @@ -32,7 +32,4 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) coinbaseTx.version = 1; - coinbaseTx.vin.resize(1); - coinbaseTx.vout.resize(1); - coinbaseTx.vin[0].scriptSig = CScript() << OP_11 << OP_EQUAL; - coinbaseTx.vout[0].nValue = 1 * CENT; - coinbaseTx.vout[0].scriptPubKey = scriptPubKey; + coinbaseTx.vin = {CTxIn{COutPoint{}, CScript{} << OP_11 << OP_EQUAL}}; + coinbaseTx.vout = {CTxOut{1 * CENT, scriptPubKey}}; @@ -472,5 +469,3 @@ BOOST_FIXTURE_TEST_CASE(version3_tests, RegTestingSetup) } - mtx_many_sigops.vout.resize(1); - mtx_many_sigops.vout.back().scriptPubKey = CScript() << OP_TRUE; - mtx_many_sigops.vout.back().nValue = 10000; + mtx_many_sigops.vout = {CTxOut{10000, CScript{} << OP_TRUE}}; auto tx_many_sigops{MakeTransactionRef(mtx_many_sigops)}; diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp index 6757f39..32180cb 100644 --- a/src/test/validation_block_tests.cpp +++ b/src/test/validation_block_tests.cpp @@ -95,6 +95,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::Block(const uint256& prev_hash) CMutableTransaction txCoinbase(*pblock->vtx[0]); - txCoinbase.vout.resize(2); - txCoinbase.vout[1].scriptPubKey = P2WSH_OP_TRUE; - txCoinbase.vout[1].nValue = txCoinbase.vout[0].nValue; - txCoinbase.vout[0].nValue = 0; + const CTxOut original_coinbase_output{txCoinbase.vout[0]}; + txCoinbase.vout = { + CTxOut{0, original_coinbase_output.scriptPubKey}, + CTxOut{original_coinbase_output.nValue, P2WSH_OP_TRUE}, + }; txCoinbase.vin[0].scriptWitness.SetNull(); @@ -375,7 +376,3 @@ BOOST_AUTO_TEST_CASE(witness_commitment_index) CMutableTransaction txCoinbase(*pblock.vtx[0]); - txCoinbase.vout.resize(4); - txCoinbase.vout[0] = witness; - txCoinbase.vout[1] = witness; - txCoinbase.vout[2] = min_plus_one; - txCoinbase.vout[3] = invalid; + txCoinbase.vout = {witness, witness, min_plus_one, invalid}; pblock.vtx[0] = MakeTransactionRef(std::move(txCoinbase)); diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp index 268529f..1537756 100644 --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -174,4 +174,12 @@ BOOST_AUTO_TEST_CASE(block_malleation) auto create_coinbase_tx = [](bool include_witness = false) { + CScript commitment; + commitment.resize(MINIMUM_WITNESS_COMMITMENT); + commitment[0] = OP_RETURN; + commitment[1] = 0x24; + commitment[2] = 0xaa; + commitment[3] = 0x21; + commitment[4] = 0xa9; + commitment[5] = 0xed; CMutableTransaction coinbase; - coinbase.vin.resize(1); + coinbase.vin = {CTxIn{}}; if (include_witness) { @@ -180,11 +188,3 @@ BOOST_AUTO_TEST_CASE(block_malleation) } - - coinbase.vout.resize(1); - coinbase.vout[0].scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT); - coinbase.vout[0].scriptPubKey[0] = OP_RETURN; - coinbase.vout[0].scriptPubKey[1] = 0x24; - coinbase.vout[0].scriptPubKey[2] = 0xaa; - coinbase.vout[0].scriptPubKey[3] = 0x21; - coinbase.vout[0].scriptPubKey[4] = 0xa9; - coinbase.vout[0].scriptPubKey[5] = 0xed; + coinbase.vout = {CTxOut{-1, commitment}}; @@ -246,5 +246,6 @@ BOOST_AUTO_TEST_CASE(block_malleation) CMutableTransaction mtx; - mtx.vin.resize(1); - mtx.vout.resize(1); - mtx.vout[0].scriptPubKey.resize(4); + CScript script_pub_key; + script_pub_key.resize(4); + mtx.vin = {CTxIn{}}; + mtx.vout = {CTxOut{-1, script_pub_key}}; block.vtx.push_back(MakeTransactionRef(mtx)); diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index fdce22a..c14119c 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -915,4 +915,3 @@ BOOST_AUTO_TEST_CASE(effective_value_test) CMutableTransaction tx; - tx.vout.resize(1); - tx.vout[nInput].nValue = nValue; + tx.vout = {CTxOut{nValue, CScript{}}}; diff --git a/src/wallet/test/fuzz/spend.cpp b/src/wallet/test/fuzz/spend.cpp index 395ba3d..7c783f4 100644 --- a/src/wallet/test/fuzz/spend.cpp +++ b/src/wallet/test/fuzz/spend.cpp @@ -80,3 +80,2 @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup) tx.nLockTime = next_locktime++; - tx.vout.resize(1); CAmount n_value{ConsumeMoney(fuzzed_data_provider)}; @@ -84,4 +83,3 @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup) if (all_values > MAX_MONEY) return; - tx.vout[0].nValue = n_value; - tx.vout[0].scriptPubKey = GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider)); + tx.vout = {CTxOut{n_value, GetScriptForDestination(fuzzed_wallet.GetDestination(fuzzed_data_provider))}}; LOCK(fuzzed_wallet.wallet->cs_wallet); diff --git a/src/wallet/test/group_outputs_tests.cpp b/src/wallet/test/group_outputs_tests.cpp index c1fe72b..767ef9b 100644 --- a/src/wallet/test/group_outputs_tests.cpp +++ b/src/wallet/test/group_outputs_tests.cpp @@ -37,5 +37,3 @@ static void addCoin(CoinsResult& coins, tx.nLockTime = nextLockTime++; // so all transactions get different hashes - tx.vout.resize(1); - tx.vout[0].nValue = nValue; - tx.vout[0].scriptPubKey = GetScriptForDestination(dest); + tx.vout = {CTxOut{nValue, GetScriptForDestination(dest)}}; ``` </details>
maflcko commented 2026-11-25 07:43:13 +00:00 (Migrated from github.com)

review ACK 5b4baa8dad 🍸

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 5b4baa8dada19ceac2b2f882cf6ca3d071c87f87 🍸
D6Za5SSauquYtXNru4XexgG38blOsVsbp9u983GdsZTT6uqb3aUg2Qw4YGt3n07ugJIzqyhecIgCBJUpa3+fBA==
review ACK 5b4baa8dada19ceac2b2f882cf6ca3d071c87f87 🍸 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 5b4baa8dada19ceac2b2f882cf6ca3d071c87f87 🍸 D6Za5SSauquYtXNru4XexgG38blOsVsbp9u983GdsZTT6uqb3aUg2Qw4YGt3n07ugJIzqyhecIgCBJUpa3+fBA== ``` </details>
janb84 (Migrated from github.com) reviewed 2026-11-25 12:56:24 +00:00
janb84 (Migrated from github.com) left a comment

re ACK 5b4baa8dad

re ACK 5b4baa8dada19ceac2b2f882cf6ca3d071c87f87
yuvicc (Migrated from github.com) reviewed 2026-11-25 12:59:25 +00:00
yuvicc (Migrated from github.com) commented 2026-11-25 12:59:25 +00:00

Alright, thanks.

Alright, thanks.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36950
No description provided.