Skip to content

Commit

Permalink
Check empty string in GraphQL address type (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
prix-uniris committed Jun 21, 2022
1 parent b36e500 commit e986567
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/archethic_web/graphql_schema/address_type.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ defmodule ArchethicWeb.GraphQLSchema.AddressType do

@spec parse_address(Absinthe.Blueprint.Input.String.t()) :: {:ok, binary()} | :error
defp parse_address(%Absinthe.Blueprint.Input.String{value: address}) do
with {:ok, addr} <- Base.decode16(address, case: :mixed),
with true <- String.length(address) > 0,
{:ok, addr} <- Base.decode16(address, case: :mixed),
true <- Crypto.valid_address?(addr) do
{:ok, addr}
else
Expand Down
10 changes: 10 additions & 0 deletions test/archethic_web/graphql_schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ defmodule ArchethicWeb.GraphQLSchemaTest do
assert Enum.slice(transactions, slice_range)
|> Enum.map(&%{"address" => Base.encode16(&1.address)}) == recv_transactions
end

test "should return error on 0 length address argument", %{conn: conn} do
conn =
post(conn, "/api", %{
"query" => "query { transactionChain(address: \"\") { address } }"
})

%{"errors" => [%{"message" => message}]} = json_response(conn, 200)
assert message |> String.starts_with?("Argument \"address\" has invalid value \"\"")
end
end

describe "query: balance" do
Expand Down

0 comments on commit e986567

Please sign in to comment.