Skip to content

Commit 14cd7bf

Browse files
committed
[test] call CheckPackage for package sanitization checks
Makes the test more minimal. We're just trying to test that our package sanitization logic is correct. Now that this code lives in its own function (rather than inside of AcceptMultipleTransactions), there's no need to call ProcessNewPackage to test this.
1 parent 6876378 commit 14cd7bf

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

src/test/txpackage_tests.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ inline CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outpu
3535
return MakeTransactionRef(mtx);
3636
}
3737

38+
BOOST_FIXTURE_TEST_CASE(package_sanitization_tests, TestChain100Setup)
39+
{
40+
// Packages can't have more than 25 transactions.
41+
Package package_too_many;
42+
package_too_many.reserve(MAX_PACKAGE_COUNT + 1);
43+
for (size_t i{0}; i < MAX_PACKAGE_COUNT + 1; ++i) {
44+
package_too_many.emplace_back(create_placeholder_tx(1, 1));
45+
}
46+
PackageValidationState state_too_many;
47+
BOOST_CHECK(!CheckPackage(package_too_many, state_too_many));
48+
BOOST_CHECK_EQUAL(state_too_many.GetResult(), PackageValidationResult::PCKG_POLICY);
49+
BOOST_CHECK_EQUAL(state_too_many.GetRejectReason(), "package-too-many-transactions");
50+
51+
// Packages can't have a total size of more than 101KvB.
52+
CTransactionRef large_ptx = create_placeholder_tx(150, 150);
53+
Package package_too_large;
54+
auto size_large = GetVirtualTransactionSize(*large_ptx);
55+
size_t total_size{0};
56+
while (total_size <= MAX_PACKAGE_SIZE * 1000) {
57+
package_too_large.push_back(large_ptx);
58+
total_size += size_large;
59+
}
60+
BOOST_CHECK(package_too_large.size() <= MAX_PACKAGE_COUNT);
61+
PackageValidationState state_too_large;
62+
BOOST_CHECK(!CheckPackage(package_too_large, state_too_large));
63+
BOOST_CHECK_EQUAL(state_too_large.GetResult(), PackageValidationResult::PCKG_POLICY);
64+
BOOST_CHECK_EQUAL(state_too_large.GetRejectReason(), "package-too-large");
65+
}
66+
3867
BOOST_FIXTURE_TEST_CASE(package_validation_tests, TestChain100Setup)
3968
{
4069
LOCK(cs_main);
@@ -70,31 +99,6 @@ BOOST_FIXTURE_TEST_CASE(package_validation_tests, TestChain100Setup)
7099
BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(),
71100
"Package validation unexpectedly failed: " << it_child->second.m_state.GetRejectReason());
72101

73-
// Packages can't have more than 25 transactions.
74-
Package package_too_many;
75-
package_too_many.reserve(MAX_PACKAGE_COUNT + 1);
76-
for (size_t i{0}; i < MAX_PACKAGE_COUNT + 1; ++i) {
77-
package_too_many.emplace_back(create_placeholder_tx(1, 1));
78-
}
79-
auto result_too_many = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, package_too_many, /* test_accept */ true);
80-
BOOST_CHECK(result_too_many.m_state.IsInvalid());
81-
BOOST_CHECK_EQUAL(result_too_many.m_state.GetResult(), PackageValidationResult::PCKG_POLICY);
82-
BOOST_CHECK_EQUAL(result_too_many.m_state.GetRejectReason(), "package-too-many-transactions");
83-
84-
// Packages can't have a total size of more than 101KvB.
85-
CTransactionRef large_ptx = create_placeholder_tx(150, 150);
86-
Package package_too_large;
87-
auto size_large = GetVirtualTransactionSize(*large_ptx);
88-
size_t total_size{0};
89-
while (total_size <= MAX_PACKAGE_SIZE * 1000) {
90-
package_too_large.push_back(large_ptx);
91-
total_size += size_large;
92-
}
93-
BOOST_CHECK(package_too_large.size() <= MAX_PACKAGE_COUNT);
94-
auto result_too_large = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, package_too_large, /* test_accept */ true);
95-
BOOST_CHECK(result_too_large.m_state.IsInvalid());
96-
BOOST_CHECK_EQUAL(result_too_large.m_state.GetResult(), PackageValidationResult::PCKG_POLICY);
97-
BOOST_CHECK_EQUAL(result_too_large.m_state.GetRejectReason(), "package-too-large");
98102

99103
// A single, giant transaction submitted through ProcessNewPackage fails on single tx policy.
100104
CTransactionRef giant_ptx = create_placeholder_tx(999, 999);

0 commit comments

Comments
 (0)