Use `txs` for list, `tx` or `address` for individual pages, respectively

pull/660/head
Tim Mecklem 6 years ago
parent e62a6bd9c2
commit fe10cae5bd
  1. 2
      apps/block_scout_web/assets/js/pages/address.js
  2. 4
      apps/block_scout_web/assets/js/pages/transaction.js
  3. 6
      apps/block_scout_web/lib/block_scout_web/router.ex
  4. 4
      apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex
  5. 2
      apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex
  6. 6
      apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs
  7. 14
      apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs
  8. 41
      apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs
  9. 23
      apps/block_scout_web/test/block_scout_web/features/pages/address_contract_page.ex
  10. 2
      apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex
  11. 51
      apps/block_scout_web/test/block_scout_web/features/pages/contract_verify_page.ex
  12. 2
      apps/block_scout_web/test/block_scout_web/features/pages/transaction_list_page.ex
  13. 4
      apps/block_scout_web/test/block_scout_web/features/pages/transaction_page.ex
  14. 19
      apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs

@ -72,7 +72,7 @@ export function reducer (state = initialState, action) {
} }
} }
router.when('/addresses/:addressHash').then((params) => initRedux(reducer, { router.when('/address/:addressHash').then((params) => initRedux(reducer, {
main (store) { main (store) {
const { addressHash, blockNumber } = params const { addressHash, blockNumber } = params
const channel = socket.channel(`addresses:${addressHash}`, {}) const channel = socket.channel(`addresses:${addressHash}`, {})

@ -65,7 +65,7 @@ export function reducer (state = initialState, action) {
} }
} }
router.when('/transactions/:transactionHash').then(() => initRedux(reducer, { router.when('/tx/:transactionHash').then(() => initRedux(reducer, {
main (store) { main (store) {
const blocksChannel = socket.channel(`blocks:new_block`, {}) const blocksChannel = socket.channel(`blocks:new_block`, {})
const $transactionBlockNumber = $('[data-selector="block-number"]') const $transactionBlockNumber = $('[data-selector="block-number"]')
@ -85,7 +85,7 @@ router.when('/transactions/:transactionHash').then(() => initRedux(reducer, {
} }
})) }))
router.when('/transactions', { exactPathMatch: true }).then((params) => initRedux(reducer, { router.when('/txs', { exactPathMatch: true }).then((params) => initRedux(reducer, {
main (store) { main (store) {
const { index } = params const { index } = params
const transactionsChannel = socket.channel(`transactions:new_transaction`) const transactionsChannel = socket.channel(`transactions:new_transaction`)

@ -54,7 +54,9 @@ defmodule BlockScoutWeb.Router do
resources("/pending_transactions", PendingTransactionController, only: [:index]) resources("/pending_transactions", PendingTransactionController, only: [:index])
resources "/transactions", TransactionController, only: [:index, :show] do get("/txs", TransactionController, :index)
resources "/tx", TransactionController, only: [:show] do
resources( resources(
"/internal_transactions", "/internal_transactions",
TransactionInternalTransactionController, TransactionInternalTransactionController,
@ -67,7 +69,7 @@ defmodule BlockScoutWeb.Router do
resources("/token_transfers", TransactionTokenTransferController, only: [:index], as: :token_transfer) resources("/token_transfers", TransactionTokenTransferController, only: [:index], as: :token_transfer)
end end
resources "/addresses", AddressController, only: [:show] do resources "/address", AddressController, only: [:show] do
resources("/transactions", AddressTransactionController, only: [:index], as: :transaction) resources("/transactions", AddressTransactionController, only: [:index], as: :transaction)
resources( resources(

@ -46,7 +46,9 @@
<%= if !smart_contract_verified?(@address) do %> <%= if !smart_contract_verified?(@address) do %>
<%= link( <%= link(
gettext("Verify and Publish"), gettext("Verify and Publish"),
to: address_verify_contract_path(@conn, :new, @conn.assigns.locale, @conn.params["address_id"]), class: "button button--primary button--sm float-right ml-3" to: address_verify_contract_path(@conn, :new, @conn.assigns.locale, @conn.params["address_id"]),
class: "button button--primary button--sm float-right ml-3",
"data-test": "verify_and_publish"
) %> ) %>
<% end %> <% end %>

@ -16,7 +16,7 @@
<div class="form-group"> <div class="form-group">
<%= label f, :name, "Contract Name" %> <%= label f, :name, "Contract Name" %>
<%= text_input f, :name, class: "form-control", "aria-describedby": "contract-name-help-block" %> <%= text_input f, :name, class: "form-control", "aria-describedby": "contract-name-help-block", "data-test": "contract_name" %>
<%= error_tag f, :name, id: "contract-name-help-block", class: "text-danger" %> <%= error_tag f, :name, id: "contract-name-help-block", class: "text-danger" %>
</div> </div>

@ -2,12 +2,12 @@ defmodule BlockScoutWeb.AddressControllerTest do
use BlockScoutWeb.ConnCase use BlockScoutWeb.ConnCase
describe "GET show/3" do describe "GET show/3" do
test "redirects to addresses/:address_id/transactions", %{conn: conn} do test "redirects to address/:address_id/transactions", %{conn: conn} do
insert(:address, hash: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed") insert(:address, hash: "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
conn = get(conn, "/en/addresses/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed") conn = get(conn, "/en/address/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
assert redirected_to(conn) =~ "/en/addresses/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed/transactions" assert redirected_to(conn) =~ "/en/address/0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed/transactions"
end end
end end
end end

@ -12,7 +12,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
|> insert() |> insert()
|> with_block() |> with_block()
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
assert List.first(conn.assigns.transactions).hash == transaction.hash assert List.first(conn.assigns.transactions).hash == transaction.hash
end end
@ -22,7 +22,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
|> insert() |> insert()
|> with_block() |> with_block()
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
assert is_integer(conn.assigns.transaction_estimated_count) assert is_integer(conn.assigns.transaction_estimated_count)
end end
@ -35,7 +35,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
insert(:transaction) insert(:transaction)
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
assert [%Transaction{hash: ^hash}] = conn.assigns.transactions assert [%Transaction{hash: ^hash}] = conn.assigns.transactions
end end
@ -53,7 +53,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
|> with_block() |> with_block()
conn = conn =
get(conn, "/en/transactions", %{ get(conn, "/en/txs", %{
"block_number" => Integer.to_string(block_number), "block_number" => Integer.to_string(block_number),
"index" => Integer.to_string(index) "index" => Integer.to_string(index)
}) })
@ -74,7 +74,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do
|> insert_list(:transaction, from_address: address) |> insert_list(:transaction, from_address: address)
|> with_block(block) |> with_block(block)
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
assert %{"block_number" => ^number, "index" => 10} = conn.assigns.next_page_params assert %{"block_number" => ^number, "index" => 10} = conn.assigns.next_page_params
end end
@ -86,13 +86,13 @@ defmodule BlockScoutWeb.TransactionControllerTest do
|> insert(from_address: address) |> insert(from_address: address)
|> with_block() |> with_block()
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
refute conn.assigns.next_page_params refute conn.assigns.next_page_params
end end
test "works when there are no transactions", %{conn: conn} do test "works when there are no transactions", %{conn: conn} do
conn = get(conn, "/en/transactions") conn = get(conn, "/en/txs")
assert conn.assigns.transactions == [] assert conn.assigns.transactions == []
end end

@ -1,11 +1,9 @@
defmodule BlockScoutWeb.AddressContractVerificationTest do defmodule BlockScoutWeb.AddressContractVerificationTest do
use BlockScoutWeb.FeatureCase, async: true use BlockScoutWeb.FeatureCase, async: true
import Wallaby.Query
alias Plug.Conn alias Plug.Conn
alias Explorer.Chain.Address
alias Explorer.Factory alias Explorer.Factory
alias BlockScoutWeb.{AddressContractPage, ContractVerifyPage}
setup do setup do
bypass = Bypass.open() bypass = Bypass.open()
@ -21,7 +19,7 @@ defmodule BlockScoutWeb.AddressContractVerificationTest do
%{name: name, source_code: source_code, bytecode: bytecode, version: version} = Factory.contract_code_info() %{name: name, source_code: source_code, bytecode: bytecode, version: version} = Factory.contract_code_info()
transaction = :transaction |> insert() |> with_block() transaction = :transaction |> insert() |> with_block()
address = %Address{hash: address_hash} = insert(:address, contract_code: bytecode) address = insert(:address, contract_code: bytecode)
insert( insert(
:internal_transaction_create, :internal_transaction_create,
@ -32,33 +30,30 @@ defmodule BlockScoutWeb.AddressContractVerificationTest do
) )
session session
|> visit("/en/addresses/#{address_hash}/contract_verifications/new") |> AddressContractPage.visit_page(address)
|> fill_in(text_field("Contract Name"), with: name) |> AddressContractPage.click_verify_and_publish()
|> click(option(version)) |> ContractVerifyPage.fill_form(%{
|> click(radio_button("No")) contract_name: name,
|> fill_in(text_field("Enter the Solidity Contract Code below"), with: source_code) version: version,
|> click(button("Verify and publish")) optimization: false,
source_code: source_code
assert current_path(session) =~ ~r/\/en\/addresses\/#{address_hash}\/contracts/ })
|> ContractVerifyPage.verify_and_publish()
assert AddressContractPage.on_page?(session, address)
end end
test "with invalid data shows error messages", %{session: session, bypass: bypass} do test "with invalid data shows error messages", %{session: session, bypass: bypass} do
Bypass.expect(bypass, fn conn -> Conn.resp(conn, 200, solc_bin_versions()) end) Bypass.expect(bypass, fn conn -> Conn.resp(conn, 200, solc_bin_versions()) end)
session session
|> visit("/en/addresses/0x1e0eaa06d02f965be2dfe0bc9ff52b2d82133461/contract_verifications/new") |> ContractVerifyPage.visit_page("0x1e0eaa06d02f965be2dfe0bc9ff52b2d82133461")
|> fill_in(text_field("Contract Name"), with: "") |> ContractVerifyPage.fill_form(%{contract_name: "", version: nil, optimization: nil, source_code: ""})
|> fill_in(text_field("Enter the Solidity Contract Code below"), with: "") |> ContractVerifyPage.verify_and_publish()
|> click(button("Verify and publish")) |> assert_has(ContractVerifyPage.validation_error())
|> assert_has(
css(
"[data-test='contract-source-code-error']",
text: "there was an error validating your contract, please try again."
)
)
end end
def solc_bin_versions() do defp solc_bin_versions do
File.read!("./test/support/fixture/smart_contract/solc_bin.json") File.read!("./test/support/fixture/smart_contract/solc_bin.json")
end end
end end

@ -0,0 +1,23 @@
defmodule BlockScoutWeb.AddressContractPage do
@moduledoc false
use Wallaby.DSL
import Wallaby.Query, only: [css: 1]
def on_page?(session, address) do
current_path(session) =~ address_contract_path(address)
end
def click_verify_and_publish(session) do
click(session, css("[data-test='verify_and_publish']"))
end
def visit_page(session, address) do
visit(session, address_contract_path(address))
end
defp address_contract_path(address) do
"/en/address/#{address.hash}/contracts"
end
end

@ -74,7 +74,7 @@ defmodule BlockScoutWeb.AddressPage do
def visit_page(session, %Address{hash: address_hash}), do: visit_page(session, address_hash) def visit_page(session, %Address{hash: address_hash}), do: visit_page(session, address_hash)
def visit_page(session, address_hash) do def visit_page(session, address_hash) do
visit(session, "/en/addresses/#{address_hash}") visit(session, "/en/address/#{address_hash}")
end end
def token_transfer(%Transaction{hash: transaction_hash}, %Address{hash: address_hash}, count: count) do def token_transfer(%Transaction{hash: transaction_hash}, %Address{hash: address_hash}, count: count) do

@ -0,0 +1,51 @@
defmodule BlockScoutWeb.ContractVerifyPage do
@moduledoc false
use Wallaby.DSL
import Wallaby.Query
def visit_page(session, address_hash) do
visit(session, "/en/address/#{address_hash}/contract_verifications/new")
end
def fill_form(session, %{
contract_name: contract_name,
version: version,
optimization: optimization,
source_code: source_code
}) do
session
|> fill_in(css("[data-test='contract_name']"), with: contract_name)
|> fill_in(text_field("Enter the Solidity Contract Code below"), with: source_code)
case version do
nil -> nil
_ -> click(session, option(version))
end
case optimization do
true ->
click(session, radio_button("Yes"))
false ->
click(session, radio_button("No"))
_ ->
nil
end
session
end
def validation_error do
css(
"[data-test='contract-source-code-error']",
text: "there was an error validating your contract, please try again."
)
end
def verify_and_publish(session) do
click(session, button("Verify and publish"))
end
end

@ -32,6 +32,6 @@ defmodule BlockScoutWeb.TransactionListPage do
end end
def visit_page(session) do def visit_page(session) do
visit(session, "/en/transactions") visit(session, "/en/txs")
end end
end end

@ -16,10 +16,10 @@ defmodule BlockScoutWeb.TransactionPage do
end end
def visit_page(session, %Transaction{hash: transaction_hash}) do def visit_page(session, %Transaction{hash: transaction_hash}) do
visit(session, "/en/transactions/#{transaction_hash}") visit(session, "/en/tx/#{transaction_hash}")
end end
def visit_page(session, transaction_hash = %Hash{}) do def visit_page(session, transaction_hash = %Hash{}) do
visit(session, "/en/transactions/#{transaction_hash}") visit(session, "/en/tx/#{transaction_hash}")
end end
end end

@ -2,7 +2,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
use BlockScoutWeb.FeatureCase, async: true use BlockScoutWeb.FeatureCase, async: true
alias Explorer.Chain.Wei alias Explorer.Chain.Wei
alias BlockScoutWeb.AddressPage alias Explorer.Factory
alias BlockScoutWeb.{AddressPage, AddressView}
setup do setup do
block = insert(:block) block = insert(:block)
@ -40,7 +41,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
describe "viewing contract creator" do describe "viewing contract creator" do
test "see the contract creator and transaction links", %{session: session} do test "see the contract creator and transaction links", %{session: session} do
address = insert(:address) address = insert(:address)
contract = insert(:address, contract_code: Explorer.Factory.data("contract_code")) contract = insert(:address, contract_code: Factory.data("contract_code"))
transaction = insert(:transaction, from_address: address, created_contract_address: contract) transaction = insert(:transaction, from_address: address, created_contract_address: contract)
internal_transaction = internal_transaction =
@ -52,8 +53,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
created_contract_address: contract created_contract_address: contract
) )
address_hash = BlockScoutWeb.AddressView.trimmed_hash(address.hash) address_hash = AddressView.trimmed_hash(address.hash)
transaction_hash = BlockScoutWeb.AddressView.trimmed_hash(transaction.hash) transaction_hash = AddressView.trimmed_hash(transaction.hash)
session session
|> AddressPage.visit_page(internal_transaction.created_contract_address) |> AddressPage.visit_page(internal_transaction.created_contract_address)
@ -62,9 +63,9 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
test "see the contract creator and transaction links even when the creator is another contract", %{session: session} do test "see the contract creator and transaction links even when the creator is another contract", %{session: session} do
lincoln = insert(:address) lincoln = insert(:address)
contract = insert(:address, contract_code: Explorer.Factory.data("contract_code")) contract = insert(:address, contract_code: Factory.data("contract_code"))
transaction = insert(:transaction) transaction = insert(:transaction)
another_contract = insert(:address, contract_code: Explorer.Factory.data("contract_code")) another_contract = insert(:address, contract_code: Factory.data("contract_code"))
insert( insert(
:internal_transaction, :internal_transaction,
@ -85,8 +86,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
created_contract_address: another_contract created_contract_address: another_contract
) )
contract_hash = BlockScoutWeb.AddressView.trimmed_hash(contract.hash) contract_hash = AddressView.trimmed_hash(contract.hash)
transaction_hash = BlockScoutWeb.AddressView.trimmed_hash(transaction.hash) transaction_hash = AddressView.trimmed_hash(transaction.hash)
session session
|> AddressPage.visit_page(internal_transaction.created_contract_address) |> AddressPage.visit_page(internal_transaction.created_contract_address)
@ -337,7 +338,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do
contract_token_address = contract_token_address =
insert( insert(
:address, :address,
contract_code: Explorer.Factory.data("contract_code") contract_code: Factory.data("contract_code")
) )
insert(:token, contract_address: contract_token_address) insert(:token, contract_address: contract_token_address)

Loading…
Cancel
Save