diff --git a/Makefile.am b/Makefile.am index bf225930..647cf118 100644 --- a/Makefile.am +++ b/Makefile.am @@ -70,7 +70,8 @@ src_libbitcoin_node_la_SOURCES = \ src/protocols/protocol_performer.cpp \ src/protocols/protocol_transaction_in_106.cpp \ src/protocols/protocol_transaction_out_106.cpp \ - src/rest/rest.cpp \ + src/rest/media.cpp \ + src/rest/parse.cpp \ src/sessions/session.cpp \ src/sessions/session_inbound.cpp \ src/sessions/session_manual.cpp \ @@ -107,7 +108,8 @@ test_libbitcoin_node_test_SOURCES = \ test/chasers/chaser_transaction.cpp \ test/chasers/chaser_validate.cpp \ test/protocols/protocol.cpp \ - test/rest/rest.cpp \ + test/rest/media.cpp \ + test/rest/parse.cpp \ test/sessions/session.cpp endif WITH_TESTS @@ -229,7 +231,8 @@ include_bitcoin_node_protocols_HEADERS = \ include_bitcoin_node_restdir = ${includedir}/bitcoin/node/rest include_bitcoin_node_rest_HEADERS = \ - include/bitcoin/node/rest/rest.hpp + include/bitcoin/node/rest/media.hpp \ + include/bitcoin/node/rest/parse.hpp include_bitcoin_node_sessionsdir = ${includedir}/bitcoin/node/sessions include_bitcoin_node_sessions_HEADERS = \ diff --git a/builds/cmake/CMakeLists.txt b/builds/cmake/CMakeLists.txt index 3cd13f0b..c19df0f2 100644 --- a/builds/cmake/CMakeLists.txt +++ b/builds/cmake/CMakeLists.txt @@ -282,7 +282,8 @@ add_library( ${CANONICAL_LIB_NAME} "../../src/protocols/protocol_performer.cpp" "../../src/protocols/protocol_transaction_in_106.cpp" "../../src/protocols/protocol_transaction_out_106.cpp" - "../../src/rest/rest.cpp" + "../../src/rest/media.cpp" + "../../src/rest/parse.cpp" "../../src/sessions/session.cpp" "../../src/sessions/session_inbound.cpp" "../../src/sessions/session_manual.cpp" @@ -349,7 +350,8 @@ if (with-tests) "../../test/chasers/chaser_transaction.cpp" "../../test/chasers/chaser_validate.cpp" "../../test/protocols/protocol.cpp" - "../../test/rest/rest.cpp" + "../../test/rest/media.cpp" + "../../test/rest/parse.cpp" "../../test/sessions/session.cpp" ) add_test( NAME libbitcoin-node-test COMMAND libbitcoin-node-test diff --git a/builds/msvc/vs2022/libbitcoin-network.import.props b/builds/msvc/vs2022/libbitcoin-network.import.props index e4c5a13c..c88f62d5 100644 --- a/builds/msvc/vs2022/libbitcoin-network.import.props +++ b/builds/msvc/vs2022/libbitcoin-network.import.props @@ -16,6 +16,7 @@ $(ProjectDir)..\..\..\..\..\libbitcoin-network\include\;%(AdditionalIncludeDirectories) + /bigobj %(AdditionalOptions) BCT_STATIC;%(PreprocessorDefinitions) diff --git a/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj b/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj index 7fe9a4f7..de7aa517 100644 --- a/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj @@ -135,7 +135,8 @@ - + + diff --git a/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj.filters index cde5b15b..701c4694 100644 --- a/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node-test/libbitcoin-node-test.vcxproj.filters @@ -75,7 +75,10 @@ src\protocols - + + src\rest + + src\rest diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj index 8912f211..adb38705 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj @@ -155,7 +155,8 @@ - + + @@ -218,7 +219,8 @@ - + + diff --git a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters index 4387b644..11beb04e 100644 --- a/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters +++ b/builds/msvc/vs2022/libbitcoin-node/libbitcoin-node.vcxproj.filters @@ -162,7 +162,10 @@ src\protocols - + + src\rest + + src\rest @@ -347,7 +350,10 @@ include\bitcoin\node\protocols - + + include\bitcoin\node\rest + + include\bitcoin\node\rest diff --git a/include/bitcoin/node.hpp b/include/bitcoin/node.hpp index 1108661f..3d166ce1 100644 --- a/include/bitcoin/node.hpp +++ b/include/bitcoin/node.hpp @@ -71,7 +71,8 @@ #include #include #include -#include +#include +#include #include #include #include diff --git a/include/bitcoin/node/protocols/protocol.hpp b/include/bitcoin/node/protocols/protocol.hpp index 37b83e6b..9b820302 100644 --- a/include/bitcoin/node/protocols/protocol.hpp +++ b/include/bitcoin/node/protocols/protocol.hpp @@ -30,18 +30,6 @@ namespace libbitcoin { namespace node { -// TODO: first split node::protocol -> node::protocol and node::protocol_peer. -// TODO: then create node::protocol_peer -> node::protocol + network::protocol_peer. -// TODO: then create node::protocol_tcp -> node::protocol + network::protocol_tcp. -// TODO: this is the same pattern as joining node::session + network::session_xxxx. -// TODO: node::session_xxx => node::session_peer : node::session. -// TODO: node::protocol_xxx => node::protocol_peer : node::protocol. -// TODO: none of the node classes derive from shared_from_base and instead just -// TODO: rely on the network base class and shared_from_sibling<> to obtain -// TODO: node object methods within protocol_peer and derived, just as in -// TODO: session_peer and derived. This could be normalized using an override -// TODO: of shared_from_base<>() withing the two templates. - /// Abstract base for node protocols, thread safe. class BCN_API protocol { diff --git a/include/bitcoin/node/protocols/protocol_html.hpp b/include/bitcoin/node/protocols/protocol_html.hpp index 847eedf2..da11cb04 100644 --- a/include/bitcoin/node/protocols/protocol_html.hpp +++ b/include/bitcoin/node/protocols/protocol_html.hpp @@ -67,13 +67,13 @@ class BCN_API protocol_html virtual void send_data(const network::http::request& request, system::data_chunk&& bytes) NOEXCEPT; virtual void send_file(const network::http::request& request, - network::http::file&& file, network::http::mime_type type) NOEXCEPT; + network::http::file&& file, network::http::media_type type) NOEXCEPT; virtual void send_span(const network::http::request& request, network::http::span_body::value_type&& span, - network::http::mime_type type) NOEXCEPT; + network::http::media_type type) NOEXCEPT; virtual void send_buffer(const network::http::request& request, network::http::buffer_body::value_type&& buffer, - network::http::mime_type type) NOEXCEPT; + network::http::media_type type) NOEXCEPT; /// Utilities. bool is_allowed_origin(const network::http::fields& fields, diff --git a/include/bitcoin/node/rest/media.hpp b/include/bitcoin/node/rest/media.hpp new file mode 100644 index 00000000..9eafec7b --- /dev/null +++ b/include/bitcoin/node/rest/media.hpp @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#ifndef LIBBITCOIN_NODE_MEDIA_HPP +#define LIBBITCOIN_NODE_MEDIA_HPP + +#include + +namespace libbitcoin { +namespace node { + +BCN_API bool get_acceptable_media_type(network::http::media_type& out, + const network::http::request& request) NOEXCEPT; + +} // namespace network +} // namespace libbitcoin + +#endif diff --git a/include/bitcoin/node/rest/rest.hpp b/include/bitcoin/node/rest/parse.hpp similarity index 84% rename from include/bitcoin/node/rest/rest.hpp rename to include/bitcoin/node/rest/parse.hpp index 1ea47785..b46a1b8a 100644 --- a/include/bitcoin/node/rest/rest.hpp +++ b/include/bitcoin/node/rest/parse.hpp @@ -16,16 +16,16 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#ifndef LIBBITCOIN_NODE_REST_HPP -#define LIBBITCOIN_NODE_REST_HPP +#ifndef LIBBITCOIN_NODE_PARSE_HPP +#define LIBBITCOIN_NODE_PARSE_HPP #include namespace libbitcoin { namespace node { -BCN_API code path_to_request(network::rpc::request_t& out, - const std::string& path) NOEXCEPT; +BCN_API code parse_request(network::rpc::request_t& out, + const std::string_view& path) NOEXCEPT; } // namespace network } // namespace libbitcoin diff --git a/src/protocols/protocol_explore.cpp b/src/protocols/protocol_explore.cpp index 87fbca27..ae589361 100644 --- a/src/protocols/protocol_explore.cpp +++ b/src/protocols/protocol_explore.cpp @@ -19,6 +19,8 @@ #include #include +#include +#include namespace libbitcoin { namespace node { @@ -26,6 +28,7 @@ namespace node { #define CLASS protocol_explore using namespace system; +using namespace network::rpc; using namespace network::http; BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) @@ -35,141 +38,116 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT) bool protocol_explore::try_dispatch_object(const request& request) NOEXCEPT { - wallet::uri uri{}; - if (!uri.decode(request.target())) + media_type accept{}; + if (!get_acceptable_media_type(accept, request)) { send_bad_target(request); return true; } - const auto parts = split(uri.path(), "/"); - if (parts.size() != two) - return false; - - const auto hd = parts.front() == "header" || parts.front() == "hd"; - const auto bk = parts.front() == "block" || parts.front() == "bk"; - const auto tx = parts.front() == "transaction" || parts.front() == "tx"; - if (!hd && !bk && !tx) - { - send_bad_target(request); - return true; - } - - auto params = uri.decode_query(); - const auto format = params["format"]; - constexpr auto text = mime_type::text_plain; - constexpr auto json = mime_type::application_json; - constexpr auto data = mime_type::application_octet_stream; - const auto accepts = to_mime_types((request)[field::accept]); - const auto is_json = contains(accepts, json) || format == "json"; - const auto is_text = contains(accepts, text) || format == "text"; - const auto is_data = contains(accepts, data) || format == "data"; - if (!is_json && !is_text && !is_data) - return false; - - hash_digest hash{}; - if (!decode_hash(hash, parts.back())) + request_t out{}; + if (const auto ec = parse_request(out, request.target())) { - send_bad_target(request); + send_bad_target(request, ec); return true; } - const auto& query = archive(); - const auto wit = params["witness"] != "false"; - constexpr auto header_size = chain::header::serialized_size(); - - if (is_json) - { - if (hd) - { - if (const auto ptr = query.get_header(query.to_header(hash))) - { - send_json(request, value_from(ptr), header_size); - return true; - } - } - else if (bk) - { - if (const auto ptr = query.get_block(query.to_header(hash), wit)) - { - send_json(request, value_from(ptr), ptr->serialized_size(wit)); - return true; - } - } - else - { - if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) - { - send_json(request, value_from(ptr), ptr->serialized_size(wit)); - return true; - } - } - - send_not_found(request); - return true; - } - - if (is_text) - { - if (hd) - { - if (const auto ptr = query.get_header(query.to_header(hash))) - { - send_text(request, encode_base16(ptr->to_data())); - return true; - } - } - else if (bk) - { - if (const auto ptr = query.get_block(query.to_header(hash), wit)) - { - send_text(request, encode_base16(ptr->to_data(wit))); - return true; - } - } - else - { - if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) - { - send_text(request, encode_base16(ptr->to_data(wit))); - return true; - } - } - - send_not_found(request); - return true; - } - - ////if (is_data) - { - if (hd) - { - if (const auto ptr = query.get_header(query.to_header(hash))) - { - send_data(request, ptr->to_data()); - return true; - } - } - else if (bk) - { - if (const auto ptr = query.get_block(query.to_header(hash), wit)) - { - send_data(request, ptr->to_data(wit)); - return true; - } - } - else - { - if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) - { - send_data(request, ptr->to_data(wit)); - return true; - } - } - - send_not_found(request); - return true; - } + ////const auto& query = archive(); + ////const auto wit = params["witness"] != "false"; + ////constexpr auto header_size = chain::header::serialized_size(); + + ////if (accept == media_type::application_json) + ////{ + //// if (hd) + //// { + //// if (const auto ptr = query.get_header(query.to_header(hash))) + //// { + //// send_json(request, value_from(ptr), header_size); + //// return true; + //// } + //// } + //// else if (bk) + //// { + //// if (const auto ptr = query.get_block(query.to_header(hash), wit)) + //// { + //// send_json(request, value_from(ptr), ptr->serialized_size(wit)); + //// return true; + //// } + //// } + //// else + //// { + //// if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) + //// { + //// send_json(request, value_from(ptr), ptr->serialized_size(wit)); + //// return true; + //// } + //// } + + //// send_not_found(request); + //// return true; + ////} + + ////if (accept == media_type::text_plain) + ////{ + //// if (hd) + //// { + //// if (const auto ptr = query.get_header(query.to_header(hash))) + //// { + //// send_text(request, encode_base16(ptr->to_data())); + //// return true; + //// } + //// } + //// else if (bk) + //// { + //// if (const auto ptr = query.get_block(query.to_header(hash), wit)) + //// { + //// send_text(request, encode_base16(ptr->to_data(wit))); + //// return true; + //// } + //// } + //// else + //// { + //// if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) + //// { + //// send_text(request, encode_base16(ptr->to_data(wit))); + //// return true; + //// } + //// } + + //// send_not_found(request); + //// return true; + ////} + + ////////if (accept == media_type::application_octet_stream) + ////{ + //// if (hd) + //// { + //// if (const auto ptr = query.get_header(query.to_header(hash))) + //// { + //// send_data(request, ptr->to_data()); + //// return true; + //// } + //// } + //// else if (bk) + //// { + //// if (const auto ptr = query.get_block(query.to_header(hash), wit)) + //// { + //// send_data(request, ptr->to_data(wit)); + //// return true; + //// } + //// } + //// else + //// { + //// if (const auto ptr = query.get_transaction(query.to_tx(hash), wit)) + //// { + //// send_data(request, ptr->to_data(wit)); + //// return true; + //// } + //// } + + //// send_not_found(request); + //// return true; + ////} } BC_POP_WARNING() diff --git a/src/protocols/protocol_html.cpp b/src/protocols/protocol_html.cpp index 7e35e0d5..1e94a4e2 100644 --- a/src/protocols/protocol_html.cpp +++ b/src/protocols/protocol_html.cpp @@ -95,25 +95,25 @@ bool protocol_html::try_dispatch_object(const request&) NOEXCEPT void protocol_html::dispatch_embedded(const request& request) NOEXCEPT { const auto& pages = config().server.explore.pages; - switch (const auto mime = file_mime_type(to_path(request.target()))) + switch (const auto media = file_media_type(to_path(request.target()))) { - case mime_type::text_css: - send_span(request, pages.css(), mime); + case media_type::text_css: + send_span(request, pages.css(), media); break; - case mime_type::text_html: - send_span(request, pages.html(), mime); + case media_type::text_html: + send_span(request, pages.html(), media); break; - case mime_type::application_javascript: - send_span(request, pages.ecma(), mime); + case media_type::application_javascript: + send_span(request, pages.ecma(), media); break; - case mime_type::font_woff: - case mime_type::font_woff2: - send_span(request, pages.font(), mime); + case media_type::font_woff: + case media_type::font_woff2: + send_span(request, pages.font(), media); break; - case mime_type::image_png: - case mime_type::image_gif: - case mime_type::image_jpeg: - send_span(request, pages.icon(), mime); + case media_type::image_png: + case media_type::image_gif: + case media_type::image_jpeg: + send_span(request, pages.icon(), media); break; default: send_not_found(request); @@ -151,16 +151,16 @@ void protocol_html::dispatch_file(const request& request) NOEXCEPT return; } - const auto octet_stream = mime_type::application_octet_stream; - send_file(request, std::move(file), file_mime_type(path, octet_stream)); + const auto octet_stream = media_type::application_octet_stream; + send_file(request, std::move(file), file_media_type(path, octet_stream)); } // Senders. // ---------------------------------------------------------------------------- -constexpr auto data = mime_type::application_octet_stream; -constexpr auto json = mime_type::application_json; -constexpr auto text = mime_type::text_plain; +constexpr auto data = media_type::application_octet_stream; +constexpr auto json = media_type::application_json; +constexpr auto text = media_type::text_plain; void protocol_html::send_json(const request& request, boost::json::value&& model, size_t size_hint) NOEXCEPT @@ -168,7 +168,7 @@ void protocol_html::send_json(const request& request, BC_ASSERT(stranded()); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(json)); + response.set(field::content_type, from_media_type(json)); response.body() = { std::move(model), size_hint }; response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); @@ -180,7 +180,7 @@ void protocol_html::send_text(const request& request, BC_ASSERT(stranded()); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(text)); + response.set(field::content_type, from_media_type(text)); response.body() = std::move(hexidecimal); response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); @@ -192,44 +192,44 @@ void protocol_html::send_data(const request& request, BC_ASSERT(stranded()); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(data)); + response.set(field::content_type, from_media_type(data)); response.body() = std::move(bytes); response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); } void protocol_html::send_file(const request& request, file&& file, - mime_type type) NOEXCEPT + media_type type) NOEXCEPT { BC_ASSERT(stranded()); BC_ASSERT_MSG(file.is_open(), "sending closed file handle"); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(type)); + response.set(field::content_type, from_media_type(type)); response.body() = std::move(file); response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); } void protocol_html::send_span(const request& request, - span_body::value_type&& span, mime_type type) NOEXCEPT + span_body::value_type&& span, media_type type) NOEXCEPT { BC_ASSERT(stranded()); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(type)); + response.set(field::content_type, from_media_type(type)); response.body() = std::move(span); response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); } void protocol_html::send_buffer(const request& request, - buffer_body::value_type&& buffer, mime_type type) NOEXCEPT + buffer_body::value_type&& buffer, media_type type) NOEXCEPT { BC_ASSERT(stranded()); response response{ status::ok, request.version() }; add_common_headers(response, request); - response.set(field::content_type, from_mime_type(type)); + response.set(field::content_type, from_media_type(type)); response.body() = std::move(buffer); response.prepare_payload(); SEND(std::move(response), handle_complete, _1, error::success); diff --git a/src/rest/media.cpp b/src/rest/media.cpp new file mode 100644 index 00000000..48a51778 --- /dev/null +++ b/src/rest/media.cpp @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#include + +#include + +namespace libbitcoin { +namespace node { + +using namespace system; +using namespace network::http; + +bool get_acceptable_media_type(media_type& out, + const request& request) NOEXCEPT +{ + wallet::uri uri{}; + if (!uri.decode(request.target())) + return false; + + constexpr auto text = media_type::text_plain; + constexpr auto json = media_type::application_json; + constexpr auto data = media_type::application_octet_stream; + const auto accepts = to_media_types((request)[field::accept]); + const auto format = uri.decode_query()["format"]; + + if (contains(accepts, json) || format == "json") + { + out = json; + return true; + } + + if (contains(accepts, text) || format == "text") + { + out = text; + return true; + } + + if (contains(accepts, data) || format == "data") + { + out = data; + return true; + } + + return false; +} + +} // namespace node +} // namespace libbitcoin diff --git a/src/rest/rest.cpp b/src/rest/parse.cpp similarity index 98% rename from src/rest/rest.cpp rename to src/rest/parse.cpp index 3dc38b43..985ee657 100644 --- a/src/rest/rest.cpp +++ b/src/rest/parse.cpp @@ -16,7 +16,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include +#include #include #include @@ -46,7 +46,7 @@ static hash_cptr to_hash(const std::string_view& token) NOEXCEPT emplace_shared(std::move(out)) : hash_cptr{}; } -code path_to_request(request_t& out, const std::string& path) NOEXCEPT +code parse_request(request_t& out, const std::string_view& path) NOEXCEPT { if (path.empty()) return error::empty_path; diff --git a/test/rest/media.cpp b/test/rest/media.cpp new file mode 100644 index 00000000..d8d04d3d --- /dev/null +++ b/test/rest/media.cpp @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2011-2025 libbitcoin developers (see AUTHORS) + * + * This file is part of libbitcoin. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#include "../test.hpp" + +BOOST_AUTO_TEST_SUITE(media_tests) + +using namespace network::http; + +BOOST_AUTO_TEST_CASE(media__get_acceptable_media_type__empty__false) +{ + media_type out{}; + BOOST_REQUIRE(!get_acceptable_media_type(out, request{})); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/test/rest/rest.cpp b/test/rest/parse.cpp similarity index 68% rename from test/rest/rest.cpp rename to test/rest/parse.cpp index ca9bf1c8..e6411726 100644 --- a/test/rest/rest.cpp +++ b/test/rest/parse.cpp @@ -18,7 +18,7 @@ */ #include "../test.hpp" -BOOST_AUTO_TEST_SUITE(rest_parser_tests) +BOOST_AUTO_TEST_SUITE(parse_tests) using namespace system; using namespace network::rpc; @@ -26,51 +26,51 @@ using object_t = network::rpc::object_t; // General errors -BOOST_AUTO_TEST_CASE(path_to_request__empty_path__empty_path) +BOOST_AUTO_TEST_CASE(parse__parse_request__empty_path__empty_path) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, ""), node::error::empty_path); + BOOST_REQUIRE_EQUAL(parse_request(out, ""), node::error::empty_path); } -BOOST_AUTO_TEST_CASE(path_to_request__missing_version__missing_version) +BOOST_AUTO_TEST_CASE(parse__parse_request__missing_version__missing_version) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/"), node::error::missing_version); - BOOST_REQUIRE_EQUAL(path_to_request(out, "/block/height/123"), node::error::missing_version); + BOOST_REQUIRE_EQUAL(parse_request(out, "/"), node::error::missing_version); + BOOST_REQUIRE_EQUAL(parse_request(out, "/block/height/123"), node::error::missing_version); } -BOOST_AUTO_TEST_CASE(path_to_request__invalid_version__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__invalid_version__invalid_number) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/vinvalid/block/height/123"), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, "/vinvalid/block/height/123"), node::error::invalid_number); } -BOOST_AUTO_TEST_CASE(path_to_request__version_leading_zero__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__version_leading_zero__invalid_number) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v01/block/height/123"), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v01/block/height/123"), node::error::invalid_number); } -BOOST_AUTO_TEST_CASE(path_to_request__missing_target__missing_target) +BOOST_AUTO_TEST_CASE(parse__parse_request__missing_target__missing_target) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3"), node::error::missing_target); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3"), node::error::missing_target); } -BOOST_AUTO_TEST_CASE(path_to_request__invalid_target__invalid_target) +BOOST_AUTO_TEST_CASE(parse__parse_request__invalid_target__invalid_target) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/invalid"), node::error::invalid_target); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/invalid"), node::error::invalid_target); } // block/hash -BOOST_AUTO_TEST_CASE(path_to_request__block_hash_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_hash_valid__expected) { const std::string path = "//v42//block//hash//0000000000000000000000000000000000000000000000000000000000000042//"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "block"); BOOST_REQUIRE(request.params.has_value()); @@ -91,37 +91,37 @@ BOOST_AUTO_TEST_CASE(path_to_request__block_hash_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__block_hash_missing_hash__missing_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_hash_missing_hash__missing_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/hash"), node::error::missing_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/hash"), node::error::missing_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__block_hash_invalid_hash__invalid_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_hash_invalid_hash__invalid_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/hash/invalidhex"), node::error::invalid_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/hash/invalidhex"), node::error::invalid_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__block_hash_invalid_component__invalid_component) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_hash_invalid_component__invalid_component) { const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/invalid"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::invalid_component); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::invalid_component); } -BOOST_AUTO_TEST_CASE(path_to_request__block_invalid_id_type__invalid_id_type) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_invalid_id_type__invalid_id_type) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/invalid/123"), node::error::invalid_id_type); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/invalid/123"), node::error::invalid_id_type); } // header/height -BOOST_AUTO_TEST_CASE(path_to_request__header_height_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__header_height_valid__expected) { request_t request{}; - BOOST_REQUIRE(!path_to_request(request, "/v42/block/height/123456/header/")); + BOOST_REQUIRE(!parse_request(request, "/v42/block/height/123456/header/")); BOOST_REQUIRE_EQUAL(request.method, "header"); BOOST_REQUIRE(request.params.has_value()); @@ -138,20 +138,20 @@ BOOST_AUTO_TEST_CASE(path_to_request__header_height_valid__expected) BOOST_REQUIRE_EQUAL(height, 123456u); } -BOOST_AUTO_TEST_CASE(path_to_request__header_height_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__header_height_extra_segment__extra_segment) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/header/extra"), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/header/extra"), node::error::extra_segment); } // header/hash -BOOST_AUTO_TEST_CASE(path_to_request__header_hash_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__header_hash_valid__expected) { const std::string path = "v42/block/hash/0000000000000000000000000000000000000000000000000000000000000042/header"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "header"); BOOST_REQUIRE(request.params.has_value()); @@ -172,19 +172,19 @@ BOOST_AUTO_TEST_CASE(path_to_request__header_hash_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__header_hash_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__header_hash_extra_segment__extra_segment) { const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/header/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // filter/height -BOOST_AUTO_TEST_CASE(path_to_request__filter_height_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__filter_height_valid__expected) { request_t request{}; - BOOST_REQUIRE(!path_to_request(request, "v42/block/height/123456/filter/")); + BOOST_REQUIRE(!parse_request(request, "v42/block/height/123456/filter/")); BOOST_REQUIRE_EQUAL(request.method, "filter"); BOOST_REQUIRE(request.params.has_value()); @@ -201,20 +201,20 @@ BOOST_AUTO_TEST_CASE(path_to_request__filter_height_valid__expected) BOOST_REQUIRE_EQUAL(height, 123456u); } -BOOST_AUTO_TEST_CASE(path_to_request__filter_height_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__filter_height_extra_segment__extra_segment) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/filter/extra"), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/filter/extra"), node::error::extra_segment); } // filter/hash -BOOST_AUTO_TEST_CASE(path_to_request__filter_hash_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__filter_hash_valid__expected) { const std::string path = "/v42/block/hash/0000000000000000000000000000000000000000000000000000000000000042/filter"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "filter"); BOOST_REQUIRE(request.params.has_value()); @@ -235,19 +235,19 @@ BOOST_AUTO_TEST_CASE(path_to_request__filter_hash_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__filter_hash_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__filter_hash_extra_segment__extra_segment) { const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/filter/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // block_txs/height -BOOST_AUTO_TEST_CASE(path_to_request__block_txs_height_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_txs_height_valid__expected) { request_t request{}; - BOOST_REQUIRE(!path_to_request(request, "/v42/block/height/123456/transactions")); + BOOST_REQUIRE(!parse_request(request, "/v42/block/height/123456/transactions")); BOOST_REQUIRE_EQUAL(request.method, "block_txs"); BOOST_REQUIRE(request.params.has_value()); @@ -264,20 +264,20 @@ BOOST_AUTO_TEST_CASE(path_to_request__block_txs_height_valid__expected) BOOST_REQUIRE_EQUAL(height, 123456u); } -BOOST_AUTO_TEST_CASE(path_to_request__block_txs_height_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_txs_height_extra_segment__extra_segment) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/transactions/extra"), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/transactions/extra"), node::error::extra_segment); } // block_txs/hash -BOOST_AUTO_TEST_CASE(path_to_request__block_txs_hash_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_txs_hash_valid__expected) { const std::string path = "/v42/block/hash/0000000000000000000000000000000000000000000000000000000000000042/transactions"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "block_txs"); BOOST_REQUIRE(request.params.has_value()); @@ -298,19 +298,19 @@ BOOST_AUTO_TEST_CASE(path_to_request__block_txs_hash_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__block_txs_hash_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_txs_hash_extra_segment__extra_segment) { const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transactions/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // block_tx/height -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_height_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_height_valid__expected) { request_t request{}; - BOOST_REQUIRE(!path_to_request(request, "/v42/block/height/123456/transaction/7")); + BOOST_REQUIRE(!parse_request(request, "/v42/block/height/123456/transaction/7")); BOOST_REQUIRE_EQUAL(request.method, "block_tx"); BOOST_REQUIRE(request.params.has_value()); @@ -330,32 +330,32 @@ BOOST_AUTO_TEST_CASE(path_to_request__block_tx_height_valid__expected) BOOST_REQUIRE_EQUAL(position, 7u); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_height_missing_position__missing_position) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_height_missing_position__missing_position) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/transaction"), node::error::missing_position); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/transaction"), node::error::missing_position); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_height_invalid_position__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_height_invalid_position__invalid_number) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/transaction/invalid"), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/transaction/invalid"), node::error::invalid_number); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_height_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_height_extra_segment__extra_segment) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/height/123/transaction/7/extra"), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/height/123/transaction/7/extra"), node::error::extra_segment); } // block_tx/hash -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_hash_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_hash_valid__expected) { const std::string path = "/v42/block/hash/0000000000000000000000000000000000000000000000000000000000000042/transaction/7"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "block_tx"); BOOST_REQUIRE(request.params.has_value()); @@ -379,33 +379,33 @@ BOOST_AUTO_TEST_CASE(path_to_request__block_tx_hash_valid__expected) BOOST_REQUIRE_EQUAL(position, 7u); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_hash_missing_position__missing_position) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_hash_missing_position__missing_position) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transaction"), node::error::missing_position); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transaction"), node::error::missing_position); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_hash_invalid_position__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_hash_invalid_position__invalid_number) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transaction/invalid"), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transaction/invalid"), node::error::invalid_number); } -BOOST_AUTO_TEST_CASE(path_to_request__block_tx_hash_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__block_tx_hash_extra_segment__extra_segment) { const std::string path = "/v3/block/hash/0000000000000000000000000000000000000000000000000000000000000000/transaction/7/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // inputs -BOOST_AUTO_TEST_CASE(path_to_request__inputs_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__inputs_valid__expected) { const std::string path = "/v255/inputs/0000000000000000000000000000000000000000000000000000000000000042"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "inputs"); BOOST_REQUIRE(request.params.has_value()); @@ -426,33 +426,33 @@ BOOST_AUTO_TEST_CASE(path_to_request__inputs_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__inputs_missing_hash__missing_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__inputs_missing_hash__missing_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/inputs"), node::error::missing_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/inputs"), node::error::missing_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__inputs_invalid_hash__invalid_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__inputs_invalid_hash__invalid_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/inputs/invalidhex"), node::error::invalid_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/inputs/invalidhex"), node::error::invalid_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__inputs_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__inputs_extra_segment__extra_segment) { const std::string path = "/v3/inputs/0000000000000000000000000000000000000000000000000000000000000000/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // input -BOOST_AUTO_TEST_CASE(path_to_request__input_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_valid__expected) { const std::string path = "/v255/input/0000000000000000000000000000000000000000000000000000000000000042/3"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "input"); BOOST_REQUIRE(request.params.has_value()); @@ -476,40 +476,40 @@ BOOST_AUTO_TEST_CASE(path_to_request__input_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__input_missing_hash__missing_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_missing_hash__missing_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/input"), node::error::missing_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/input"), node::error::missing_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__input_invalid_hash__invalid_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_invalid_hash__invalid_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/input/invalidhex/3"), node::error::invalid_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/input/invalidhex/3"), node::error::invalid_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__input_missing_component__missing_component) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_missing_component__missing_component) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::missing_component); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::missing_component); } -BOOST_AUTO_TEST_CASE(path_to_request__input_invalid_index__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_invalid_index__invalid_number) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/invalid"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::invalid_number); } // input_script -BOOST_AUTO_TEST_CASE(path_to_request__input_script_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_script_valid__expected) { const std::string path = "/v255/input/0000000000000000000000000000000000000000000000000000000000000042/3/script"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "input_script"); BOOST_REQUIRE(request.params.has_value()); @@ -533,28 +533,28 @@ BOOST_AUTO_TEST_CASE(path_to_request__input_script_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__input_script_invalid_subcomponent__invalid_subcomponent) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_script_invalid_subcomponent__invalid_subcomponent) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/3/invalid"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::invalid_subcomponent); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::invalid_subcomponent); } -BOOST_AUTO_TEST_CASE(path_to_request__input_script_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_script_extra_segment__extra_segment) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/3/script/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // input_scripts -BOOST_AUTO_TEST_CASE(path_to_request__input_scripts_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_scripts_valid__expected) { const std::string path = "/v255/input/0000000000000000000000000000000000000000000000000000000000000042/scripts"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "input_scripts"); BOOST_REQUIRE(request.params.has_value()); @@ -575,21 +575,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__input_scripts_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__input_scripts_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_scripts_extra_segment__extra_segment) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/scripts/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // input_witness -BOOST_AUTO_TEST_CASE(path_to_request__input_witness_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_witness_valid__expected) { const std::string path = "/v255/input/0000000000000000000000000000000000000000000000000000000000000042/3/witness"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "input_witness"); BOOST_REQUIRE(request.params.has_value()); @@ -613,21 +613,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__input_witness_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__input_witness_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_witness_extra_segment__extra_segment) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/3/witness/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // input_witnesses -BOOST_AUTO_TEST_CASE(path_to_request__input_witnesses_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_witnesses_valid__expected) { const std::string path = "/v255/input/0000000000000000000000000000000000000000000000000000000000000042/witnesses"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "input_witnesses"); BOOST_REQUIRE(request.params.has_value()); @@ -648,21 +648,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__input_witnesses_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__input_witnesses_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__input_witnesses_extra_segment__extra_segment) { const std::string path = "/v3/input/0000000000000000000000000000000000000000000000000000000000000000/witnesses/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // outputs -BOOST_AUTO_TEST_CASE(path_to_request__outputs_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__outputs_valid__expected) { const std::string path = "/v255/outputs/0000000000000000000000000000000000000000000000000000000000000042"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "outputs"); BOOST_REQUIRE(request.params.has_value()); @@ -683,33 +683,33 @@ BOOST_AUTO_TEST_CASE(path_to_request__outputs_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__outputs_missing_hash__missing_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__outputs_missing_hash__missing_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/outputs"), node::error::missing_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/outputs"), node::error::missing_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__outputs_invalid_hash__invalid_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__outputs_invalid_hash__invalid_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/outputs/invalidhex"), node::error::invalid_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/outputs/invalidhex"), node::error::invalid_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__outputs_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__outputs_extra_segment__extra_segment) { const std::string path = "/v3/outputs/0000000000000000000000000000000000000000000000000000000000000000/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // output -BOOST_AUTO_TEST_CASE(path_to_request__output_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_valid__expected) { const std::string path = "/v255/output/0000000000000000000000000000000000000000000000000000000000000042/3"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "output"); BOOST_REQUIRE(request.params.has_value()); @@ -733,28 +733,28 @@ BOOST_AUTO_TEST_CASE(path_to_request__output_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__output_missing_component__missing_component) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_missing_component__missing_component) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::missing_component); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::missing_component); } -BOOST_AUTO_TEST_CASE(path_to_request__output_invalid_index__invalid_number) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_invalid_index__invalid_number) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/invalid"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::invalid_number); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::invalid_number); } // output_script -BOOST_AUTO_TEST_CASE(path_to_request__output_script_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_script_valid__expected) { const std::string path = "/v255/output/0000000000000000000000000000000000000000000000000000000000000042/3/script"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "output_script"); BOOST_REQUIRE(request.params.has_value()); @@ -778,28 +778,28 @@ BOOST_AUTO_TEST_CASE(path_to_request__output_script_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__output_script_invalid_subcomponent__invalid_subcomponent) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_script_invalid_subcomponent__invalid_subcomponent) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/invalid"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::invalid_subcomponent); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::invalid_subcomponent); } -BOOST_AUTO_TEST_CASE(path_to_request__output_script_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_script_extra_segment__extra_segment) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/script/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // output_scripts -BOOST_AUTO_TEST_CASE(path_to_request__output_scripts_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_scripts_valid__expected) { const std::string path = "/v255/output/0000000000000000000000000000000000000000000000000000000000000042/scripts"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "output_scripts"); BOOST_REQUIRE(request.params.has_value()); @@ -820,21 +820,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__output_scripts_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__output_scripts_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_scripts_extra_segment__extra_segment) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/scripts/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // output_spender -BOOST_AUTO_TEST_CASE(path_to_request__output_spender_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_spender_valid__expected) { const std::string path = "/v255/output/0000000000000000000000000000000000000000000000000000000000000042/3/spender"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "output_spender"); BOOST_REQUIRE(request.params.has_value()); @@ -858,21 +858,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__output_spender_valid__expected) BOOST_REQUIRE_EQUAL(index, 3u); } -BOOST_AUTO_TEST_CASE(path_to_request__output_spender_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_spender_extra_segment__extra_segment) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/3/spender/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // output_spenders -BOOST_AUTO_TEST_CASE(path_to_request__output_spenders_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_spenders_valid__expected) { const std::string path = "/v255/output/0000000000000000000000000000000000000000000000000000000000000042/spenders"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "output_spenders"); BOOST_REQUIRE(request.params.has_value()); @@ -893,21 +893,21 @@ BOOST_AUTO_TEST_CASE(path_to_request__output_spenders_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__output_spenders_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__output_spenders_extra_segment__extra_segment) { const std::string path = "/v3/output/0000000000000000000000000000000000000000000000000000000000000000/spenders/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } // address -BOOST_AUTO_TEST_CASE(path_to_request__address_valid__expected) +BOOST_AUTO_TEST_CASE(parse__parse_request__address_valid__expected) { const std::string path = "/v255/address/0000000000000000000000000000000000000000000000000000000000000042"; request_t request{}; - BOOST_REQUIRE(!path_to_request(request, path)); + BOOST_REQUIRE(!parse_request(request, path)); BOOST_REQUIRE_EQUAL(request.method, "address"); BOOST_REQUIRE(request.params.has_value()); @@ -928,23 +928,23 @@ BOOST_AUTO_TEST_CASE(path_to_request__address_valid__expected) BOOST_REQUIRE_EQUAL(to_uintx(*hash_cptr), uint256_t{ 0x42 }); } -BOOST_AUTO_TEST_CASE(path_to_request__address_missing_hash__missing_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__address_missing_hash__missing_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/address"), node::error::missing_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/address"), node::error::missing_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__address_invalid_hash__invalid_hash) +BOOST_AUTO_TEST_CASE(parse__parse_request__address_invalid_hash__invalid_hash) { request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, "/v3/address/invalidhex"), node::error::invalid_hash); + BOOST_REQUIRE_EQUAL(parse_request(out, "/v3/address/invalidhex"), node::error::invalid_hash); } -BOOST_AUTO_TEST_CASE(path_to_request__address_extra_segment__extra_segment) +BOOST_AUTO_TEST_CASE(parse__parse_request__address_extra_segment__extra_segment) { const std::string path = "/v3/address/0000000000000000000000000000000000000000000000000000000000000000/extra"; request_t out{}; - BOOST_REQUIRE_EQUAL(path_to_request(out, path), node::error::extra_segment); + BOOST_REQUIRE_EQUAL(parse_request(out, path), node::error::extra_segment); } BOOST_AUTO_TEST_SUITE_END()