From 29ac7117ec1d7e6b1aa85105a5a8b8b751db3596 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 11 Nov 2024 09:56:31 -0600 Subject: [PATCH] GH-985 Move push_trx to test_utils --- unittests/checktime_tests.cpp | 32 -------------------------------- unittests/test_utils.hpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/unittests/checktime_tests.cpp b/unittests/checktime_tests.cpp index dae5521b77..66d0ef91df 100644 --- a/unittests/checktime_tests.cpp +++ b/unittests/checktime_tests.cpp @@ -42,38 +42,6 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(checktime_pass_tests, T, validating_testers) { tr BOOST_REQUIRE_EQUAL( chain.validate(), true ); } FC_LOG_AND_RETHROW() } -template -void push_trx(Tester& test, T ac, uint32_t billed_cpu_time_us , uint32_t max_cpu_usage_ms, uint32_t max_block_cpu_ms, - bool explicit_bill, std::vector payload = {}, name account = "testapi"_n, transaction_metadata::trx_type trx_type = transaction_metadata::trx_type::input ) { - signed_transaction trx; - - action act; - act.account = ac.get_account(); - act.name = ac.get_name(); - if ( trx_type != transaction_metadata::trx_type::read_only ) { - auto pl = vector{{account, config::active_name}}; - act.authorization = pl; - } - act.data = payload; - - trx.actions.push_back(act); - test.set_transaction_headers(trx); - if ( trx_type != transaction_metadata::trx_type::read_only ) { - auto sigs = trx.sign(test.get_private_key(account, "active"), test.get_chain_id()); - } - flat_set keys; - trx.get_signature_keys(test.get_chain_id(), fc::time_point::maximum(), keys); - auto ptrx = std::make_shared( std::move(trx) ); - - auto fut = transaction_metadata::start_recover_keys( std::move( ptrx ), test.control->get_thread_pool(), - test.get_chain_id(), fc::microseconds::maximum(), - trx_type ); - auto res = test.control->push_transaction( fut.get(), fc::time_point::now() + fc::milliseconds(max_block_cpu_ms), - fc::milliseconds(max_cpu_usage_ms), billed_cpu_time_us, explicit_bill, 0 ); - if( res->except_ptr ) std::rethrow_exception( res->except_ptr ); - if( res->except ) throw *res->except; -}; - template void call_test(Tester& test, T ac, uint32_t billed_cpu_time_us , uint32_t max_cpu_usage_ms, uint32_t max_block_cpu_ms, std::vector payload = {}, name account = "testapi"_n, transaction_metadata::trx_type trx_type = transaction_metadata::trx_type::input ) { diff --git a/unittests/test_utils.hpp b/unittests/test_utils.hpp index 1f218b2c9e..09897c43d4 100644 --- a/unittests/test_utils.hpp +++ b/unittests/test_utils.hpp @@ -67,6 +67,38 @@ struct test_chain_action { } }; +template +void push_trx(Tester& test, T ac, uint32_t billed_cpu_time_us , uint32_t max_cpu_usage_ms, uint32_t max_block_cpu_ms, + bool explicit_bill, std::vector payload = {}, name account = "testapi"_n, transaction_metadata::trx_type trx_type = transaction_metadata::trx_type::input ) { + signed_transaction trx; + + action act; + act.account = ac.get_account(); + act.name = ac.get_name(); + if ( trx_type != transaction_metadata::trx_type::read_only ) { + auto pl = vector{{account, config::active_name}}; + act.authorization = pl; + } + act.data = payload; + + trx.actions.push_back(act); + test.set_transaction_headers(trx); + if ( trx_type != transaction_metadata::trx_type::read_only ) { + auto sigs = trx.sign(test.get_private_key(account, "active"), test.get_chain_id()); + } + flat_set keys; + trx.get_signature_keys(test.get_chain_id(), fc::time_point::maximum(), keys); + auto ptrx = std::make_shared( std::move(trx) ); + + auto fut = transaction_metadata::start_recover_keys( std::move( ptrx ), test.control->get_thread_pool(), + test.get_chain_id(), fc::microseconds::maximum(), + trx_type ); + auto res = test.control->push_transaction( fut.get(), fc::time_point::now() + fc::milliseconds(max_block_cpu_ms), + fc::milliseconds(max_cpu_usage_ms), billed_cpu_time_us, explicit_bill, 0 ); + if( res->except_ptr ) std::rethrow_exception( res->except_ptr ); + if( res->except ) throw *res->except; +}; + static constexpr unsigned int DJBH(const char* cp) { unsigned int hash = 5381; while (*cp)