@@ -35,6 +35,35 @@ inline CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outpu
35
35
return MakeTransactionRef (mtx);
36
36
}
37
37
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
+
38
67
BOOST_FIXTURE_TEST_CASE (package_validation_tests, TestChain100Setup)
39
68
{
40
69
LOCK (cs_main);
@@ -70,31 +99,6 @@ BOOST_FIXTURE_TEST_CASE(package_validation_tests, TestChain100Setup)
70
99
BOOST_CHECK_MESSAGE (it_child->second .m_state .IsValid (),
71
100
" Package validation unexpectedly failed: " << it_child->second .m_state .GetRejectReason ());
72
101
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" );
98
102
99
103
// A single, giant transaction submitted through ProcessNewPackage fails on single tx policy.
100
104
CTransactionRef giant_ptx = create_placeholder_tx (999 , 999 );
0 commit comments