|
|
@ -6,6 +6,13 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do |
|
|
|
defp value_html(type, value) do |
|
|
|
defp value_html(type, value) do |
|
|
|
type |
|
|
|
type |
|
|
|
|> ABIEncodedValueView.value_html(value) |
|
|
|
|> ABIEncodedValueView.value_html(value) |
|
|
|
|
|
|
|
|> case do |
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
raise "failed to generate html" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
other -> |
|
|
|
|
|
|
|
other |
|
|
|
|
|
|
|
end |
|
|
|
|> Phoenix.HTML.Safe.to_iodata() |
|
|
|
|> Phoenix.HTML.Safe.to_iodata() |
|
|
|
|> IO.iodata_to_binary() |
|
|
|
|> IO.iodata_to_binary() |
|
|
|
end |
|
|
|
end |
|
|
@ -13,6 +20,13 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do |
|
|
|
defp copy_text(type, value) do |
|
|
|
defp copy_text(type, value) do |
|
|
|
type |
|
|
|
type |
|
|
|
|> ABIEncodedValueView.copy_text(value) |
|
|
|
|> ABIEncodedValueView.copy_text(value) |
|
|
|
|
|
|
|
|> case do |
|
|
|
|
|
|
|
:error -> |
|
|
|
|
|
|
|
raise "failed to generate copy text" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
other -> |
|
|
|
|
|
|
|
other |
|
|
|
|
|
|
|
end |
|
|
|
|> Phoenix.HTML.Safe.to_iodata() |
|
|
|
|> Phoenix.HTML.Safe.to_iodata() |
|
|
|
|> IO.iodata_to_binary() |
|
|
|
|> IO.iodata_to_binary() |
|
|
|
end |
|
|
|
end |
|
|
@ -75,7 +89,11 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do |
|
|
|
|
|
|
|
|
|
|
|
address_bytes = "0x0000000000000000000000000000000000000000" |> String.trim_leading("0x") |> Base.decode16!() |
|
|
|
address_bytes = "0x0000000000000000000000000000000000000000" |> String.trim_leading("0x") |> Base.decode16!() |
|
|
|
|
|
|
|
|
|
|
|
assert value_html("address[]", [address_bytes, address_bytes, address_bytes, address_bytes]) == expected |
|
|
|
assert value_html("address[4]", [address_bytes, address_bytes, address_bytes, address_bytes]) == expected |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "it renders :dynamic values as bytes" do |
|
|
|
|
|
|
|
assert value_html("uint", {:dynamic, <<1>>}) == "0x01" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -88,7 +106,18 @@ defmodule BlockScoutWeb.ABIEncodedValueViewTest do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "it skips the formatting when copying lists" do |
|
|
|
test "it skips the formatting when copying lists" do |
|
|
|
assert copy_text("uint[]", [1, 2, 3, 4]) == "[1, 2, 3, 4]" |
|
|
|
assert copy_text("uint[4]", [1, 2, 3, 4]) == "[1, 2, 3, 4]" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "it copies bytes as their hex representation" do |
|
|
|
|
|
|
|
hex = "0xffffff" |
|
|
|
|
|
|
|
bytes = hex |> String.trim_leading("0x") |> Base.decode16!(case: :lower) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert copy_text("bytes", bytes) == hex |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test "it copies :dynamic values as bytes" do |
|
|
|
|
|
|
|
assert copy_text("uint", {:dynamic, <<1>>}) == "0x01" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|