Skip to content

Commit

Permalink
Merge branch 'master' into vb-first-trace-on-demand
Browse files Browse the repository at this point in the history
  • Loading branch information
vbaranov committed Feb 20, 2020
2 parents 6de9ab2 + f42ef81 commit 091c9ac
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 170 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,9 @@
- [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash

### Fixes
- [#3016](https://github.com/poanetwork/blockscout/pull/3016), [#3017](https://github.com/poanetwork/blockscout/pull/3017) - Fix token instance QR code data
- [#3012](https://github.com/poanetwork/blockscout/pull/3012) - Speedup token transfers list query
- [#3011](https://github.com/poanetwork/blockscout/pull/3011) - Revert realtime fetcher small skips feature
- [#3009](https://github.com/poanetwork/blockscout/pull/3009) - Fix broken export to CSV
- [#3007](https://github.com/poanetwork/blockscout/pull/3007) - Fix copy UTF8 tx input action
- [#2996](https://github.com/poanetwork/blockscout/pull/2996) - Fix awesomplete lib loading in Firefox
Expand Down
26 changes: 21 additions & 5 deletions apps/block_scout_web/lib/block_scout_web/views/api_docs_view.ex
Expand Up @@ -34,7 +34,21 @@ defmodule BlockScoutWeb.APIDocsView do
end)
end

def blockscout_url(is_api) do
def blockscout_url(set_path) when set_path == false do
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
host = url_params[:host]

scheme = Keyword.get(url_params, :scheme, "http")

if host != "localhost" do
"#{scheme}://#{host}"
else
port = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:http][:port]
"#{scheme}://#{host}:#{to_string(port)}"
end
end

def blockscout_url(set_path, is_api) when set_path == true do
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
host = url_params[:host]

Expand All @@ -57,17 +71,19 @@ defmodule BlockScoutWeb.APIDocsView do

def api_url do
is_api = true
set_path = true

is_api
|> blockscout_url()
set_path
|> blockscout_url(is_api)
|> Path.join("api")
end

def eth_rpc_api_url do
is_api = true
set_path = true

is_api
|> blockscout_url()
set_path
|> blockscout_url(is_api)
|> Path.join("api/eth_rpc")
end
end
Expand Up @@ -4,7 +4,7 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
alias BlockScoutWeb.CurrencyHelpers
alias Explorer.Chain.{Address, SmartContract, Token}

import BlockScoutWeb.APIDocsView, only: [blockscout_url: 1]
import BlockScoutWeb.APIDocsView, only: [blockscout_url: 1, blockscout_url: 2]

@tabs ["token_transfers", "metadata"]

Expand Down Expand Up @@ -55,8 +55,26 @@ defmodule BlockScoutWeb.Tokens.Instance.OverviewView do
def qr_code(conn, token_id, hash) do
token_instance_path = token_instance_path(conn, :show, to_string(hash), to_string(token_id))

is_api = false
url = Path.join(blockscout_url(is_api), token_instance_path)
url_params = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)[:url]
api_path = url_params[:api_path]
path = url_params[:path]

url_prefix =
if String.length(path) > 0 && path != "/" do
set_path = false
blockscout_url(set_path)
else
if String.length(api_path) > 0 && api_path != "/" do
is_api = true
set_path = true
blockscout_url(set_path, is_api)
else
set_path = false
blockscout_url(set_path)
end
end

url = Path.join(url_prefix, token_instance_path)

url
|> QRCode.to_png()
Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/priv/gettext/default.pot
Expand Up @@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:90
#: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers"
Expand Down Expand Up @@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:91
msgid "Metadata"
msgstr ""

Expand Down
4 changes: 2 additions & 2 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Expand Up @@ -898,7 +898,7 @@ msgstr ""
#: lib/block_scout_web/templates/transaction/_tabs.html.eex:4
#: lib/block_scout_web/templates/transaction_token_transfer/index.html.eex:7
#: lib/block_scout_web/views/address_view.ex:308
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:72
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:90
#: lib/block_scout_web/views/tokens/overview_view.ex:35
#: lib/block_scout_web/views/transaction_view.ex:314
msgid "Token Transfers"
Expand Down Expand Up @@ -1774,7 +1774,7 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/tokens/instance/metadata/index.html.eex:18
#: lib/block_scout_web/templates/tokens/instance/overview/_tabs.html.eex:10
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:73
#: lib/block_scout_web/views/tokens/instance/overview_view.ex:91
msgid "Metadata"
msgstr ""

Expand Down
Expand Up @@ -3,10 +3,26 @@ defmodule BlockScoutWeb.AddressControllerTest do
# ETS tables are shared in `Explorer.Counters.*`
async: false

import Mox

alias Explorer.Chain.Address
alias Explorer.Counters.AddressesCounter

describe "GET index/2" do
setup :set_mox_global

setup do
# Use TestSource mock for this test set
configuration = Application.get_env(:block_scout_web, :show_percentage)
Application.put_env(:block_scout_web, :show_percentage, false)

:ok

on_exit(fn ->
Application.put_env(:block_scout_web, :show_percentage, configuration)
end)
end

test "returns top addresses", %{conn: conn} do
address_hashes =
4..1
Expand Down Expand Up @@ -38,8 +54,21 @@ defmodule BlockScoutWeb.AddressControllerTest do
end

describe "GET show/3" do
setup :set_mox_global

setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)

:ok

on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end

test "redirects to address/:address_id/transactions", %{conn: conn} do
insert(:address, hash: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
insert(:address, hash: "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed")

conn = get(conn, "/address/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")

Expand All @@ -48,7 +77,7 @@ defmodule BlockScoutWeb.AddressControllerTest do
end

describe "GET address_counters/2" do
test "returns address counters" do
test "returns address counters", %{conn: conn} do
address = insert(:address)

conn = get(conn, "/address_counters", %{"id" => Address.checksum(address.hash)})
Expand Down
Expand Up @@ -4,7 +4,22 @@ defmodule BlockScoutWeb.AddressReadContractControllerTest do
alias Explorer.ExchangeRates.Token
alias Explorer.Chain.Address

import Mox

describe "GET index/3" do
setup :set_mox_global

setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)

:ok

on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end

test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_read_contract_path(BlockScoutWeb.Endpoint, :index, "invalid_address"))

Expand Down
Expand Up @@ -2,10 +2,24 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
use BlockScoutWeb.ConnCase, async: true

import BlockScoutWeb.WebRouter.Helpers, only: [address_token_path: 3]
import Mox

alias Explorer.Chain.{Address, Token}

describe "GET index/2" do
setup :set_mox_global

setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)

:ok

on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end

test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_token_path(conn, :index, "invalid_address"))

Expand Down
Expand Up @@ -2,11 +2,25 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
use BlockScoutWeb.ConnCase, async: true

import BlockScoutWeb.WebRouter.Helpers, only: [address_transaction_path: 3, address_transaction_path: 4]
import Mox

alias Explorer.Chain.{Address, Transaction}
alias Explorer.ExchangeRates.Token

describe "GET index/2" do
setup :set_mox_global

setup do
configuration = Application.get_env(:explorer, :checksum_function)
Application.put_env(:explorer, :checksum_function, :eth)

:ok

on_exit(fn ->
Application.put_env(:explorer, :checksum_function, configuration)
end)
end

test "with invalid address hash", %{conn: conn} do
conn = get(conn, address_transaction_path(conn, :index, "invalid_address"))

Expand Down
@@ -1,9 +1,23 @@
defmodule BlockScoutWeb.Schema.Subscription.TokenTransfersTest do
use BlockScoutWeb.SubscriptionCase
import Mox

alias BlockScoutWeb.Notifier

describe "token_transfers field" do
setup :set_mox_global

setup do
configuration = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, pubsub: [name: BlockScoutWeb.PubSub])

:ok

on_exit(fn ->
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint, configuration)
end)
end

test "with valid argument, returns all expected fields", %{socket: socket} do
transaction = insert(:transaction)
token_transfer = insert(:token_transfer, transaction: transaction)
Expand Down
Expand Up @@ -38,6 +38,40 @@ defmodule BlockScoutWeb.ApiDocsViewTest do
end
end

describe "blockscout_url/2" do
test "set_path = true returns url with path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet"]
)

assert APIDocsView.blockscout_url(true, true) == "https://blockscout.com/eth/mainnet"
end

test "set_path = false returns url w/out path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet"]
)

assert APIDocsView.blockscout_url(false) == "https://blockscout.com"
end

test "set_path = true is_api returns url with api_path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/"]
)

assert APIDocsView.blockscout_url(true, true) == "https://blockscout.com/eth/mainnet"
end

test "set_path = true is_api returns url with path" do
Application.put_env(:block_scout_web, BlockScoutWeb.Endpoint,
url: [scheme: "https", host: "blockscout.com", api_path: "/eth/mainnet", path: "/eth/mainnet2"]
)

assert APIDocsView.blockscout_url(true, false) == "https://blockscout.com/eth/mainnet2"
end
end

describe "eth_rpc_api_url/1" do
setup do
original = Application.get_env(:block_scout_web, BlockScoutWeb.Endpoint)
Expand Down

0 comments on commit 091c9ac

Please sign in to comment.