Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/dev_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ apply_routes(Msg, R, Opts) ->
%% - `match' and `with': A regex to replace in the path.
apply_route(Msg, Route, Opts) ->
% LoadedRoute = hb_cache:ensure_all_loaded(Route, Opts),
RouteOpts = hb_maps:get(<<"opts">>, Route, #{}),
RouteOpts = hb_opts:mimic_default_types(
hb_maps:get(<<"opts">>, Route, #{}), existing, Opts),
{ok, #{
<<"opts">> => RouteOpts,
<<"uri">> =>
Expand Down
4 changes: 2 additions & 2 deletions src/dev_scheduler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ redirect_from_graphql() ->
#{ store =>
[
#{ <<"store-module">> => hb_store_fs, <<"name">> => <<"cache-mainnet">> },
#{ <<"store-module">> => hb_store_gateway, <<"store">> => false }
#{ <<"store-module">> => hb_store_gateway, <<"store">> => [] }
Copy link
Author

Choose a reason for hiding this comment

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

Since now <<"routes">> is converted to routes atom, false is not an acceptable result.

]
},
{ok, Msg} = hb_cache:read(<<"0syT13r0s0tgPmIed95bJnuSqaD29HQNN8D3ElLSrsc">>, Opts),
Expand Down Expand Up @@ -1877,7 +1877,7 @@ http_init(Opts) ->
<<"store-module">> => hb_store_lmdb,
<<"name">> => <<"cache-mainnet/lmdb">>
},
#{ <<"store-module">> => hb_store_gateway, <<"store">> => false }
#{ <<"store-module">> => hb_store_gateway, <<"store">> => [] }
]
},
Node = hb_http_server:start_node(ExtendedOpts),
Expand Down
49 changes: 38 additions & 11 deletions src/hb_store_gateway.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ read(BaseStoreOpts, Key) ->
%% @doc Normalize the routes in the given `Opts`.
opts(Opts) ->
case hb_maps:find(<<"node">>, Opts) of
error -> Opts;
error ->
hb_opts:mimic_default_types(Opts, existing, Opts);
{ok, Node} ->
case hb_maps:get(<<"node-type">>, Opts, <<"arweave">>, Opts) of
<<"arweave">> ->
Expand Down Expand Up @@ -214,23 +215,49 @@ cache_read_message_test() ->
%% produce the same result, despite an empty 'only' route list, then we would
%% know that the module is not respecting the route list.
specific_route_test() ->
hb_http_server:start_node(#{}),
LocalNode = hb_http_server:start_node(#{}),
%% Define the response we want
ID = <<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>,
%% Define configuration, we use a valid gateway to obtain a valid response
%% and then mock the raw endpoint to our mockserver.
Opts = #{
store =>
[
#{ <<"store-module">> => hb_store_gateway,
<<"routes">> => [],
<<"only">> => local
Copy link
Author

Choose a reason for hiding this comment

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

Removed <<only>> => local because this will make us load everything necessary from the global configuration, like preloaded_devices, HTTP timeout configurations, and others. To test only routes, we don't need this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting... Why would only => local do that? Its intention is to avoid looking up Opts from the global defaults table.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that is the behavior that is shown here. By not loading the remaining configuration from the global defaults, the following modules, which need access to some of the defaults (like preloaded_devices), cannot function properly.

Because we're testing only a different routes configuration, we don't need to add only => local. If we add it, it will complain of no preloaded_devices being available.

<<"routes">> => [
#{
<<"template">> => <<"/graphql">>,
<<"nodes">> => [
#{
<<"prefix">> => <<"https://arweave-search.goldsky.com">>,
<<"opts">> => #{
<<"http_client">> => httpc,
<<"protocol">> => http2
}
}
]
},
#{
<<"template">> => <<"/raw">>,
<<"node">> =>
%% This prefix allow us to set a custom message that is a little bit
%% different than the original one (data field isn't provided).
#{
<<"prefix">> => <<LocalNode/binary, "~message@1.0/message?message=3#">>,
<<"opts">> => #{
<<"http_client">> => gun,
<<"protocol">> => http2
}
}
}
]
}
]
},
?assertMatch(
not_found,
hb_cache:read(
<<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>,
Opts
)
).
Comment on lines -227 to -233
Copy link
Author

Choose a reason for hiding this comment

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

There is a lot of error behaviours that mimic a "true" not_found output. Changed this to a value we expect.

{ok, Response} = hb_cache:read(ID, Opts),
%% If the result returns <<"1984">>, it is using the default route,
%% not the custom one we defined
?assert(maps:get(<<"data">>, Response, <<>>) /= <<"1984">>).

%% @doc Test that the default node config allows for data to be accessed.
external_http_access_test() ->
Expand Down