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

New test to ensure require_recipient to generator is ignored #5446

Merged
merged 3 commits into from
Aug 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contracts/test_api/test_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ void test_action::require_notice(uint64_t receiver, uint64_t code, uint64_t acti
eosio_assert(false, "Should've failed");
}

void test_action::require_notice_tests(uint64_t receiver, uint64_t code, uint64_t action) {
eosio::print( "require_notice_tests" );
if( receiver == N( testapi ) ) {
eosio::print( "require_recipient( N(acc5) )" );
eosio::require_recipient( N( acc5 ) );
} else if( receiver == N( acc5 ) ) {
eosio::print( "require_recipient( N(testapi) )" );
eosio::require_recipient( N( testapi ) );
}
}

void test_action::require_auth() {
prints("require_auth");
eosio::require_auth( N(acc3) );
Expand Down
1 change: 1 addition & 0 deletions contracts/test_api/test_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ extern "C" {
WASM_TEST_HANDLER(test_action, read_action_to_0);
WASM_TEST_HANDLER(test_action, read_action_to_64k);
WASM_TEST_HANDLER_EX(test_action, require_notice);
WASM_TEST_HANDLER_EX(test_action, require_notice_tests);
WASM_TEST_HANDLER(test_action, require_auth);
WASM_TEST_HANDLER(test_action, assert_false);
WASM_TEST_HANDLER(test_action, assert_true);
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 @@ -64,6 +64,7 @@ struct test_action {
static void test_dummy_action();
static void test_cf_action();
static void require_notice(uint64_t receiver, uint64_t code, uint64_t action);
static void require_notice_tests(uint64_t receiver, uint64_t code, uint64_t action);
static void require_auth();
static void assert_false();
static void assert_true();
Expand Down
30 changes: 30 additions & 0 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,36 @@ BOOST_FIXTURE_TEST_CASE(action_tests, TESTER) { try {
BOOST_REQUIRE_EQUAL( validate(), true );
} FC_LOG_AND_RETHROW() }

// test require_recipient loop (doesn't cause infinite loop)
BOOST_FIXTURE_TEST_CASE(require_notice_tests, TESTER) { try {
produce_blocks(2);
create_account( N(testapi) );
create_account( N(acc5) );
produce_blocks(1);
set_code( N(testapi), test_api_wast );
set_code( N(acc5), test_api_wast );
produce_blocks(1);

// test require_notice
auto scope = std::vector<account_name>{N(testapi)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually used?

auto test_require_notice = [this](auto& test, std::vector<account_name>& scope){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the lambda actually get you anything here? If not simplify it and just make it part of the method.

signed_transaction trx;
auto tm = test_api_action<TEST_METHOD("test_action", "require_notice_tests")>{};

action act(std::vector<permission_level>{{N(testapi), config::active_name}}, tm);
trx.actions.push_back(act);

test.set_transaction_headers(trx);
trx.sign(test.get_private_key(N(testapi), "active"), control->get_chain_id());
auto res = test.push_transaction(trx);
BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed);
};

test_require_notice(*this, scope); // no exception expected

} FC_LOG_AND_RETHROW() }


/*************************************************************************************
* context free action tests
*************************************************************************************/
Expand Down