Increase credo and formatter columns to 120

pull/131/head
Luke Imhoff 7 years ago
parent 3e55171fac
commit 125b540871
  1. 2
      .credo.exs
  2. 3
      .formatter.exs
  3. 3
      apps/explorer/config/prod.exs
  4. 8
      apps/explorer/lib/explorer/chain.ex
  5. 3
      apps/explorer/lib/explorer/workers/refresh_balance.ex
  6. 3
      apps/explorer/mix.exs
  7. 9
      apps/explorer/test/explorer/chain/block_test.exs
  8. 6
      apps/explorer/test/explorer/chain/credit_test.exs
  9. 6
      apps/explorer/test/explorer/chain/debit_test.exs
  10. 3
      apps/explorer/test/explorer/chain/statistics_test.exs
  11. 57
      apps/explorer/test/explorer/chain_test.exs
  12. 6
      apps/explorer/test/explorer/exchange_rates/exchange_rates_test.exs
  13. 3
      apps/explorer/test/explorer/importers/block_importer_test.exs
  14. 6
      apps/explorer/test/explorer/importers/internal_transaction_importer_test.exs
  15. 32
      apps/explorer/test/explorer/importers/receipt_importer_test.exs
  16. 79
      apps/explorer/test/explorer/importers/transaction_importer_test.exs
  17. 3
      apps/explorer/test/explorer/workers/import_balance_test.exs
  18. 8
      apps/explorer/test/explorer/workers/import_internal_transaction_test.exs
  19. 8
      apps/explorer/test/explorer/workers/import_receipt_test.exs
  20. 26
      apps/explorer/test/explorer/workers/import_transaction_test.exs
  21. 3
      apps/explorer_web/lib/explorer_web/chain.ex
  22. 3
      apps/explorer_web/lib/explorer_web/controllers/block_controller.ex
  23. 3
      apps/explorer_web/lib/explorer_web/router.ex
  24. 3
      apps/explorer_web/mix.exs
  25. 18
      apps/explorer_web/test/explorer_web/controllers/address_transaction_from_controller_test.exs
  26. 18
      apps/explorer_web/test/explorer_web/controllers/address_transaction_to_controller_test.exs
  27. 3
      apps/explorer_web/test/explorer_web/controllers/block_controller_test.exs
  28. 3
      apps/explorer_web/test/explorer_web/controllers/block_transaction_controller_test.exs
  29. 3
      apps/explorer_web/test/explorer_web/controllers/chain_controller_test.exs
  30. 3
      apps/explorer_web/test/explorer_web/controllers/transaction_controller_test.exs

@ -81,7 +81,7 @@
{Credo.Check.Design.TagFIXME},
{Credo.Check.Readability.FunctionNames},
{Credo.Check.Readability.LargeNumbers},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 100},
{Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 120},
{Credo.Check.Readability.ModuleAttributeNames},
{Credo.Check.Readability.ModuleDoc},
{Credo.Check.Readability.ModuleNames},

@ -6,5 +6,6 @@
"apps/*/{config,lib,test}/**/*.{ex,exs}",
"mix.exs",
"{config}/**/*.{ex,exs}"
]
],
line_length: 120
]

@ -43,8 +43,7 @@ config :exq,
queues: [
{"blocks", String.to_integer(System.get_env("EXQ_BLOCKS_CONCURRENCY") || "1")},
{"default", String.to_integer(System.get_env("EXQ_CONCURRENCY") || "1")},
{"internal_transactions",
String.to_integer(System.get_env("EXQ_INTERNAL_TRANSACTIONS_CONCURRENCY") || "1")},
{"internal_transactions", String.to_integer(System.get_env("EXQ_INTERNAL_TRANSACTIONS_CONCURRENCY") || "1")},
{"receipts", String.to_integer(System.get_env("EXQ_RECEIPTS_CONCURRENCY") || "1")},
{"transactions", String.to_integer(System.get_env("EXQ_TRANSACTIONS_CONCURRENCY") || "1")}
]

@ -58,8 +58,9 @@ defmodule Explorer.Chain do
* `:pagination` - pagination params to pass to scrivener.
"""
@spec block_to_transactions(Block.t()) :: %Scrivener.Page{entries: [Transaction.t()]}
@spec block_to_transactions(Block.t(), [necessity_by_association_option | pagination_option]) ::
%Scrivener.Page{entries: [Transaction.t()]}
@spec block_to_transactions(Block.t(), [necessity_by_association_option | pagination_option]) :: %Scrivener.Page{
entries: [Transaction.t()]
}
def block_to_transactions(%Block{id: block_id}, options \\ []) when is_list(options) do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
pagination = Keyword.get(options, :pagination, %{})
@ -405,8 +406,7 @@ defmodule Explorer.Chain do
then the `t:Explorer.Chain.InternalTransaction.t/0` will not be included in the list.
"""
@spec transactions_recently_before_id(id :: non_neg_integer, [necessity_by_association_option]) ::
[
@spec transactions_recently_before_id(id :: non_neg_integer, [necessity_by_association_option]) :: [
Transaction.t()
]
def transactions_recently_before_id(id, options \\ []) when is_list(options) do

@ -22,8 +22,7 @@ defmodule Explorer.Workers.RefreshBalance do
def refreshing(table) do
query = "REFRESH MATERIALIZED VIEW CONCURRENTLY #{table}%"
result =
SQL.query!(Repo, "SELECT TRUE FROM pg_stat_activity WHERE query ILIKE '$#{query}'", [])
result = SQL.query!(Repo, "SELECT TRUE FROM pg_stat_activity WHERE query ILIKE '$#{query}'", [])
Enum.count(result.rows) > 0
end

@ -46,8 +46,7 @@ defmodule Explorer.Mixfile do
defp elixirc_paths, do: ["lib"]
# Specifies extra applications to start per environment
defp extra_applications(:prod),
do: [:phoenix_pubsub_redis, :exq, :exq_ui | extra_applications()]
defp extra_applications(:prod), do: [:phoenix_pubsub_redis, :exq, :exq_ui | extra_applications()]
defp extra_applications(:dev), do: [:exq, :exq_ui | extra_applications()]
defp extra_applications(_), do: extra_applications()

@ -19,8 +19,7 @@ defmodule Explorer.Chain.BlockTest do
test "with duplicate information" do
insert(:block, hash: "0x0")
{:error, changeset} =
%Block{} |> Block.changeset(params_for(:block, hash: "0x0")) |> Repo.insert()
{:error, changeset} = %Block{} |> Block.changeset(params_for(:block, hash: "0x0")) |> Repo.insert()
refute changeset.valid?
assert changeset.errors == [hash: {"has already been taken", []}]
@ -29,8 +28,7 @@ defmodule Explorer.Chain.BlockTest do
test "rejects duplicate blocks with mixed case" do
insert(:block, hash: "0xa")
{:error, changeset} =
%Block{} |> Block.changeset(params_for(:block, hash: "0xA")) |> Repo.insert()
{:error, changeset} = %Block{} |> Block.changeset(params_for(:block, hash: "0xA")) |> Repo.insert()
refute changeset.valid?
assert changeset.errors == [hash: {"has already been taken", []}]
@ -48,8 +46,7 @@ defmodule Explorer.Chain.BlockTest do
insert(:block, number: 1)
insert(:block, number: 5)
assert Block |> Block.latest() |> Repo.all() ==
Block |> order_by(desc: :number) |> Repo.all()
assert Block |> Block.latest() |> Repo.all() == Block |> order_by(desc: :number) |> Repo.all()
end
end
end

@ -28,8 +28,7 @@ defmodule Explorer.Chain.CreditTest do
recipient = insert(:address)
sender = insert(:address)
transaction =
insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
transaction = insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
insert(:receipt, transaction: transaction, status: 1)
address_id = sender.id
@ -42,8 +41,7 @@ defmodule Explorer.Chain.CreditTest do
recipient = insert(:address)
sender = insert(:address)
transaction =
insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
transaction = insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
insert(:receipt, transaction: transaction, status: 1)
address_id = recipient.id

@ -28,8 +28,7 @@ defmodule Explorer.Chain.DebitTest do
recipient = insert(:address)
sender = insert(:address)
transaction =
insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
transaction = insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
insert(:receipt, transaction: transaction, status: 1)
address_id = sender.id
@ -42,8 +41,7 @@ defmodule Explorer.Chain.DebitTest do
recipient = insert(:address)
sender = insert(:address)
transaction =
insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
transaction = insert(:transaction, value: 21, to_address_id: recipient.id, from_address_id: sender.id)
insert(:receipt, transaction: transaction, status: 1)
address_id = recipient.id

@ -69,8 +69,7 @@ defmodule Explorer.Chain.StatisticsTest do
inserted_at = validation_time |> Timex.shift(seconds: 5)
insert(:block, timestamp: validation_time, inserted_at: inserted_at)
assert %Statistics{lag: %Duration{seconds: 5, megaseconds: 0, microseconds: 0}} =
Statistics.fetch()
assert %Statistics{lag: %Duration{seconds: 5, megaseconds: 0, microseconds: 0}} = Statistics.fetch()
end
test "returns the number of blocks inserted in the last minute" do

@ -92,8 +92,7 @@ defmodule Explorer.ChainTest do
insert(:block_transaction, block_id: block_id, transaction_id: transaction_id)
end)
[%Transaction{id: first_transaction_id}, %Transaction{id: second_transaction_id}] =
transactions
[%Transaction{id: first_transaction_id}, %Transaction{id: second_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^first_transaction_id}],
@ -144,8 +143,7 @@ defmodule Explorer.ChainTest do
assert block.number < max_block_number
assert Chain.confirmations(block, max_block_number: max_block_number) ==
max_block_number - block.number
assert Chain.confirmations(block, max_block_number: max_block_number) == max_block_number - block.number
end
end
@ -188,18 +186,15 @@ defmodule Explorer.ChainTest do
end
test ":gwei unit" do
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :gwei) ==
Decimal.new("1e-9")
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :gwei) == Decimal.new("1e-9")
assert Chain.gas_price(%Transaction{gas_price: Decimal.new("1e9")}, :gwei) == Decimal.new(1)
end
test ":ether unit" do
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :ether) ==
Decimal.new("1e-18")
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :ether) == Decimal.new("1e-18")
assert Chain.gas_price(%Transaction{gas_price: Decimal.new("1e18")}, :ether) ==
Decimal.new(1)
assert Chain.gas_price(%Transaction{gas_price: Decimal.new("1e18")}, :ether) == Decimal.new(1)
end
end
@ -230,13 +225,11 @@ defmodule Explorer.ChainTest do
test "with transactions with receipt required without receipt does not return transaction" do
address = %Address{id: from_address_id} = insert(:address)
%Transaction{id: transaction_id_with_receipt} =
insert(:transaction, from_address_id: from_address_id)
%Transaction{id: transaction_id_with_receipt} = insert(:transaction, from_address_id: from_address_id)
insert(:receipt, transaction_id: transaction_id_with_receipt)
%Transaction{id: transaction_id_without_receipt} =
insert(:transaction, from_address_id: from_address_id)
%Transaction{id: transaction_id_without_receipt} = insert(:transaction, from_address_id: from_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id_with_receipt, receipt: %Receipt{}}],
@ -273,8 +266,7 @@ defmodule Explorer.ChainTest do
adddress = %Address{id: from_address_id} = insert(:address)
transactions = insert_list(2, :transaction, from_address_id: from_address_id)
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] =
transactions
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^newest_transaction_id}],
@ -290,8 +282,7 @@ defmodule Explorer.ChainTest do
page_size: 1,
total_entries: 2,
total_pages: 2
} =
Chain.from_address_to_transactions(adddress, pagination: %{page: 2, page_size: 1})
} = Chain.from_address_to_transactions(adddress, pagination: %{page: 2, page_size: 1})
end
end
@ -321,8 +312,7 @@ defmodule Explorer.ChainTest do
end
test "with transaction with receipt required without receipt returns {:error, :not_found}" do
%Transaction{hash: hash_with_receipt, id: transaction_id_with_receipt} =
insert(:transaction)
%Transaction{hash: hash_with_receipt, id: transaction_id_with_receipt} = insert(:transaction)
insert(:receipt, transaction_id: transaction_id_with_receipt)
@ -479,13 +469,11 @@ defmodule Explorer.ChainTest do
test "with transactions with receipt required without receipt does not return transaction" do
address = %Address{id: to_address_id} = insert(:address)
%Transaction{id: transaction_id_with_receipt} =
insert(:transaction, to_address_id: to_address_id)
%Transaction{id: transaction_id_with_receipt} = insert(:transaction, to_address_id: to_address_id)
insert(:receipt, transaction_id: transaction_id_with_receipt)
%Transaction{id: transaction_id_without_receipt} =
insert(:transaction, to_address_id: to_address_id)
%Transaction{id: transaction_id_without_receipt} = insert(:transaction, to_address_id: to_address_id)
assert %Scrivener.Page{
entries: [%Transaction{id: ^transaction_id_with_receipt, receipt: %Receipt{}}],
@ -522,8 +510,7 @@ defmodule Explorer.ChainTest do
adddress = %Address{id: to_address_id} = insert(:address)
transactions = insert_list(2, :transaction, to_address_id: to_address_id)
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] =
transactions
[%Transaction{id: oldest_transaction_id}, %Transaction{id: newest_transaction_id}] = transactions
assert %Scrivener.Page{
entries: [%Transaction{id: ^newest_transaction_id}],
@ -643,11 +630,9 @@ defmodule Explorer.ChainTest do
insert(:receipt, transaction_id: id)
end)
assert length(Chain.transactions_recently_before_id(last_transaction_id, pending: true)) ==
8
assert length(Chain.transactions_recently_before_id(last_transaction_id, pending: true)) == 8
assert length(Chain.transactions_recently_before_id(last_transaction_id, pending: false)) ==
10
assert length(Chain.transactions_recently_before_id(last_transaction_id, pending: false)) == 10
assert length(Chain.transactions_recently_before_id(last_transaction_id)) == 10
end
@ -761,8 +746,7 @@ defmodule Explorer.ChainTest do
Chain.update_balance(hash, 88)
assert {:ok, %Address{balance_updated_at: balance_updated_at}} =
Chain.hash_to_address("0xtwizzlers")
assert {:ok, %Address{balance_updated_at: balance_updated_at}} = Chain.hash_to_address("0xtwizzlers")
refute is_nil(balance_updated_at)
end
@ -782,18 +766,15 @@ defmodule Explorer.ChainTest do
end
test "with InternalTransaction.t with :gwei" do
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :gwei) ==
Decimal.new("1e-9")
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :gwei) == Decimal.new("1e-9")
assert Chain.value(%InternalTransaction{value: Decimal.new("1e9")}, :gwei) == Decimal.new(1)
end
test "with InternalTransaction.t with :ether" do
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :ether) ==
Decimal.new("1e-18")
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :ether) == Decimal.new("1e-18")
assert Chain.value(%InternalTransaction{value: Decimal.new("1e18")}, :ether) ==
Decimal.new(1)
assert Chain.value(%InternalTransaction{value: Decimal.new("1e18")}, :ether) == Decimal.new(1)
end
test "with Transaction.t with :wei" do

@ -62,8 +62,7 @@ defmodule Explorer.ExchangeRatesTest do
id = expected_rate.id
state = %{}
assert {:noreply, ^state} =
ExchangeRates.handle_info({nil, {id, {:ok, expected_rate}}}, state)
assert {:noreply, ^state} = ExchangeRates.handle_info({nil, {id, {:ok, expected_rate}}}, state)
assert [{^id, ^expected_rate}] = :ets.lookup(ExchangeRates.table_name(), id)
end
@ -75,8 +74,7 @@ defmodule Explorer.ExchangeRatesTest do
expect(TestSource, :fetch_exchange_rate, fn "failed-ticker" -> {:ok, %Rate{}} end)
set_mox_global()
assert {:noreply, ^state} =
ExchangeRates.handle_info({nil, {ticker, {:error, "some error"}}}, state)
assert {:noreply, ^state} = ExchangeRates.handle_info({nil, {ticker, {:error, "some error"}}}, state)
assert_receive {_, {^ticker, {:ok, _}}}
end

@ -14,8 +14,7 @@ defmodule Explorer.BlockImporterTest do
BlockImporter.import("0xc4f0d")
block = Block |> order_by(desc: :inserted_at) |> Repo.one()
assert block.hash ==
"0x16cb43ccfb7875c14eb3f03bdc098e4af053160544270594fa429d256cbca64e"
assert block.hash == "0x16cb43ccfb7875c14eb3f03bdc098e4af053160544270594fa429d256cbca64e"
end
end
end

@ -29,8 +29,7 @@ defmodule Explorer.InternalTransactionImporterTest do
InternalTransactionImporter.import(transaction.hash)
last_internal_transaction =
InternalTransaction |> order_by(desc: :index) |> limit(1) |> Repo.one()
last_internal_transaction = InternalTransaction |> order_by(desc: :index) |> limit(1) |> Repo.one()
assert last_internal_transaction.index == 1
end
@ -46,8 +45,7 @@ defmodule Explorer.InternalTransactionImporterTest do
InternalTransactionImporter.import(transaction.hash)
last_internal_transaction =
InternalTransaction |> order_by(desc: :index) |> limit(1) |> Repo.one()
last_internal_transaction = InternalTransaction |> order_by(desc: :index) |> limit(1) |> Repo.one()
assert last_internal_transaction.call_type == "create"
end

@ -13,9 +13,7 @@ defmodule Explorer.ReceiptImporterTest do
)
use_cassette "transaction_importer_import_1_receipt" do
ReceiptImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
ReceiptImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
receipt = Receipt |> preload([:transaction]) |> Repo.one()
assert receipt.transaction == transaction
@ -29,9 +27,7 @@ defmodule Explorer.ReceiptImporterTest do
)
use_cassette "transaction_importer_import_1_receipt" do
ReceiptImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
ReceiptImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
receipt = Receipt |> preload([:transaction]) |> Repo.one()
log = Log |> preload(receipt: :transaction) |> Repo.one()
@ -48,9 +44,7 @@ defmodule Explorer.ReceiptImporterTest do
address = insert(:address, hash: "0x353fe3ffbf77edef7f9c352c47965a38c07e837c")
use_cassette "transaction_importer_import_1_receipt" do
ReceiptImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
ReceiptImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
log = Log |> preload([:address]) |> Repo.one()
assert log.address == address
@ -64,9 +58,7 @@ defmodule Explorer.ReceiptImporterTest do
)
use_cassette "transaction_importer_import_1_failed" do
ReceiptImporter.import(
"0x2532864dc2e0d0bc2dfabf4685c0c03dbdbe9cf67ebc593fc82d41087ab71435"
)
ReceiptImporter.import("0x2532864dc2e0d0bc2dfabf4685c0c03dbdbe9cf67ebc593fc82d41087ab71435")
receipt = Repo.one(Receipt)
assert receipt.status == 0
@ -80,9 +72,7 @@ defmodule Explorer.ReceiptImporterTest do
)
use_cassette "transaction_importer_import_1_out_of_gas" do
ReceiptImporter.import(
"0x702e518267b0a57e4cb44b9db100afe4d7115f2d2650466a8c376f3dbb77eb35"
)
ReceiptImporter.import("0x702e518267b0a57e4cb44b9db100afe4d7115f2d2650466a8c376f3dbb77eb35")
receipt = Repo.one(Receipt)
assert receipt.status == 0
@ -99,9 +89,7 @@ defmodule Explorer.ReceiptImporterTest do
insert(:receipt, transaction: transaction)
use_cassette "transaction_importer_import_1_receipt" do
ReceiptImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
ReceiptImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
assert Repo.all(Receipt) |> Enum.count() == 1
end
@ -109,9 +97,7 @@ defmodule Explorer.ReceiptImporterTest do
test "does not import a receipt for a nonexistent transaction" do
use_cassette "transaction_importer_import_1_receipt" do
ReceiptImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
ReceiptImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
assert Repo.all(Receipt) |> Enum.count() == 0
end
@ -124,9 +110,7 @@ defmodule Explorer.ReceiptImporterTest do
)
use_cassette "transaction_importer_import_1_pending" do
ReceiptImporter.import(
"0xde791cfcde3900d4771e5fcf8c11dc305714118df7aa7e42f84576e64dbf6246"
)
ReceiptImporter.import("0xde791cfcde3900d4771e5fcf8c11dc305714118df7aa7e42f84576e64dbf6246")
assert Repo.all(Receipt) |> Enum.count() == 0
end

@ -40,14 +40,11 @@ defmodule Explorer.TransactionImporterTest do
describe "import/1" do
test "imports and saves a transaction to the database" do
use_cassette "transaction_importer_import_saves_the_transaction" do
TransactionImporter.import(
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
)
TransactionImporter.import("0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291")
transaction = Transaction |> order_by(desc: :inserted_at) |> Repo.one()
assert transaction.hash ==
"0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
assert transaction.hash == "0xdc3a0dfd0bbffd5eabbe40fb13afbe35ac5f5c030bff148f3e50afe32974b291"
end
end
@ -59,9 +56,7 @@ defmodule Explorer.TransactionImporterTest do
gas: 5
)
TransactionImporter.import(
"0x170baac4eca26076953370dd603c68eab340c0135b19b585010d3158a5dbbf23"
)
TransactionImporter.import("0x170baac4eca26076953370dd603c68eab340c0135b19b585010d3158a5dbbf23")
transaction = Transaction |> order_by(desc: :inserted_at) |> Repo.one()
@ -77,15 +72,11 @@ defmodule Explorer.TransactionImporterTest do
hash: "0xfce13392435a8e7dab44c07d482212efb9dc39a9bea1915a9ead308b55a617f9"
)
TransactionImporter.import(
"0x64d851139325479c3bb7ccc6e6ab4cde5bc927dce6810190fe5d770a4c1ac333"
)
TransactionImporter.import("0x64d851139325479c3bb7ccc6e6ab4cde5bc927dce6810190fe5d770a4c1ac333")
transaction =
Transaction
|> Repo.get_by(
hash: "0x64d851139325479c3bb7ccc6e6ab4cde5bc927dce6810190fe5d770a4c1ac333"
)
|> Repo.get_by(hash: "0x64d851139325479c3bb7ccc6e6ab4cde5bc927dce6810190fe5d770a4c1ac333")
block_transaction = BlockTransaction |> Repo.get_by(transaction_id: transaction.id)
@ -95,15 +86,11 @@ defmodule Explorer.TransactionImporterTest do
test "when there is no block it does not save a block transaction" do
use_cassette "transaction_importer_txn_without_block" do
TransactionImporter.import(
"0xc6aa189827c14880f012a65292f7add7b5310094f8773a3d85b66303039b9dcf"
)
TransactionImporter.import("0xc6aa189827c14880f012a65292f7add7b5310094f8773a3d85b66303039b9dcf")
transaction =
Transaction
|> Repo.get_by(
hash: "0xc6aa189827c14880f012a65292f7add7b5310094f8773a3d85b66303039b9dcf"
)
|> Repo.get_by(hash: "0xc6aa189827c14880f012a65292f7add7b5310094f8773a3d85b66303039b9dcf")
block_transaction = BlockTransaction |> Repo.get_by(transaction_id: transaction.id)
@ -113,15 +100,11 @@ defmodule Explorer.TransactionImporterTest do
test "creates a from address" do
use_cassette "transaction_importer_creates_a_from_address" do
TransactionImporter.import(
"0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d"
)
TransactionImporter.import("0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d")
transaction =
Transaction
|> Repo.get_by(
hash: "0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d"
)
|> Repo.get_by(hash: "0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d")
address = Address |> Repo.get_by(hash: "0xa5b4b372112ab8dbbb48c8d0edd89227e24ec785")
@ -133,15 +116,11 @@ defmodule Explorer.TransactionImporterTest do
insert(:address, hash: "0xa5b4b372112ab8dbbb48c8d0edd89227e24ec785")
use_cassette "transaction_importer_creates_a_from_address" do
TransactionImporter.import(
"0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d"
)
TransactionImporter.import("0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d")
transaction =
Transaction
|> Repo.get_by(
hash: "0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d"
)
|> Repo.get_by(hash: "0xc445f5410912458c480d992dd93355ae3dad64d9f65db25a3cf43a9c609a2e0d")
address = Address |> Repo.get_by(hash: "0xa5b4b372112ab8dbbb48c8d0edd89227e24ec785")
@ -151,15 +130,11 @@ defmodule Explorer.TransactionImporterTest do
test "creates a to address" do
use_cassette "transaction_importer_creates_a_to_address" do
TransactionImporter.import(
"0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
TransactionImporter.import("0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
transaction =
Transaction
|> Repo.get_by(
hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
|> Repo.get_by(hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
address = Address |> Repo.get_by(hash: "0x24e5b8528fe83257d5fe3497ef616026713347f8")
@ -171,15 +146,11 @@ defmodule Explorer.TransactionImporterTest do
insert(:address, hash: "0x24e5b8528fe83257d5fe3497ef616026713347f8")
use_cassette "transaction_importer_creates_a_to_address" do
TransactionImporter.import(
"0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
TransactionImporter.import("0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
transaction =
Transaction
|> Repo.get_by(
hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
|> Repo.get_by(hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
address = Address |> Repo.get_by(hash: "0x24e5b8528fe83257d5fe3497ef616026713347f8")
@ -189,15 +160,11 @@ defmodule Explorer.TransactionImporterTest do
test "creates a to address using creates when to is nil" do
use_cassette "transaction_importer_creates_a_to_address_from_creates" do
TransactionImporter.import(
"0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
TransactionImporter.import("0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
transaction =
Transaction
|> Repo.get_by(
hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
|> Repo.get_by(hash: "0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
address = Address |> Repo.get_by(hash: "0x24e5b8528fe83257d5fe3497ef616026713347f8")
@ -208,9 +175,7 @@ defmodule Explorer.TransactionImporterTest do
test "processes a map of transaction attributes" do
insert(:block, hash: "0xtakis")
TransactionImporter.import(
Map.merge(@raw_transaction, %{"hash" => "0xmunchos", "blockHash" => "0xtakis"})
)
TransactionImporter.import(Map.merge(@raw_transaction, %{"hash" => "0xmunchos", "blockHash" => "0xtakis"}))
last_transaction = Transaction |> order_by(desc: :inserted_at) |> limit(1) |> Repo.one()
@ -218,9 +183,7 @@ defmodule Explorer.TransactionImporterTest do
end
test "gets balances for addresses" do
TransactionImporter.import(
"0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c"
)
TransactionImporter.import("0xdc533d4227734a7cacd75a069e8dc57ac571b865ed97bae5ea4cb74b54145f4c")
from_address = Address |> Repo.get_by(hash: "0xb2867180771b196518651c174c9240d5e8bd0ecd")
to_address = Address |> Repo.get_by(hash: "0x24e5b8528fe83257d5fe3497ef616026713347f8")
@ -245,9 +208,7 @@ defmodule Explorer.TransactionImporterTest do
test "downloads a transaction" do
use_cassette "transaction_importer_download_transaction" do
raw_transaction =
TransactionImporter.download_transaction(
"0x170baac4eca26076953370dd603c68eab340c0135b19b585010d3158a5dbbf23"
)
TransactionImporter.download_transaction("0x170baac4eca26076953370dd603c68eab340c0135b19b585010d3158a5dbbf23")
assert(raw_transaction["from"] == "0xbe96ef1d056c97323e210fd0dd818aa027e57143")
end

@ -32,8 +32,7 @@ defmodule Explorer.Workers.ImportBalanceTest do
expected_balance = Decimal.new(66)
assert {:ok, %Address{balance: ^expected_balance}} =
Chain.hash_to_address("0xskateboards")
assert {:ok, %Address{balance: ^expected_balance}} = Chain.hash_to_address("0xskateboards")
end
end
end

@ -9,9 +9,7 @@ defmodule Explorer.Workers.ImportInternalTransactionTest do
test "does not import the internal transactions when no transaction with the hash exists" do
use_cassette "import_internal_transaction_perform_1" do
assert_raise Ecto.NoResultsError, fn ->
ImportInternalTransaction.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportInternalTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
end
end
end
@ -23,9 +21,7 @@ defmodule Explorer.Workers.ImportInternalTransactionTest do
)
use_cassette "import_internal_transaction_perform_1" do
ImportInternalTransaction.perform(
"0x051e031f05b3b3a5ff73e1189c36e3e2a41fd1c2d9772b2c75349e22ed4d3f68"
)
ImportInternalTransaction.perform("0x051e031f05b3b3a5ff73e1189c36e3e2a41fd1c2d9772b2c75349e22ed4d3f68")
internal_transaction_count = InternalTransaction |> Repo.all() |> Enum.count()
assert internal_transaction_count == 2

@ -8,9 +8,7 @@ defmodule Explorer.Workers.ImportReceiptTest do
describe "perform/1" do
test "does not import a receipt when no transaction with the hash exists" do
use_cassette "import_receipt_perform_1" do
ImportReceipt.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportReceipt.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
assert Repo.one(Receipt) == nil
end
@ -23,9 +21,7 @@ defmodule Explorer.Workers.ImportReceiptTest do
)
use_cassette "import_receipt_perform_1" do
ImportReceipt.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportReceipt.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
receipt_count = Receipt |> Repo.all() |> Enum.count()
assert receipt_count == 1

@ -12,15 +12,12 @@ defmodule Explorer.Workers.ImportTransactionTest do
test "imports the requested transaction hash" do
use_cassette "import_transaction_perform_1" do
with_mock Exq, enqueue: fn _, _, _, _ -> :ok end do
ImportTransaction.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
end
transaction = Transaction |> Repo.one()
assert transaction.hash ==
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
assert transaction.hash == "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
end
end
@ -32,9 +29,7 @@ defmodule Explorer.Workers.ImportTransactionTest do
use_cassette "import_transaction_perform_1" do
with_mock Exq, enqueue: fn _, _, _, _ -> :ok end do
ImportTransaction.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
end
transaction_count = Transaction |> Repo.all() |> Enum.count()
@ -52,9 +47,7 @@ defmodule Explorer.Workers.ImportTransactionTest do
use_cassette "import_transaction_perform_1" do
with_mock Exq, enqueue: fn _, _, _, _ -> insert(:receipt, transaction: transaction) end do
with_mock ImportInternalTransaction, perform_later: fn _ -> :ok end do
ImportTransaction.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
receipt = Repo.one(Receipt)
refute is_nil(receipt)
@ -98,9 +91,7 @@ defmodule Explorer.Workers.ImportTransactionTest do
with_mock Exq, enqueue: fn _, _, _, _ -> :ok end do
with_mock ImportInternalTransaction,
perform_later: fn _ -> insert(:internal_transaction, transaction: transaction) end do
ImportTransaction.perform(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportTransaction.perform("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
internal_transaction = Repo.one(InternalTransaction)
refute is_nil(internal_transaction)
@ -145,14 +136,11 @@ defmodule Explorer.Workers.ImportTransactionTest do
hash: "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
end do
ImportTransaction.perform_later(
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
)
ImportTransaction.perform_later("0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926")
transaction = Repo.one(Transaction)
assert transaction.hash ==
"0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
assert transaction.hash == "0xf9a0959d5ccde33ec5221ddba1c6d7eaf9580a8d3512c7a1a60301362a98f926"
end
end
end

@ -5,8 +5,7 @@ defmodule ExplorerWeb.Chain do
import Explorer.Chain, only: [hash_to_address: 1, hash_to_transaction: 1, number_to_block: 1]
@spec from_param(String.t()) ::
{:ok, Address.t() | Transaction.t() | Block.t()} | {:error, :not_found}
@spec from_param(String.t()) :: {:ok, Address.t() | Transaction.t() | Block.t()} | {:error, :not_found}
def from_param(param)
def from_param(hash) when byte_size(hash) > 42 do

@ -4,8 +4,7 @@ defmodule ExplorerWeb.BlockController do
alias Explorer.Chain
def index(conn, params) do
blocks =
Chain.list_blocks(necessity_by_association: %{transactions: :optional}, pagination: params)
blocks = Chain.list_blocks(necessity_by_association: %{transactions: :optional}, pagination: params)
render(conn, "index.html", blocks: blocks)
end

@ -40,8 +40,7 @@ defmodule ExplorerWeb.Router do
end
pipeline :jasmine do
if Mix.env() != :prod,
do: plug(Jasmine, js_files: ["js/test.js"], css_files: ["css/test.css"])
if Mix.env() != :prod, do: plug(Jasmine, js_files: ["js/test.js"], css_files: ["css/test.css"])
end
pipeline :api do

@ -46,8 +46,7 @@ defmodule ExplorerWeb.Mixfile do
defp elixirc_paths, do: ["lib"]
# Specifies extra applications to start per environment
defp extra_applications(:prod),
do: [:phoenix_pubsub_redis, :exq, :exq_ui | extra_applications()]
defp extra_applications(:prod), do: [:phoenix_pubsub_redis, :exq, :exq_ui | extra_applications()]
defp extra_applications(:dev), do: [:exq, :exq_ui | extra_applications()]
defp extra_applications(_), do: extra_applications()

@ -18,13 +18,11 @@ defmodule ExplorerWeb.AddressTransactionFromControllerTest do
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
conn =
get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
transaction_hash_divs =
Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
assert length(transaction_hash_divs) == 1
@ -43,8 +41,7 @@ defmodule ExplorerWeb.AddressTransactionFromControllerTest do
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: other_address)
conn =
get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -58,8 +55,7 @@ defmodule ExplorerWeb.AddressTransactionFromControllerTest do
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -73,8 +69,7 @@ defmodule ExplorerWeb.AddressTransactionFromControllerTest do
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -88,8 +83,7 @@ defmodule ExplorerWeb.AddressTransactionFromControllerTest do
address = insert(:address)
insert(:from_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_from_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0

@ -18,14 +18,12 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
block = insert(:block)
insert(:block_transaction, transaction: transaction, block: block)
conn =
get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 1
transaction_hash_divs =
Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
assert length(transaction_hash_divs) == 1
@ -44,8 +42,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
insert(:to_address, transaction: transaction, address: other_address)
insert(:from_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -59,8 +56,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
insert(:to_address, transaction: transaction, address: address)
insert(:from_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -74,8 +70,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
address = insert(:address)
insert(:to_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0
@ -89,8 +84,7 @@ defmodule ExplorerWeb.AddressTransactionToControllerTest do
address = insert(:address)
insert(:from_address, transaction: transaction, address: address)
conn =
get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
conn = get(conn, address_transaction_to_path(ExplorerWeb.Endpoint, :index, :en, address.hash))
assert html = html_response(conn, 200)
assert html |> Floki.find("tbody tr") |> length == 0

@ -17,8 +17,7 @@ defmodule ExplorerWeb.BlockControllerTest do
describe "GET index/2" do
test "returns all blocks", %{conn: conn} do
block_ids =
insert_list(4, :block) |> Enum.map(fn block -> block.number end) |> Enum.reverse()
block_ids = insert_list(4, :block) |> Enum.map(fn block -> block.number end) |> Enum.reverse()
conn = get(conn, "/en/blocks")
assert conn.assigns.blocks |> Enum.map(fn block -> block.number end) == block_ids

@ -30,8 +30,7 @@ defmodule ExplorerWeb.BlockTransactionControllerTest do
assert html = html_response(conn, 200)
transaction_hash_divs =
Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
transaction_hash_divs = Floki.find(html, "td.transactions__column--hash div.transactions__hash a")
assert length(transaction_hash_divs) == 1

@ -1,8 +1,7 @@
defmodule ExplorerWeb.ChainControllerTest do
use ExplorerWeb.ConnCase
import ExplorerWeb.Router.Helpers,
only: [chain_path: 3, block_path: 4, transaction_path: 4, address_path: 4]
import ExplorerWeb.Router.Helpers, only: [chain_path: 3, block_path: 4, transaction_path: 4, address_path: 4]
describe "GET index/2 without a locale" do
test "redirects to the en locale", %{conn: conn} do

@ -77,8 +77,7 @@ defmodule ExplorerWeb.TransactionControllerTest do
assert html |> Floki.find("div.transaction__header h3") |> Floki.text() == transaction.hash
assert html |> Floki.find("span.transaction__item--primary a") |> Floki.text() ==
to_string(block.number)
assert html |> Floki.find("span.transaction__item--primary a") |> Floki.text() == to_string(block.number)
end
test "returns a transaction without associated block data", %{conn: conn} do

Loading…
Cancel
Save