From 265132ede8fad50aa2ada6470450596b6264d5de Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 27 Aug 2018 11:26:24 -0500 Subject: [PATCH 1/2] New test to ensure require_recipient to generator is ignored --- contracts/test_api/test_action.cpp | 11 +++++++++++ contracts/test_api/test_api.cpp | 1 + contracts/test_api/test_api.hpp | 1 + unittests/api_tests.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/contracts/test_api/test_action.cpp b/contracts/test_api/test_action.cpp index adc517453fa..74c90330bf0 100644 --- a/contracts/test_api/test_action.cpp +++ b/contracts/test_api/test_action.cpp @@ -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) ); diff --git a/contracts/test_api/test_api.cpp b/contracts/test_api/test_api.cpp index 3bccd9a4a8c..e900dfd82fd 100644 --- a/contracts/test_api/test_api.cpp +++ b/contracts/test_api/test_api.cpp @@ -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); diff --git a/contracts/test_api/test_api.hpp b/contracts/test_api/test_api.hpp index b54f12bff02..18368932bcf 100644 --- a/contracts/test_api/test_api.hpp +++ b/contracts/test_api/test_api.hpp @@ -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(); diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 63eda3116b0..9ac15cc4473 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -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{N(testapi)}; + auto test_require_notice = [this](auto& test, std::vector& scope){ + signed_transaction trx; + auto tm = test_api_action{}; + + action act(std::vector{{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 *************************************************************************************/ From ecb446bbbdbca1e2b0ad3009c63667c63d3cd4ea Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 29 Aug 2018 09:40:02 -0500 Subject: [PATCH 2/2] Clean up from peer review comments --- unittests/api_tests.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/unittests/api_tests.cpp b/unittests/api_tests.cpp index 9ac15cc4473..f2524022254 100644 --- a/unittests/api_tests.cpp +++ b/unittests/api_tests.cpp @@ -448,21 +448,16 @@ BOOST_FIXTURE_TEST_CASE(require_notice_tests, TESTER) { try { produce_blocks(1); // test require_notice - auto scope = std::vector{N(testapi)}; - auto test_require_notice = [this](auto& test, std::vector& scope){ - signed_transaction trx; - auto tm = test_api_action{}; - - action act(std::vector{{N(testapi), config::active_name}}, tm); - trx.actions.push_back(act); + signed_transaction trx; + auto tm = test_api_action{}; - 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); - }; + action act( std::vector{{N( testapi ), config::active_name}}, tm ); + trx.actions.push_back( act ); - test_require_notice(*this, scope); // no exception expected + set_transaction_headers( trx ); + trx.sign( get_private_key( N( testapi ), "active" ), control->get_chain_id() ); + auto res = push_transaction( trx ); + BOOST_CHECK_EQUAL( res->receipt->status, transaction_receipt::executed ); } FC_LOG_AND_RETHROW() }