9
9
#include < primitives/transaction.h>
10
10
#include < script/script.h>
11
11
#include < test/util/random.h>
12
+ #include < test/util/script.h>
12
13
#include < test/util/setup_common.h>
13
14
#include < validation.h>
14
15
@@ -47,7 +48,7 @@ BOOST_FIXTURE_TEST_CASE(package_sanitization_tests, TestChain100Setup)
47
48
package_too_many.emplace_back (create_placeholder_tx (1 , 1 ));
48
49
}
49
50
PackageValidationState state_too_many;
50
- BOOST_CHECK (!CheckPackage (package_too_many, state_too_many));
51
+ BOOST_CHECK (!CheckPackage (package_too_many, state_too_many, /* require_sorted= */ true ));
51
52
BOOST_CHECK_EQUAL (state_too_many.GetResult (), PackageValidationResult::PCKG_POLICY);
52
53
BOOST_CHECK_EQUAL (state_too_many.GetRejectReason (), " package-too-many-transactions" );
53
54
@@ -62,7 +63,7 @@ BOOST_FIXTURE_TEST_CASE(package_sanitization_tests, TestChain100Setup)
62
63
}
63
64
BOOST_CHECK (package_too_large.size () <= MAX_PACKAGE_COUNT);
64
65
PackageValidationState state_too_large;
65
- BOOST_CHECK (!CheckPackage (package_too_large, state_too_large));
66
+ BOOST_CHECK (!CheckPackage (package_too_large, state_too_large, /* require_sorted= */ true ));
66
67
BOOST_CHECK_EQUAL (state_too_large.GetResult (), PackageValidationResult::PCKG_POLICY);
67
68
BOOST_CHECK_EQUAL (state_too_large.GetRejectReason (), " package-too-large" );
68
69
@@ -73,9 +74,39 @@ BOOST_FIXTURE_TEST_CASE(package_sanitization_tests, TestChain100Setup)
73
74
package_duplicate_txids_empty.emplace_back (MakeTransactionRef (empty_tx));
74
75
}
75
76
PackageValidationState state_duplicates;
76
- BOOST_CHECK (!CheckPackage (package_duplicate_txids_empty, state_duplicates));
77
+ BOOST_CHECK (!CheckPackage (package_duplicate_txids_empty, state_duplicates, /* require_sorted= */ true ));
77
78
BOOST_CHECK_EQUAL (state_duplicates.GetResult (), PackageValidationResult::PCKG_POLICY);
78
79
BOOST_CHECK_EQUAL (state_duplicates.GetRejectReason (), " package-contains-duplicates" );
80
+ BOOST_CHECK (!IsConsistentPackage (package_duplicate_txids_empty));
81
+
82
+ // Packages can't have transactions spending the same prevout
83
+ CMutableTransaction tx_zero_1;
84
+ CMutableTransaction tx_zero_2;
85
+ COutPoint same_prevout{InsecureRand256 (), 0 };
86
+ tx_zero_1.vin .emplace_back (same_prevout);
87
+ tx_zero_2.vin .emplace_back (same_prevout);
88
+ // Different vouts (not the same tx)
89
+ tx_zero_1.vout .emplace_back (CENT, P2WSH_OP_TRUE);
90
+ tx_zero_2.vout .emplace_back (2 * CENT, P2WSH_OP_TRUE);
91
+ Package package_conflicts{MakeTransactionRef (tx_zero_1), MakeTransactionRef (tx_zero_2)};
92
+ BOOST_CHECK (!IsConsistentPackage (package_conflicts));
93
+ // Transactions are considered sorted when they have no dependencies.
94
+ BOOST_CHECK (IsTopoSortedPackage (package_conflicts));
95
+ PackageValidationState state_conflicts;
96
+ BOOST_CHECK (!CheckPackage (package_conflicts, state_conflicts, /* require_sorted=*/ true ));
97
+ BOOST_CHECK_EQUAL (state_conflicts.GetResult (), PackageValidationResult::PCKG_POLICY);
98
+ BOOST_CHECK_EQUAL (state_conflicts.GetRejectReason (), " conflict-in-package" );
99
+
100
+ // IsConsistentPackage only cares about conflicts between transactions, not about a transaction
101
+ // conflicting with itself (i.e. duplicate prevouts in vin).
102
+ CMutableTransaction dup_tx;
103
+ const COutPoint rand_prevout{InsecureRand256 (), 0 };
104
+ dup_tx.vin .emplace_back (rand_prevout);
105
+ dup_tx.vin .emplace_back (rand_prevout);
106
+ Package package_with_dup_tx{MakeTransactionRef (dup_tx)};
107
+ BOOST_CHECK (IsConsistentPackage (package_with_dup_tx));
108
+ package_with_dup_tx.emplace_back (create_placeholder_tx (1 , 1 ));
109
+ BOOST_CHECK (IsConsistentPackage (package_with_dup_tx));
79
110
}
80
111
81
112
BOOST_FIXTURE_TEST_CASE (package_validation_tests, TestChain100Setup)
@@ -157,8 +188,8 @@ BOOST_FIXTURE_TEST_CASE(noncontextual_package_tests, TestChain100Setup)
157
188
CTransactionRef tx_child = MakeTransactionRef (mtx_child);
158
189
159
190
PackageValidationState state;
160
- BOOST_CHECK (CheckPackage ({tx_parent, tx_child}, state));
161
- BOOST_CHECK (!CheckPackage ({tx_child, tx_parent}, state));
191
+ BOOST_CHECK (CheckPackage ({tx_parent, tx_child}, state, /* require_sorted= */ true ));
192
+ BOOST_CHECK (!CheckPackage ({tx_child, tx_parent}, state, /* require_sorted= */ true ));
162
193
BOOST_CHECK_EQUAL (state.GetResult (), PackageValidationResult::PCKG_POLICY);
163
194
BOOST_CHECK_EQUAL (state.GetRejectReason (), " package-not-sorted" );
164
195
BOOST_CHECK (IsChildWithParents ({tx_parent, tx_child}));
@@ -186,7 +217,7 @@ BOOST_FIXTURE_TEST_CASE(noncontextual_package_tests, TestChain100Setup)
186
217
package.push_back (MakeTransactionRef (child));
187
218
188
219
PackageValidationState state;
189
- BOOST_CHECK (CheckPackage (package, state));
220
+ BOOST_CHECK (CheckPackage (package, state, /* require_sorted= */ true ));
190
221
BOOST_CHECK (IsChildWithParents (package));
191
222
BOOST_CHECK (IsChildWithParentsTree (package));
192
223
@@ -224,8 +255,8 @@ BOOST_FIXTURE_TEST_CASE(noncontextual_package_tests, TestChain100Setup)
224
255
BOOST_CHECK (!IsChildWithParentsTree ({tx_parent, tx_parent_also_child, tx_child}));
225
256
// IsChildWithParents does not detect unsorted parents.
226
257
BOOST_CHECK (IsChildWithParents ({tx_parent_also_child, tx_parent, tx_child}));
227
- BOOST_CHECK (CheckPackage ({tx_parent, tx_parent_also_child, tx_child}, state));
228
- BOOST_CHECK (!CheckPackage ({tx_parent_also_child, tx_parent, tx_child}, state));
258
+ BOOST_CHECK (CheckPackage ({tx_parent, tx_parent_also_child, tx_child}, state, /* require_sorted= */ true ));
259
+ BOOST_CHECK (!CheckPackage ({tx_parent_also_child, tx_parent, tx_child}, state, /* require_sorted= */ true ));
229
260
BOOST_CHECK_EQUAL (state.GetResult (), PackageValidationResult::PCKG_POLICY);
230
261
BOOST_CHECK_EQUAL (state.GetRejectReason (), " package-not-sorted" );
231
262
}
0 commit comments