diff --git a/src/dev_router.erl b/src/dev_router.erl index 38e3e469c..bc774382b 100644 --- a/src/dev_router.erl +++ b/src/dev_router.erl @@ -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">> => diff --git a/src/dev_scheduler.erl b/src/dev_scheduler.erl index cbc294b66..f32b21253 100644 --- a/src/dev_scheduler.erl +++ b/src/dev_scheduler.erl @@ -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">> => [] } ] }, {ok, Msg} = hb_cache:read(<<"0syT13r0s0tgPmIed95bJnuSqaD29HQNN8D3ElLSrsc">>, Opts), @@ -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), diff --git a/src/hb_store_gateway.erl b/src/hb_store_gateway.erl index 57f8e3083..d6ad1b4dd 100644 --- a/src/hb_store_gateway.erl +++ b/src/hb_store_gateway.erl @@ -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">> -> @@ -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 + <<"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">> => <>, + <<"opts">> => #{ + <<"http_client">> => gun, + <<"protocol">> => http2 + } + } + } + ] } ] }, - ?assertMatch( - not_found, - hb_cache:read( - <<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>, - Opts - ) - ). + {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() ->