Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5464 from EOSIO/cancel-self-bug-unit-test
Browse files Browse the repository at this point in the history
Unit test for self-cancelling deferred transaction bug
  • Loading branch information
heifner authored Aug 28, 2018
2 parents a4096cb + 083935e commit dc5f5d0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions contracts/test_api/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ extern "C" {
WASM_TEST_HANDLER(test_transaction, context_free_api);
WASM_TEST_HANDLER(test_transaction, new_feature);
WASM_TEST_HANDLER(test_transaction, active_new_feature);
WASM_TEST_HANDLER_EX(test_transaction, repeat_deferred_transaction);

//test chain
WASM_TEST_HANDLER(test_chain, test_activeprods);
Expand Down
1 change: 1 addition & 0 deletions contracts/test_api/test_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ struct test_transaction {
static void context_free_api();
static void new_feature();
static void active_new_feature();
static void repeat_deferred_transaction(uint64_t receiver, uint64_t code, uint64_t action);
};

struct test_chain {
Expand Down
20 changes: 20 additions & 0 deletions contracts/test_api/test_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,23 @@ void test_transaction::new_feature() {
void test_transaction::active_new_feature() {
activate_feature((int64_t)N(newfeature));
}

void test_transaction::repeat_deferred_transaction(uint64_t receiver, uint64_t code, uint64_t action) {
using namespace eosio;

uint128_t sender_id = 0;

uint32_t payload = unpack_action_data<uint32_t>();
print( "repeat_deferred_transaction called: payload = ", payload );

bool res = cancel_deferred( sender_id );

print( "\nrepeat_deferred_transaction cancelled trx with sender_id = ", sender_id, ", result is ", res );

if( payload == 0 ) return;

--payload;
transaction trx;
trx.actions.emplace_back( permission_level{receiver, N(active)}, code, action, payload );
trx.send( sender_id, receiver );
}
20 changes: 20 additions & 0 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,27 @@ BOOST_FIXTURE_TEST_CASE(deferred_transaction_tests, TESTER) { try {

produce_blocks(10);

//repeated deferred transactions
{
vector<transaction_trace_ptr> traces;
auto c = control->applied_transaction.connect([&]( const transaction_trace_ptr& t) {
if (t && t->scheduled) {
traces.push_back( t );
}
} );

CALL_TEST_FUNCTION(*this, "test_transaction", "repeat_deferred_transaction", fc::raw::pack( (uint32_t)5 ) );

produce_block();

c.disconnect();

BOOST_CHECK_EQUAL( traces.size(), 5 );
}

produce_blocks(10);

{
// Trigger a tx which in turn sends a deferred tx with payer != receiver
// Payer is alice in this case, this tx should fail since we don't have the authorization of alice
dtt_action dtt_act1;
Expand Down

0 comments on commit dc5f5d0

Please sign in to comment.