Skip to content

Commit

Permalink
GH-985 Move push_trx to test_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Nov 11, 2024
1 parent f871bf2 commit 29ac711
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
32 changes: 0 additions & 32 deletions unittests/checktime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class T, typename Tester>
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<char> 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<permission_level>{{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<public_key_type> keys;
trx.get_signature_keys(test.get_chain_id(), fc::time_point::maximum(), keys);
auto ptrx = std::make_shared<packed_transaction>( 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<class T, typename Tester>
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<char> payload = {}, name account = "testapi"_n, transaction_metadata::trx_type trx_type = transaction_metadata::trx_type::input ) {
Expand Down
32 changes: 32 additions & 0 deletions unittests/test_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ struct test_chain_action {
}
};

template<class T, typename Tester>
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<char> 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<permission_level>{{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<public_key_type> keys;
trx.get_signature_keys(test.get_chain_id(), fc::time_point::maximum(), keys);
auto ptrx = std::make_shared<packed_transaction>( 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)
Expand Down

0 comments on commit 29ac711

Please sign in to comment.