Merge pull request #509 from poanetwork/sa-api-address-balance-in-wei

Edit API account balance actions to return Wei
pull/512/head
Sebastian Abondano 6 years ago committed by GitHub
commit 47edb92b06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      apps/explorer_web/lib/explorer_web/views/api/rpc/address_view.ex
  2. 37
      apps/explorer_web/test/explorer_web/controllers/api/rpc/address_controller_test.exs

@ -4,8 +4,7 @@ defmodule ExplorerWeb.API.RPC.AddressView do
alias ExplorerWeb.API.RPC.RPCView
def render("balance.json", %{addresses: [address]}) do
ether_balance = wei_to_ether(address.fetched_balance)
RPCView.render("show.json", data: ether_balance)
RPCView.render("show.json", data: "#{address.fetched_balance.value}")
end
def render("balance.json", assigns) do
@ -17,7 +16,7 @@ defmodule ExplorerWeb.API.RPC.AddressView do
Enum.map(addresses, fn address ->
%{
"account" => "#{address.hash}",
"balance" => wei_to_ether(address.fetched_balance)
"balance" => "#{address.fetched_balance.value}"
}
end)
@ -33,10 +32,6 @@ defmodule ExplorerWeb.API.RPC.AddressView do
RPCView.render("error.json", assigns)
end
defp wei_to_ether(wei) do
format_wei_value(wei, :ether, include_unit_label: false)
end
defp prepare_transaction(transaction) do
%{
"blockNumber" => "#{transaction.block_number}",

@ -2,7 +2,7 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
use ExplorerWeb.ConnCase
alias Explorer.Chain
alias Explorer.Chain.{Transaction, Wei}
alias Explorer.Chain.Transaction
describe "balance" do
test "with missing address hash", %{conn: conn} do
@ -66,17 +66,12 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
"address" => "#{address.hash}"
}
expected_balance =
address.fetched_balance
|> Wei.to(:ether)
|> Decimal.to_string(:normal)
assert response =
conn
|> get("/api", params)
|> json_response(200)
assert response["result"] == expected_balance
assert response["result"] == "#{address.fetched_balance.value}"
assert response["status"] == "1"
assert response["message"] == "OK"
end
@ -100,12 +95,7 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
expected_result =
Enum.map(addresses, fn address ->
expected_balance =
address.fetched_balance
|> Wei.to(:ether)
|> Decimal.to_string(:normal)
%{"account" => "#{address.hash}", "balance" => expected_balance}
%{"account" => "#{address.hash}", "balance" => "#{address.fetched_balance.value}"}
end)
assert response =
@ -207,12 +197,7 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
expected_result =
Enum.map(addresses, fn address ->
expected_balance =
address.fetched_balance
|> Wei.to(:ether)
|> Decimal.to_string(:normal)
%{"account" => "#{address.hash}", "balance" => expected_balance}
%{"account" => "#{address.hash}", "balance" => "#{address.fetched_balance.value}"}
end)
assert response =
@ -235,14 +220,9 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
"address" => "#{address1.hash},#{address2_hash}"
}
expected_balance1 =
address1.fetched_balance
|> Wei.to(:ether)
|> Decimal.to_string(:normal)
expected_result = [
%{"account" => address2_hash, "balance" => "0"},
%{"account" => "#{address1.hash}", "balance" => expected_balance1}
%{"account" => "#{address1.hash}", "balance" => "#{address1.fetched_balance.value}"}
]
assert response =
@ -288,13 +268,8 @@ defmodule ExplorerWeb.API.RPC.AddressControllerTest do
"address" => "#{address.hash}"
}
expected_balance =
address.fetched_balance
|> Wei.to(:ether)
|> Decimal.to_string(:normal)
expected_result = [
%{"account" => "#{address.hash}", "balance" => expected_balance}
%{"account" => "#{address.hash}", "balance" => "#{address.fetched_balance.value}"}
]
assert response =

Loading…
Cancel
Save