Skip to content

Commit

Permalink
move modify_gto_for_canceldelay_test out of controller to delay_test
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 committed Sep 27, 2023
1 parent 2d7811d commit 907d54d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
16 changes: 0 additions & 16 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<generated_transaction_object, by_trx_id>(trx_id);
if (gto) {
my->db.modify<generated_transaction_object>(*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<>
Expand Down
5 changes: 1 addition & 4 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
20 changes: 18 additions & 2 deletions unittests/delay_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<generated_transaction_object, by_trx_id>(trx_id);
if (gto) {
control.mutable_db().modify<generated_transaction_object>(*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});
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 907d54d

Please sign in to comment.