Skip to content

Commit cc462f2

Browse files
committed
Full test coverage for path_to_request.
1 parent b758282 commit cc462f2

File tree

2 files changed

+876
-36
lines changed

2 files changed

+876
-36
lines changed

src/rest/rest.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ static hash_cptr to_hash(const std::string_view& token) NOEXCEPT
4848

4949
code path_to_request(request_t& out, const std::string& path) NOEXCEPT
5050
{
51+
if (path.empty())
52+
return error::empty_path;
53+
5154
// Avoid conflict with node type.
5255
using object_t = network::rpc::object_t;
5356

@@ -63,8 +66,7 @@ code path_to_request(request_t& out, const std::string& path) NOEXCEPT
6366
auto& method = out.method;
6467
auto& params = std::get<object_t>(out.params.value());
6568
const auto segments = split(path, "/", false, true);
66-
if (segments.empty())
67-
return error::empty_path;
69+
BC_ASSERT(!segments.empty());
6870

6971
size_t segment{};
7072
if (!segments[segment].starts_with('v'))
@@ -256,24 +258,26 @@ code path_to_request(request_t& out, const std::string& path) NOEXCEPT
256258
else
257259
{
258260
const auto component = segments[segment++];
259-
if (component == "header")
261+
if (component == "transaction")
262+
{
263+
if (segment == segments.size())
264+
return error::missing_position;
265+
266+
uint32_t position{};
267+
if (!to_number(position, segments[segment++]))
268+
return error::invalid_number;
269+
270+
params["position"] = position;
271+
method = "block_tx";
272+
}
273+
else if (component == "header")
260274
method = "header";
261275
else if (component == "filter")
262276
method = "filter";
263277
else if (component == "transactions")
264278
method = "block_txs";
265-
else if (component != "transaction")
279+
else
266280
return error::invalid_component;
267-
268-
if (segment == segments.size())
269-
return error::missing_position;
270-
271-
uint32_t position{};
272-
if (!to_number(position, segments[segment++]))
273-
return error::invalid_number;
274-
275-
params["position"] = position;
276-
method = "block_tx";
277281
}
278282
}
279283
else

0 commit comments

Comments
 (0)