diff --git a/lib/cashubrew/NUTs/NUT-02/keysets.ex b/lib/cashubrew/NUTs/NUT-02/keysets.ex index ecc5115..d0aea33 100644 --- a/lib/cashubrew/NUTs/NUT-02/keysets.ex +++ b/lib/cashubrew/NUTs/NUT-02/keysets.ex @@ -10,7 +10,7 @@ defmodule Cashubrew.Nuts.Nut02.Keyset do end defp keyset_id_version do - <<0>> + "00" end @doc """ diff --git a/lib/cashubrew/NUTs/NUT-04/info.ex b/lib/cashubrew/NUTs/NUT-04/info.ex index b28769c..a94e9d0 100644 --- a/lib/cashubrew/NUTs/NUT-04/info.ex +++ b/lib/cashubrew/NUTs/NUT-04/info.ex @@ -4,6 +4,7 @@ defmodule Cashubrew.Nuts.Nut04.Info do """ @enforce_keys [:method, :unit] + @derive [Jason.Encoder] defstruct [:method, :unit, :min_amount, :max_amount, :description] @doc """ diff --git a/lib/cashubrew/NUTs/NUT-06/info.ex b/lib/cashubrew/NUTs/NUT-06/info.ex index 1b478d8..2958570 100644 --- a/lib/cashubrew/NUTs/NUT-06/info.ex +++ b/lib/cashubrew/NUTs/NUT-06/info.ex @@ -2,13 +2,13 @@ defmodule Cashubrew.Nuts.Nut06.Info do @moduledoc """ Implementation and structs of the NUT-06 """ - alias Cashubrew.Mint alias Cashubrew.Nuts.Nut00 alias Cashubrew.Nuts.Nut01 alias Cashubrew.Nuts.Nut02 alias Cashubrew.Nuts.Nut03 alias Cashubrew.Nuts.Nut04 + @derive [Jason.Encoder] defstruct [ :name, :pubkey, @@ -27,13 +27,14 @@ defmodule Cashubrew.Nuts.Nut06.Info do A Contact info """ @enforce_keys [:method, :info] + @derive [Jason.Encoder] defstruct [:method, :info] end def info do info = %__MODULE__{ name: "Cashubrew Cashu Mint", - pubkey: Base.encode16(Mint.get_pubkey(), case: :lower), + pubkey: Base.encode16(<<00, 01, 02, 03>>, case: :lower), version: "Cashubrew/0.1.0", description: "An Elixir implementation of Cashu Mint", description_long: nil, diff --git a/lib/cashubrew/web/controllers/mint_controller.ex b/lib/cashubrew/web/controllers/mint_controller.ex index e0e80dc..d143c98 100644 --- a/lib/cashubrew/web/controllers/mint_controller.ex +++ b/lib/cashubrew/web/controllers/mint_controller.ex @@ -11,8 +11,6 @@ defmodule Cashubrew.Web.MintController do def info(conn, _params) do info = Nut06.Info.info() json(conn, info) - rescue - e in RuntimeError -> conn |> put_status(:bad_request) |> json(Nut00.Error.new_error(0, e)) end def keysets(conn, _params) do diff --git a/mix.exs b/mix.exs index 740c42f..c6edf2e 100644 --- a/mix.exs +++ b/mix.exs @@ -6,6 +6,7 @@ defmodule Cashubrew.MixProject do app: :cashubrew, version: "0.0.1", elixir: "~> 1.14", + elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, deps: deps(), aliases: aliases(), @@ -20,6 +21,10 @@ defmodule Cashubrew.MixProject do ] end + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + def application do [ extra_applications: [:logger, :crypto], diff --git a/test/nut06_test.exs b/test/nut06_test.exs new file mode 100644 index 0000000..14c36e7 --- /dev/null +++ b/test/nut06_test.exs @@ -0,0 +1,12 @@ +defmodule Cashubrew.Nuts.Nut06Test do + use Cashubrew.Test.ConnCase + + test "info", %{conn: conn} do + conn = get(conn, ~p"/api/v1/info") + data = json_response(conn, 200) + + assert Map.has_key?(data, "contact") + assert Map.has_key?(data, "nuts") + assert Map.has_key?(data, "pubkey") + end +end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex new file mode 100644 index 0000000..fa94ae7 --- /dev/null +++ b/test/support/conn_case.ex @@ -0,0 +1,29 @@ +defmodule Cashubrew.Test.ConnCase do + @moduledoc """ + This module defines helpers to be used by tests that require an http connection. + It also starts a sandboxed database connection. + """ + use ExUnit.CaseTemplate + + using do + quote do + @endpoint Cashubrew.Web.Endpoint + + use Cashubrew.Web, :verified_routes + + import Plug.Conn + import Phoenix.ConnTest + import Cashubrew.Test.ConnCase + end + end + + setup tags do + Cashubrew.Test.ConnCase.setup_sandbox(tags) + {:ok, conn: Phoenix.ConnTest.build_conn()} + end + + def setup_sandbox(tags) do + pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Cashubrew.Repo, shared: not tags[:async]) + on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) + end +end