diff --git a/lib/rpc.ex b/lib/rpc.ex index 13c3018..f976e32 100644 --- a/lib/rpc.ex +++ b/lib/rpc.ex @@ -64,12 +64,9 @@ defmodule Tezex.Rpc do Enum.map(preapplied_operations, fn content -> if validation_passes(content["kind"]) == 3 do internal_consumed_milligas = - Enum.reduce(content["metadata"]["internal_operation_results"], 0, fn obj, sum -> - sum + - case get_in(obj, ["result", "consumed_milligas"]) do - nil -> 0 - n -> String.to_integer(n) - end + (get_in(content, ["metadata", "internal_operation_results"]) || []) + |> Enum.reduce(0, fn obj, sum -> + sum + String.to_integer(get_in(obj, ["result", "consumed_milligas"]) || "0") end) consumed_milligas = diff --git a/test/rpc_test.exs b/test/rpc_test.exs index 3983f47..154c08a 100644 --- a/test/rpc_test.exs +++ b/test/rpc_test.exs @@ -9,6 +9,7 @@ defmodule Tezex.RpcTest do @ghostnet_1_pkey "edsk33h91RysSBUiYyEWbeRwo41YeZrtMPTNsuZ9nzsYWwiV8CFyKi" @ghostnet_2_address "tz1cMcDFLgFe2picQbo4DY1i6mZJiVhPCu5B" + @tag :tezos test "get_counter_for_account" do counter = Rpc.get_counter_for_account( @@ -467,6 +468,7 @@ defmodule Tezex.RpcTest do end end + @tag :tezos test "raise" do rpc = %Rpc{endpoint: @endpoint}