mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
[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.
This commit is contained in:
parent
6876378365
commit
14cd7bf793
1 changed files with 29 additions and 25 deletions
|
@ -35,6 +35,35 @@ inline CTransactionRef create_placeholder_tx(size_t num_inputs, size_t num_outpu
|
|||
return MakeTransactionRef(mtx);
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(package_sanitization_tests, TestChain100Setup)
|
||||
{
|
||||
// Packages can't have more than 25 transactions.
|
||||
Package package_too_many;
|
||||
package_too_many.reserve(MAX_PACKAGE_COUNT + 1);
|
||||
for (size_t i{0}; i < MAX_PACKAGE_COUNT + 1; ++i) {
|
||||
package_too_many.emplace_back(create_placeholder_tx(1, 1));
|
||||
}
|
||||
PackageValidationState state_too_many;
|
||||
BOOST_CHECK(!CheckPackage(package_too_many, state_too_many));
|
||||
BOOST_CHECK_EQUAL(state_too_many.GetResult(), PackageValidationResult::PCKG_POLICY);
|
||||
BOOST_CHECK_EQUAL(state_too_many.GetRejectReason(), "package-too-many-transactions");
|
||||
|
||||
// Packages can't have a total size of more than 101KvB.
|
||||
CTransactionRef large_ptx = create_placeholder_tx(150, 150);
|
||||
Package package_too_large;
|
||||
auto size_large = GetVirtualTransactionSize(*large_ptx);
|
||||
size_t total_size{0};
|
||||
while (total_size <= MAX_PACKAGE_SIZE * 1000) {
|
||||
package_too_large.push_back(large_ptx);
|
||||
total_size += size_large;
|
||||
}
|
||||
BOOST_CHECK(package_too_large.size() <= MAX_PACKAGE_COUNT);
|
||||
PackageValidationState state_too_large;
|
||||
BOOST_CHECK(!CheckPackage(package_too_large, state_too_large));
|
||||
BOOST_CHECK_EQUAL(state_too_large.GetResult(), PackageValidationResult::PCKG_POLICY);
|
||||
BOOST_CHECK_EQUAL(state_too_large.GetRejectReason(), "package-too-large");
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(package_validation_tests, TestChain100Setup)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
@ -70,31 +99,6 @@ BOOST_FIXTURE_TEST_CASE(package_validation_tests, TestChain100Setup)
|
|||
BOOST_CHECK_MESSAGE(it_child->second.m_state.IsValid(),
|
||||
"Package validation unexpectedly failed: " << it_child->second.m_state.GetRejectReason());
|
||||
|
||||
// Packages can't have more than 25 transactions.
|
||||
Package package_too_many;
|
||||
package_too_many.reserve(MAX_PACKAGE_COUNT + 1);
|
||||
for (size_t i{0}; i < MAX_PACKAGE_COUNT + 1; ++i) {
|
||||
package_too_many.emplace_back(create_placeholder_tx(1, 1));
|
||||
}
|
||||
auto result_too_many = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, package_too_many, /* test_accept */ true);
|
||||
BOOST_CHECK(result_too_many.m_state.IsInvalid());
|
||||
BOOST_CHECK_EQUAL(result_too_many.m_state.GetResult(), PackageValidationResult::PCKG_POLICY);
|
||||
BOOST_CHECK_EQUAL(result_too_many.m_state.GetRejectReason(), "package-too-many-transactions");
|
||||
|
||||
// Packages can't have a total size of more than 101KvB.
|
||||
CTransactionRef large_ptx = create_placeholder_tx(150, 150);
|
||||
Package package_too_large;
|
||||
auto size_large = GetVirtualTransactionSize(*large_ptx);
|
||||
size_t total_size{0};
|
||||
while (total_size <= MAX_PACKAGE_SIZE * 1000) {
|
||||
package_too_large.push_back(large_ptx);
|
||||
total_size += size_large;
|
||||
}
|
||||
BOOST_CHECK(package_too_large.size() <= MAX_PACKAGE_COUNT);
|
||||
auto result_too_large = ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, package_too_large, /* test_accept */ true);
|
||||
BOOST_CHECK(result_too_large.m_state.IsInvalid());
|
||||
BOOST_CHECK_EQUAL(result_too_large.m_state.GetResult(), PackageValidationResult::PCKG_POLICY);
|
||||
BOOST_CHECK_EQUAL(result_too_large.m_state.GetRejectReason(), "package-too-large");
|
||||
|
||||
// A single, giant transaction submitted through ProcessNewPackage fails on single tx policy.
|
||||
CTransactionRef giant_ptx = create_placeholder_tx(999, 999);
|
||||
|
|
Loading…
Add table
Reference in a new issue