From 482eabf4cd4dc7c2b66f55ebe486984a631f2d9a Mon Sep 17 00:00:00 2001 From: joaop21 Date: Tue, 5 Aug 2025 18:29:37 +0100 Subject: [PATCH 1/2] accept path as well --- lib/exth/provider.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/exth/provider.ex b/lib/exth/provider.ex index 676dd21..ffbfbc4 100644 --- a/lib/exth/provider.ex +++ b/lib/exth/provider.ex @@ -92,7 +92,7 @@ defmodule Exth.Provider do ### Required Options * `:transport_type` - The transport type to use (`:http`, `:websocket`, or `:custom`) - * `:rpc_url` - The URL of the Ethereum JSON-RPC endpoint + * `:rpc_url` | `:path` - The URL/path of the Ethereum JSON-RPC endpoint * `:otp_app` - The application name for config lookup (required when using application config) ## Generated Functions @@ -390,7 +390,7 @@ defmodule Exth.Provider do The client is uniquely identified by the combination of: * transport_type (e.g., :http) - * rpc_url (the endpoint URL) + * rpc_url | path (the endpoint URL) ## Returns @@ -417,15 +417,23 @@ defmodule Exth.Provider do config = Keyword.merge(app_config, @provider_inline_opts) transport_type = Keyword.fetch!(config, :transport_type) - rpc_url = Keyword.fetch!(config, :rpc_url) - case ClientCache.get_client(transport_type, rpc_url) do + rpc = + case transport_type do + :ipc -> + Keyword.fetch!(config, :path) + + _ -> + Keyword.fetch!(config, :rpc_url) + end + + case ClientCache.get_client(transport_type, rpc) do {:ok, client} -> client {:error, :not_found} -> client = Rpc.new_client(transport_type, config) - ClientCache.create_client(transport_type, rpc_url, client) + ClientCache.create_client(transport_type, rpc, client) end end end From c5f3e03bb6672a59fe22f02adf13d691f98c42c6 Mon Sep 17 00:00:00 2001 From: joaop21 Date: Tue, 5 Aug 2025 18:42:06 +0100 Subject: [PATCH 2/2] add provider tests --- test/exth/provider_test.exs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/exth/provider_test.exs b/test/exth/provider_test.exs index 2bd9550..64364a4 100644 --- a/test/exth/provider_test.exs +++ b/test/exth/provider_test.exs @@ -103,6 +103,35 @@ defmodule Exth.ProviderTest do InvalidTransportProvider.get_client() end end + + test "accepts :path when transport_type is :ipc" do + # Create a provider with invalid transport config + defmodule IpcTestProvider do + use Exth.Provider, + otp_app: :exth, + transport_type: :ipc, + path: "/tmp/valid.sock" + end + + # Get the client to force compilation + client = IpcTestProvider.get_client() + + assert client.transport.path == "/tmp/valid.sock" + end + + test "does not accept :path when transport_type is not :ipc" do + # Create a provider with invalid transport config + defmodule InvalidPathTestProvider do + use Exth.Provider, + otp_app: :exth, + transport_type: :custom, + path: "/tmp/valid.sock" + end + + assert_raise KeyError, fn -> + InvalidPathTestProvider.get_client() + end + end end describe "RPC method generation" do