From 9e3516253d504f6aa316cc6af627ca6727724a82 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:14:34 -0500 Subject: [PATCH 01/12] GH-1433 Allow errors to be returned from runCmdReturnStr --- tests/TestHarness/testUtils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/TestHarness/testUtils.py b/tests/TestHarness/testUtils.py index 2cbe58650c..e7001ab293 100755 --- a/tests/TestHarness/testUtils.py +++ b/tests/TestHarness/testUtils.py @@ -205,7 +205,7 @@ def checkDelayedOutput(popen, cmd, ignoreError=False): Utils.checkOutputFileWrite(start, cmd, output, error) if popen.returncode != 0 and not ignoreError: raise subprocess.CalledProcessError(returncode=popen.returncode, cmd=cmd, output=output, stderr=error) - return output.decode("utf-8") + return output.decode("utf-8") if popen.returncode == 0 else error.decode("utf-8") @staticmethod def errorExit(msg="", raw=False, errorCode=1): @@ -304,13 +304,13 @@ def runCmdArrReturnJson(cmdArr, trace=False, silentErrors=True): return Utils.toJson(retStr) @staticmethod - def runCmdReturnStr(cmd, trace=False): + def runCmdReturnStr(cmd, trace=False, ignoreError=False): cmdArr=shlex.split(cmd) - return Utils.runCmdArrReturnStr(cmdArr) + return Utils.runCmdArrReturnStr(cmdArr, ignoreError=ignoreError) @staticmethod - def runCmdArrReturnStr(cmdArr, trace=False): - retStr=Utils.checkOutput(cmdArr) + def runCmdArrReturnStr(cmdArr, trace=False, ignoreError=False): + retStr=Utils.checkOutput(cmdArr, ignoreError=ignoreError) if trace: Utils.Print ("RAW > %s" % (retStr)) return retStr From f6a8c43261e8e6dfff388aa81abb7d637d986490 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:15:08 -0500 Subject: [PATCH 02/12] GH-1433 Add tests for trace_api get_transaction_trace --- tests/plugin_http_api_test.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index 4739ec3823..d88a330708 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -1487,6 +1487,24 @@ def test_TraceApi(self) : self.assertEqual(ret_json["code"], 404) self.assertEqual(ret_json["error"]["code"], 0) + # get_transaction_trace with empty parameter + default_cmd = cmd_base + "get_transaction_trace" + ret_json = Utils.runCmdReturnJson(default_cmd) + self.assertEqual(ret_json["code"], 400) + # get_transaction_trace with empty content parameter + empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str + ret_json = Utils.runCmdReturnJson(empty_content_cmd) + self.assertEqual(ret_json["code"], 400) + # get_transaction_trace with invalid parameter + invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param + ret_json = Utils.runCmdReturnJson(invalid_cmd) + self.assertEqual(ret_json["code"], 400) + # get_transaction_trace with valid parameter + valid_cmd = default_cmd + self.http_post_str + ("'{\"id\":\"f6e325a524e0d75c2275e7d9c2d9e065a38760c29b1d0471a75ccde650ef26d6\"}'") + ret_json = Utils.runCmdReturnJson(valid_cmd) + self.assertEqual(ret_json["code"], 404) + self.assertEqual(ret_json["error"]["code"], 0) + # test all db_size api def test_DbSizeApi(self) : cmd_base = self.base_node_cmd_str + "db_size/" From 61fe0e5983bde8649eb0544739081faab8e21ebe Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:15:45 -0500 Subject: [PATCH 03/12] GH-1433 New tests for yield in abi handler --- .../test/test_data_handlers.cpp | 46 +++++++++++++++ .../trace_api_plugin/test/test_responses.cpp | 59 +++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/plugins/trace_api_plugin/test/test_data_handlers.cpp b/plugins/trace_api_plugin/test/test_data_handlers.cpp index 6ae4501b08..99c5a680d4 100644 --- a/plugins/trace_api_plugin/test/test_data_handlers.cpp +++ b/plugins/trace_api_plugin/test/test_data_handlers.cpp @@ -135,6 +135,52 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests) BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element()); } + BOOST_AUTO_TEST_CASE(abi_fail_yield) + { + auto action = action_trace_v1 { + { 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}}, + {0x04, 0x05, 0x06, 0x07} + }; + + std::variant action_trace_t = action; + + auto abi = chain::abi_def ( {}, + { + { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } } + }, + { + { "foo"_n, "foo", ""} + }, + {}, {}, {} + ); + abi.version = "eosio::abi/1."; + + bool except_called = false; + auto except_handler = [&](const exception_with_context& e) { + except_called = true; + BOOST_CHECK(std::get<0>(e).operator bool()); + BOOST_CHECK(std::get<2>(e) > 0); + if (std::get<0>(e)) { // rethrow so caller is notified of error + std::rethrow_exception(std::get<0>(e)); + } + }; + + abi_data_handler handler(except_handler); + handler.add_abi("alice"_n, abi); + + fc::variant expected = fc::mutable_variant_object() + ("a", 0) + ("b", 1) + ("c", 2) + ("d", 3); + + uint32_t depth = 0; + BOOST_CHECK_EXCEPTION(handler.serialize_to_variant(action_trace_t, [&](){ ++depth; if (depth > 1) throw std::runtime_error("oops"); }), std::runtime_error, + [](const std::runtime_error& e) { + return std::string(e.what()).find("oops") != std::string::npos; + }); + } + BOOST_AUTO_TEST_CASE(basic_abi_wrong_type) { auto action = action_trace_v0 { diff --git a/plugins/trace_api_plugin/test/test_responses.cpp b/plugins/trace_api_plugin/test/test_responses.cpp index 431f5f00d5..9cb548c266 100644 --- a/plugins/trace_api_plugin/test/test_responses.cpp +++ b/plugins/trace_api_plugin/test/test_responses.cpp @@ -556,6 +556,65 @@ BOOST_AUTO_TEST_SUITE(trace_responses) BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception); } + BOOST_FIXTURE_TEST_CASE(yield_throws_from_data_handler, response_test_fixture) + { + auto action_trace = action_trace_v1 { + { + 0, + "receiver"_n, "contract"_n, "action"_n, + {{ "alice"_n, "active"_n }}, + { 0x00, 0x01, 0x02, 0x03 } + }, + { 0x04, 0x05, 0x06, 0x07 } + }; + + auto transaction_trace = transaction_trace_v2 { + "0000000000000000000000000000000000000000000000000000000000000001"_h, + std::vector { + action_trace + }, + fc::enum_type{chain::transaction_receipt_header::status_enum::executed}, + 10, + 5, + std::vector{ chain::signature_type() }, + { chain::time_point(), 1, 0, 100, 50, 0 } + }; + + auto block_trace = block_trace_v2 { + "b000000000000000000000000000000000000000000000000000000000000001"_h, + 1, + "0000000000000000000000000000000000000000000000000000000000000000"_h, + chain::block_timestamp_type(0), + "bp.one"_n, + "0000000000000000000000000000000000000000000000000000000000000000"_h, + "0000000000000000000000000000000000000000000000000000000000000000"_h, + 0, + std::vector { + transaction_trace + } + }; + + mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t { + BOOST_TEST(height == 1); + return std::make_tuple(data_log_entry(block_trace), false); + }; + + mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t { + BOOST_TEST(height == 1); + return std::make_tuple(data_log_entry(block_trace), true); + }; + + // simulate data_handler failing + mock_data_handler_v1 = [&](const action_trace_v1&, const yield_function&) -> std::tuple> { + throw std::runtime_error("mock error"); + }; + + // no other yield calls will throw + yield_function yield = [&]() {}; + + BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), std::runtime_error); + } + BOOST_FIXTURE_TEST_CASE(old_version_block_response, response_test_fixture) { auto block_trace = block_trace_v0 { From b16135df950c24318da547fb75cf5ce45321dc90 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:16:18 -0500 Subject: [PATCH 04/12] GH-1433 Update test for failure case of trace_api_plugin not having time to deserialize --- tests/trace_plugin_test.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/trace_plugin_test.py b/tests/trace_plugin_test.py index 3f13d3cf88..5b5eb51c1e 100755 --- a/tests/trace_plugin_test.py +++ b/tests/trace_plugin_test.py @@ -5,8 +5,9 @@ import time import unittest import os +import signal -from TestHarness import Cluster, Node, TestHelper, Utils, WalletMgr +from TestHarness import Cluster, Node, TestHelper, Utils, WalletMgr, ReturnType from core_symbol import CORE_SYMBOL class TraceApiPluginTest(unittest.TestCase): @@ -29,7 +30,7 @@ def cleanEnv(self, shouldCleanup: bool) : def startEnv(self) : account_names = ["alice", "bob", "charlie"] abs_path = os.path.abspath(os.getcwd() + '/unittests/contracts/eosio.token/eosio.token.abi') - traceNodeosArgs = " --trace-rpc-abi eosio.token=" + abs_path + traceNodeosArgs = " --verbose-http-errors --trace-rpc-abi eosio.token=" + abs_path self.cluster.launch(totalNodes=1, extraNodeosArgs=traceNodeosArgs) self.walletMgr.launch() testWalletName="testwallet" @@ -102,6 +103,19 @@ def test_TraceApi(self) : break self.assertTrue(isTrxInBlockFromTraceApi) + # relaunch with no time allocated for http response & abi-serializer so should always fail + node.kill(signal.SIGTERM) + Utils.Print("Ignore expected: ERROR: Node relaunch Failed") + isRelaunchSuccess = node.relaunch(addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "10"}) + + cmdDesc="get block_trace" + cmd=" --print-response %s %d" % (cmdDesc, blockNum) + cmd="%s %s %s" % (Utils.EosClientPath, node.eosClientArgs(), cmd) + result=Utils.runCmdReturnStr(cmd, ignoreError=True) + + Utils.Print(f"{cmdDesc} returned: {result}") + self.assertIn("Internal Server Error", result) + @classmethod def setUpClass(self): self.cleanEnv(self, shouldCleanup=True) From 86987245729f95dc1b944333d3cc9ba668f4b410 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:16:44 -0500 Subject: [PATCH 05/12] GH-1433 rethrow exception so API can report error to user --- plugins/trace_api_plugin/trace_api_plugin.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/trace_api_plugin/trace_api_plugin.cpp b/plugins/trace_api_plugin/trace_api_plugin.cpp index adb9534f2b..28419bf2c5 100644 --- a/plugins/trace_api_plugin/trace_api_plugin.cpp +++ b/plugins/trace_api_plugin/trace_api_plugin.cpp @@ -202,6 +202,9 @@ struct trace_api_rpc_plugin_impl : public std::enable_shared_from_this data_handler = std::make_shared([](const exception_with_context& e){ log_exception(e, fc::log_level::debug); + if (std::get<0>(e)) { // rethrow so caller is notified of error + std::rethrow_exception(std::get<0>(e)); + } }); if( options.count("trace-rpc-abi") ) { From c3c9ebd3ea91db25a30a4a1ca7a65b5806276cae Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 25 Jul 2023 15:59:18 -0500 Subject: [PATCH 06/12] GH-1433 Reduce timeout so test runs in allotted time --- tests/trace_plugin_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/trace_plugin_test.py b/tests/trace_plugin_test.py index 5b5eb51c1e..42de59dee6 100755 --- a/tests/trace_plugin_test.py +++ b/tests/trace_plugin_test.py @@ -103,10 +103,10 @@ def test_TraceApi(self) : break self.assertTrue(isTrxInBlockFromTraceApi) - # relaunch with no time allocated for http response & abi-serializer so should always fail + # relaunch with no time allocated for http response & abi-serializer. Will fail because get_info fails. node.kill(signal.SIGTERM) Utils.Print("Ignore expected: ERROR: Node relaunch Failed") - isRelaunchSuccess = node.relaunch(addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "10"}) + isRelaunchSuccess = node.relaunch(timeout=10, addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "10"}) cmdDesc="get block_trace" cmd=" --print-response %s %d" % (cmdDesc, blockNum) From 5b05c194db2f7b07260e93f4345d8f88bbc85c30 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 28 Jul 2023 07:23:55 -0500 Subject: [PATCH 07/12] GH-1433 Add missing BOOST_CHECK --- plugins/trace_api_plugin/test/test_data_handlers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/trace_api_plugin/test/test_data_handlers.cpp b/plugins/trace_api_plugin/test/test_data_handlers.cpp index 99c5a680d4..ee63ab50fb 100644 --- a/plugins/trace_api_plugin/test/test_data_handlers.cpp +++ b/plugins/trace_api_plugin/test/test_data_handlers.cpp @@ -179,6 +179,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests) [](const std::runtime_error& e) { return std::string(e.what()).find("oops") != std::string::npos; }); + BOOST_CHECK(except_called); } BOOST_AUTO_TEST_CASE(basic_abi_wrong_type) From e17bc3148b4873b513e2f3d60c527e65b74603d1 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 28 Jul 2023 14:35:12 -0500 Subject: [PATCH 08/12] GH-1433 Fix merge issue --- plugins/trace_api_plugin/test/test_data_handlers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/trace_api_plugin/test/test_data_handlers.cpp b/plugins/trace_api_plugin/test/test_data_handlers.cpp index ee33e269ad..0244bc0521 100644 --- a/plugins/trace_api_plugin/test/test_data_handlers.cpp +++ b/plugins/trace_api_plugin/test/test_data_handlers.cpp @@ -166,7 +166,7 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests) }; abi_data_handler handler(except_handler); - handler.add_abi("alice"_n, abi); + handler.add_abi("alice"_n, std::move(abi)); fc::variant expected = fc::mutable_variant_object() ("a", 0) From 38196b8d7abc8cdfd85bc0f68786683e6616ac27 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Fri, 28 Jul 2023 16:31:40 -0500 Subject: [PATCH 09/12] GH-1433 Use new processUrllibRequest --- tests/plugin_http_api_test.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index 4de6cacb7a..bd1e5abac1 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -1363,20 +1363,18 @@ def test_TraceApi(self) : self.assertEqual(ret_json["error"]["code"], 0) # get_transaction_trace with empty parameter - default_cmd = cmd_base + "get_transaction_trace" - ret_json = Utils.runCmdReturnJson(default_cmd) + command = "get_transaction_trace" + ret_json = self.nodeos.processUrllibRequest(resource, command) self.assertEqual(ret_json["code"], 400) # get_transaction_trace with empty content parameter - empty_content_cmd = default_cmd + self.http_post_str + self.empty_content_str - ret_json = Utils.runCmdReturnJson(empty_content_cmd) + ret_json = self.nodeos.processUrllibRequest(resource, command, self.empty_content_dict) self.assertEqual(ret_json["code"], 400) # get_transaction_trace with invalid parameter - invalid_cmd = default_cmd + self.http_post_str + self.http_post_invalid_param - ret_json = Utils.runCmdReturnJson(invalid_cmd) + ret_json = self.nodeos.processUrllibRequest(resource, command, self.http_post_invalid_param) self.assertEqual(ret_json["code"], 400) # get_transaction_trace with valid parameter - valid_cmd = default_cmd + self.http_post_str + ("'{\"id\":\"f6e325a524e0d75c2275e7d9c2d9e065a38760c29b1d0471a75ccde650ef26d6\"}'") - ret_json = Utils.runCmdReturnJson(valid_cmd) + payload = {"id":"f6e325a524e0d75c2275e7d9c2d9e065a38760c29b1d0471a75ccde650ef26d6"} + ret_json = self.nodeos.processUrllibRequest(resource, command, payload) self.assertEqual(ret_json["code"], 404) self.assertEqual(ret_json["error"]["code"], 0) From 579facd100238049b9bea0662c36efbcdd95b11d Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 31 Jul 2023 08:45:39 -0500 Subject: [PATCH 10/12] GH-1433 trace_api_plugin can't fail due to timeout. Remove unneeded tests. --- .../test/test_data_handlers.cpp | 47 ------- .../trace_api_plugin/test/test_responses.cpp | 124 ------------------ tests/trace_plugin_test.py | 5 +- 3 files changed, 3 insertions(+), 173 deletions(-) diff --git a/plugins/trace_api_plugin/test/test_data_handlers.cpp b/plugins/trace_api_plugin/test/test_data_handlers.cpp index 34c3282762..464b3a81c1 100644 --- a/plugins/trace_api_plugin/test/test_data_handlers.cpp +++ b/plugins/trace_api_plugin/test/test_data_handlers.cpp @@ -134,53 +134,6 @@ BOOST_AUTO_TEST_SUITE(abi_data_handler_tests) BOOST_TEST(to_kv(expected) == to_kv(std::get<0>(actual)), boost::test_tools::per_element()); } - BOOST_AUTO_TEST_CASE(abi_fail_yield) - { - auto action = action_trace_v1 { - { 0, "alice"_n, "alice"_n, "foo"_n, {}, {0x00, 0x01, 0x02, 0x03}}, - {0x04, 0x05, 0x06, 0x07} - }; - - std::variant action_trace_t = action; - - auto abi = chain::abi_def ( {}, - { - { "foo", "", { {"a", "varuint32"}, {"b", "varuint32"}, {"c", "varuint32"}, {"d", "varuint32"} } } - }, - { - { "foo"_n, "foo", ""} - }, - {}, {}, {} - ); - abi.version = "eosio::abi/1."; - - bool except_called = false; - auto except_handler = [&](const exception_with_context& e) { - except_called = true; - BOOST_CHECK(std::get<0>(e).operator bool()); - BOOST_CHECK(std::get<2>(e) > 0); - if (std::get<0>(e)) { // rethrow so caller is notified of error - std::rethrow_exception(std::get<0>(e)); - } - }; - - abi_data_handler handler(except_handler); - handler.add_abi("alice"_n, std::move(abi)); - - fc::variant expected = fc::mutable_variant_object() - ("a", 0) - ("b", 1) - ("c", 2) - ("d", 3); - - uint32_t depth = 0; - BOOST_CHECK_EXCEPTION(handler.serialize_to_variant(action_trace_t, [&](){ ++depth; if (depth > 1) throw std::runtime_error("oops"); }), std::runtime_error, - [](const std::runtime_error& e) { - return std::string(e.what()).find("oops") != std::string::npos; - }); - BOOST_CHECK(except_called); - } - BOOST_AUTO_TEST_CASE(basic_abi_wrong_type) { auto action = action_trace_v0 { diff --git a/plugins/trace_api_plugin/test/test_responses.cpp b/plugins/trace_api_plugin/test/test_responses.cpp index a138f9acf5..42ca936332 100644 --- a/plugins/trace_api_plugin/test/test_responses.cpp +++ b/plugins/trace_api_plugin/test/test_responses.cpp @@ -490,130 +490,6 @@ BOOST_AUTO_TEST_SUITE(trace_responses) BOOST_TEST(null_response.is_null()); } - BOOST_FIXTURE_TEST_CASE(yield_throws, response_test_fixture) - { - auto block_trace = block_trace_v1 { - { - "b000000000000000000000000000000000000000000000000000000000000001"_h, - 1, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - chain::block_timestamp_type(0), - "bp.one"_n - }, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - 0, - { - { - { - "0000000000000000000000000000000000000000000000000000000000000001"_h, - { - { - 0, - "receiver"_n, "contract"_n, "action"_n, - {{ "alice"_n, "active"_n }}, - { 0x00, 0x01, 0x02, 0x03 } - } - } - }, - fc::enum_type{chain::transaction_receipt_header::status_enum::executed}, - 10, - 5, - std::vector{chain::signature_type()}, - {chain::time_point(), 1, 0, 100, 50, 0} - } - } - }; - - mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t { - BOOST_TEST(height == 1); - return std::make_tuple(data_log_entry(block_trace), false); - }; - - int countdown = 3; - yield_function yield = [&]() { - if (countdown-- == 0) { - throw yield_exception("mock"); - } - }; - - BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception); - } - - BOOST_FIXTURE_TEST_CASE(yield_throws_from_get_block, response_test_fixture) - { - // no other yield calls will throw - yield_function yield = [&]() { - }; - - // simulate a yield throw inside get block - mock_get_block = []( uint32_t height, const yield_function& yield) -> get_block_t { - throw yield_exception("mock exception"); - }; - - - BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), yield_exception); - } - - BOOST_FIXTURE_TEST_CASE(yield_throws_from_data_handler, response_test_fixture) - { - auto action_trace = action_trace_v1 { - { - 0, - "receiver"_n, "contract"_n, "action"_n, - {{ "alice"_n, "active"_n }}, - { 0x00, 0x01, 0x02, 0x03 } - }, - { 0x04, 0x05, 0x06, 0x07 } - }; - - auto transaction_trace = transaction_trace_v2 { - "0000000000000000000000000000000000000000000000000000000000000001"_h, - std::vector { - action_trace - }, - fc::enum_type{chain::transaction_receipt_header::status_enum::executed}, - 10, - 5, - std::vector{ chain::signature_type() }, - { chain::time_point(), 1, 0, 100, 50, 0 } - }; - - auto block_trace = block_trace_v2 { - "b000000000000000000000000000000000000000000000000000000000000001"_h, - 1, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - chain::block_timestamp_type(0), - "bp.one"_n, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - "0000000000000000000000000000000000000000000000000000000000000000"_h, - 0, - std::vector { - transaction_trace - } - }; - - mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t { - BOOST_TEST(height == 1); - return std::make_tuple(data_log_entry(block_trace), false); - }; - - mock_get_block = [&block_trace]( uint32_t height, const yield_function& ) -> get_block_t { - BOOST_TEST(height == 1); - return std::make_tuple(data_log_entry(block_trace), true); - }; - - // simulate data_handler failing - mock_data_handler_v1 = [&](const action_trace_v1&, const yield_function&) -> std::tuple> { - throw std::runtime_error("mock error"); - }; - - // no other yield calls will throw - yield_function yield = [&]() {}; - - BOOST_REQUIRE_THROW(get_block_trace( 1, yield ), std::runtime_error); - } - BOOST_FIXTURE_TEST_CASE(old_version_block_response, response_test_fixture) { auto block_trace = block_trace_v0 { diff --git a/tests/trace_plugin_test.py b/tests/trace_plugin_test.py index 0ab7836e0d..aecca71123 100755 --- a/tests/trace_plugin_test.py +++ b/tests/trace_plugin_test.py @@ -99,15 +99,16 @@ def test_TraceApi(self) : # relaunch with no time allocated for http response & abi-serializer. Will fail because get_info fails. node.kill(signal.SIGTERM) Utils.Print("Ignore expected: ERROR: Node relaunch Failed") - isRelaunchSuccess = node.relaunch(timeout=10, addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "10"}) + isRelaunchSuccess = node.relaunch(timeout=10, addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "0"}) + # Verify get block_trace still works even with no time for http-max-response-time-ms and no time for bi-serializer-max-time-ms cmdDesc="get block_trace" cmd=" --print-response %s %d" % (cmdDesc, blockNum) cmd="%s %s %s" % (Utils.EosClientPath, node.eosClientArgs(), cmd) result=Utils.runCmdReturnStr(cmd, ignoreError=True) Utils.Print(f"{cmdDesc} returned: {result}") - self.assertIn("Internal Server Error", result) + self.assertIn("test transfer a->b", result) @classmethod def setUpClass(self): From a752b48c999e77ca8068a81471dff3e4f6eca4d7 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 31 Jul 2023 09:16:53 -0500 Subject: [PATCH 11/12] GH-1433 get_info can't fail do to deadline, so relaunch does not indicate failure --- tests/trace_plugin_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/trace_plugin_test.py b/tests/trace_plugin_test.py index aecca71123..1bfe110c60 100755 --- a/tests/trace_plugin_test.py +++ b/tests/trace_plugin_test.py @@ -96,10 +96,10 @@ def test_TraceApi(self) : global testSuccessful testSuccessful = True - # relaunch with no time allocated for http response & abi-serializer. Will fail because get_info fails. + # relaunch with no time allocated for http response & abi-serializer node.kill(signal.SIGTERM) - Utils.Print("Ignore expected: ERROR: Node relaunch Failed") isRelaunchSuccess = node.relaunch(timeout=10, addSwapFlags={"--http-max-response-time-ms": "0", "--abi-serializer-max-time-ms": "0"}) + self.assertTrue(isRelaunchSuccess) # Verify get block_trace still works even with no time for http-max-response-time-ms and no time for bi-serializer-max-time-ms cmdDesc="get block_trace" From f0f7ebe1719370b21dbd1750475a15663e0ddaca Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Mon, 31 Jul 2023 09:39:40 -0500 Subject: [PATCH 12/12] GH-1433 Update comment --- tests/plugin_http_api_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugin_http_api_test.py b/tests/plugin_http_api_test.py index 879ee9dd83..c903173ff6 100755 --- a/tests/plugin_http_api_test.py +++ b/tests/plugin_http_api_test.py @@ -1416,7 +1416,7 @@ def test_TraceApi(self) : # get_transaction_trace with invalid parameter ret_json = self.nodeos.processUrllibRequest(resource, command, self.http_post_invalid_param) self.assertEqual(ret_json["code"], 400) - # get_transaction_trace with valid parameter + # get_transaction_trace with syntactically correct id parameter, but random id, so should return 404 (not found) payload = {"id":"f6e325a524e0d75c2275e7d9c2d9e065a38760c29b1d0471a75ccde650ef26d6"} ret_json = self.nodeos.processUrllibRequest(resource, command, payload) self.assertEqual(ret_json["code"], 404)