diff --git a/libraries/chain/controller.cpp b/libraries/chain/controller.cpp index c04013cb04..f9c59f26b6 100644 --- a/libraries/chain/controller.cpp +++ b/libraries/chain/controller.cpp @@ -3716,22 +3716,6 @@ void controller::code_block_num_last_used(const digest_type& code_hash, uint8_t return my->code_block_num_last_used(code_hash, vm_type, vm_version, block_num); } -// Native action hardcodes sender empty and builds sender_id from trx id. -// This method modifies those two fields for contract generated deferred -// trxs so canceldelay can be tested by canceldelay_test in delay_tests.cpp. -// It cannot be used for any other purpose. -void controller::modify_gto_for_canceldelay_test(const transaction_id_type& trx_id) { - auto gto = my->db.find(trx_id); - if (gto) { - my->db.modify(*gto, [&]( auto& gtx ) { - gtx.sender = account_name(); - - fc::uint128 _id(trx_id._hash[3], trx_id._hash[2]); - gtx.sender_id = (unsigned __int128)_id; - }); - } -} - /// Protocol feature activation handlers: template<> diff --git a/libraries/chain/include/eosio/chain/controller.hpp b/libraries/chain/include/eosio/chain/controller.hpp index e90a97a59f..21c1bc9620 100644 --- a/libraries/chain/include/eosio/chain/controller.hpp +++ b/libraries/chain/include/eosio/chain/controller.hpp @@ -366,13 +366,10 @@ namespace eosio { namespace chain { bool is_write_window() const; void code_block_num_last_used(const digest_type& code_hash, uint8_t vm_type, uint8_t vm_version, uint32_t block_num); - // Warning: this method is only used by canceldelay_test - // in delay_tests.cpp. Do not use it for any other purpose. - void modify_gto_for_canceldelay_test(const transaction_id_type& trx_id); - private: friend class apply_context; friend class transaction_context; + friend void modify_gto_for_canceldelay_test(controller& control, const transaction_id_type& trx_id); // canceldelay_test in delay_tests.cpp need access to mutable_db chainbase::database& mutable_db()const; diff --git a/unittests/delay_tests.cpp b/unittests/delay_tests.cpp index 2c99288361..122ea997bf 100644 --- a/unittests/delay_tests.cpp +++ b/unittests/delay_tests.cpp @@ -16,6 +16,22 @@ using mvo = fc::mutable_variant_object; const std::string eosio_token = name("eosio.token"_n).to_string(); +// Native action hardcodes sender empty and builds sender_id from trx id. +// This method modifies those two fields for contract generated deferred +// trxs so canceldelay can be tested by canceldelay_test. +namespace eosio::chain { +inline void modify_gto_for_canceldelay_test(controller& control, const transaction_id_type& trx_id) { + auto gto = control.mutable_db().find(trx_id); + if (gto) { + control.mutable_db().modify(*gto, [&]( auto& gtx ) { + gtx.sender = account_name(); + + fc::uint128 _id(trx_id._hash[3], trx_id._hash[2]); + gtx.sender_id = (unsigned __int128)_id; + }); + } +}} /// namespace eosio::chain + static void create_accounts(validating_tester& chain) { chain.produce_blocks(); chain.create_accounts({"eosio.msig"_n, "eosio.token"_n}); @@ -1392,7 +1408,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test ) { try { // canceldelay assumes sender and sender_id to be a specific // format. hardcode them for testing purpose only - chain.control->modify_gto_for_canceldelay_test(deferred_id); + modify_gto_for_canceldelay_test(*(chain.control.get()), deferred_id); // send canceldelay for the delayed transaction signed_transaction trx; @@ -1451,7 +1467,7 @@ BOOST_AUTO_TEST_CASE( canceldelay_test2 ) { try { // canceldelay assumes sender and sender_id to be a specific // format. hardcode them for testing purpose only - chain.control->modify_gto_for_canceldelay_test(deferred_id); + modify_gto_for_canceldelay_test(*(chain.control.get()), deferred_id); // attempt canceldelay with wrong canceling_auth for delayed trx {