From fe10cae5bd43c19ea933cafaf76edd3d5faac474 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Fri, 31 Aug 2018 15:45:28 -0400 Subject: [PATCH] Use `txs` for list, `tx` or `address` for individual pages, respectively --- .../assets/js/pages/address.js | 2 +- .../assets/js/pages/transaction.js | 4 +- .../lib/block_scout_web/router.ex | 6 ++- .../templates/address_contract/index.html.eex | 4 +- .../new.html.eex | 2 +- .../controllers/address_controller_test.exs | 6 +-- .../transaction_controller_test.exs | 14 ++--- .../address_contract_verification_test.exs | 41 +++++++-------- .../features/pages/address_contract_page.ex | 23 +++++++++ .../features/pages/address_page.ex | 2 +- .../features/pages/contract_verify_page.ex | 51 +++++++++++++++++++ .../features/pages/transaction_list_page.ex | 2 +- .../features/pages/transaction_page.ex | 4 +- .../features/viewing_addresses_test.exs | 19 +++---- 14 files changed, 127 insertions(+), 53 deletions(-) create mode 100644 apps/block_scout_web/test/block_scout_web/features/pages/address_contract_page.ex create mode 100644 apps/block_scout_web/test/block_scout_web/features/pages/contract_verify_page.ex diff --git a/apps/block_scout_web/assets/js/pages/address.js b/apps/block_scout_web/assets/js/pages/address.js index 5ea3f34acb..dd8116be1e 100644 --- a/apps/block_scout_web/assets/js/pages/address.js +++ b/apps/block_scout_web/assets/js/pages/address.js @@ -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) { const { addressHash, blockNumber } = params const channel = socket.channel(`addresses:${addressHash}`, {}) diff --git a/apps/block_scout_web/assets/js/pages/transaction.js b/apps/block_scout_web/assets/js/pages/transaction.js index 759994a554..84183423e9 100644 --- a/apps/block_scout_web/assets/js/pages/transaction.js +++ b/apps/block_scout_web/assets/js/pages/transaction.js @@ -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) { const blocksChannel = socket.channel(`blocks:new_block`, {}) 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) { const { index } = params const transactionsChannel = socket.channel(`transactions:new_transaction`) diff --git a/apps/block_scout_web/lib/block_scout_web/router.ex b/apps/block_scout_web/lib/block_scout_web/router.ex index 244498dc80..11159eee25 100644 --- a/apps/block_scout_web/lib/block_scout_web/router.ex +++ b/apps/block_scout_web/lib/block_scout_web/router.ex @@ -54,7 +54,9 @@ defmodule BlockScoutWeb.Router do resources("/pending_transactions", PendingTransactionController, only: [:index]) - resources "/transactions", TransactionController, only: [:index, :show] do + get("/txs", TransactionController, :index) + + resources "/tx", TransactionController, only: [:show] do resources( "/internal_transactions", TransactionInternalTransactionController, @@ -67,7 +69,7 @@ defmodule BlockScoutWeb.Router do resources("/token_transfers", TransactionTokenTransferController, only: [:index], as: :token_transfer) end - resources "/addresses", AddressController, only: [:show] do + resources "/address", AddressController, only: [:show] do resources("/transactions", AddressTransactionController, only: [:index], as: :transaction) resources( diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex index 1767000106..3a4beae326 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract/index.html.eex @@ -46,7 +46,9 @@ <%= if !smart_contract_verified?(@address) do %> <%= link( 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 %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex index b2dad37cde..404ce842cd 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/address_contract_verification/new.html.eex @@ -16,7 +16,7 @@
<%= 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" %>
diff --git a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs index e284612310..c658ac5a27 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/address_controller_test.exs @@ -2,12 +2,12 @@ defmodule BlockScoutWeb.AddressControllerTest do use BlockScoutWeb.ConnCase 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") - 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 diff --git a/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs b/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs index 90106238ce..c96987a839 100644 --- a/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs +++ b/apps/block_scout_web/test/block_scout_web/controllers/transaction_controller_test.exs @@ -12,7 +12,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do |> insert() |> with_block() - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") assert List.first(conn.assigns.transactions).hash == transaction.hash end @@ -22,7 +22,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do |> insert() |> with_block() - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") assert is_integer(conn.assigns.transaction_estimated_count) end @@ -35,7 +35,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do insert(:transaction) - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") assert [%Transaction{hash: ^hash}] = conn.assigns.transactions end @@ -53,7 +53,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do |> with_block() conn = - get(conn, "/en/transactions", %{ + get(conn, "/en/txs", %{ "block_number" => Integer.to_string(block_number), "index" => Integer.to_string(index) }) @@ -74,7 +74,7 @@ defmodule BlockScoutWeb.TransactionControllerTest do |> insert_list(:transaction, from_address: address) |> with_block(block) - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") assert %{"block_number" => ^number, "index" => 10} = conn.assigns.next_page_params end @@ -86,13 +86,13 @@ defmodule BlockScoutWeb.TransactionControllerTest do |> insert(from_address: address) |> with_block() - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") refute conn.assigns.next_page_params end test "works when there are no transactions", %{conn: conn} do - conn = get(conn, "/en/transactions") + conn = get(conn, "/en/txs") assert conn.assigns.transactions == [] end diff --git a/apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs b/apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs index 1f93e12fc5..b1b60ebd96 100644 --- a/apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/address_contract_verification_test.exs @@ -1,11 +1,9 @@ defmodule BlockScoutWeb.AddressContractVerificationTest do use BlockScoutWeb.FeatureCase, async: true - import Wallaby.Query - alias Plug.Conn - alias Explorer.Chain.Address alias Explorer.Factory + alias BlockScoutWeb.{AddressContractPage, ContractVerifyPage} setup do 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() transaction = :transaction |> insert() |> with_block() - address = %Address{hash: address_hash} = insert(:address, contract_code: bytecode) + address = insert(:address, contract_code: bytecode) insert( :internal_transaction_create, @@ -32,33 +30,30 @@ defmodule BlockScoutWeb.AddressContractVerificationTest do ) session - |> visit("/en/addresses/#{address_hash}/contract_verifications/new") - |> fill_in(text_field("Contract Name"), with: name) - |> click(option(version)) - |> click(radio_button("No")) - |> fill_in(text_field("Enter the Solidity Contract Code below"), with: source_code) - |> click(button("Verify and publish")) - - assert current_path(session) =~ ~r/\/en\/addresses\/#{address_hash}\/contracts/ + |> AddressContractPage.visit_page(address) + |> AddressContractPage.click_verify_and_publish() + |> ContractVerifyPage.fill_form(%{ + contract_name: name, + version: version, + optimization: false, + source_code: source_code + }) + |> ContractVerifyPage.verify_and_publish() + + assert AddressContractPage.on_page?(session, address) end 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) session - |> visit("/en/addresses/0x1e0eaa06d02f965be2dfe0bc9ff52b2d82133461/contract_verifications/new") - |> fill_in(text_field("Contract Name"), with: "") - |> fill_in(text_field("Enter the Solidity Contract Code below"), with: "") - |> click(button("Verify and publish")) - |> assert_has( - css( - "[data-test='contract-source-code-error']", - text: "there was an error validating your contract, please try again." - ) - ) + |> ContractVerifyPage.visit_page("0x1e0eaa06d02f965be2dfe0bc9ff52b2d82133461") + |> ContractVerifyPage.fill_form(%{contract_name: "", version: nil, optimization: nil, source_code: ""}) + |> ContractVerifyPage.verify_and_publish() + |> assert_has(ContractVerifyPage.validation_error()) end - def solc_bin_versions() do + defp solc_bin_versions do File.read!("./test/support/fixture/smart_contract/solc_bin.json") end end diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/address_contract_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/address_contract_page.ex new file mode 100644 index 0000000000..e8110aa86d --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/features/pages/address_contract_page.ex @@ -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 diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex index dd3a854d4c..e700c2ca8b 100644 --- a/apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex +++ b/apps/block_scout_web/test/block_scout_web/features/pages/address_page.ex @@ -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) do - visit(session, "/en/addresses/#{address_hash}") + visit(session, "/en/address/#{address_hash}") end def token_transfer(%Transaction{hash: transaction_hash}, %Address{hash: address_hash}, count: count) do diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/contract_verify_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/contract_verify_page.ex new file mode 100644 index 0000000000..0fcfd066a1 --- /dev/null +++ b/apps/block_scout_web/test/block_scout_web/features/pages/contract_verify_page.ex @@ -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 diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_list_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_list_page.ex index ca6dede9ae..e801d892b8 100644 --- a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_list_page.ex +++ b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_list_page.ex @@ -32,6 +32,6 @@ defmodule BlockScoutWeb.TransactionListPage do end def visit_page(session) do - visit(session, "/en/transactions") + visit(session, "/en/txs") end end diff --git a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_page.ex b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_page.ex index 0e662a914e..d8e3ad7eba 100644 --- a/apps/block_scout_web/test/block_scout_web/features/pages/transaction_page.ex +++ b/apps/block_scout_web/test/block_scout_web/features/pages/transaction_page.ex @@ -16,10 +16,10 @@ defmodule BlockScoutWeb.TransactionPage do end def visit_page(session, %Transaction{hash: transaction_hash}) do - visit(session, "/en/transactions/#{transaction_hash}") + visit(session, "/en/tx/#{transaction_hash}") end def visit_page(session, transaction_hash = %Hash{}) do - visit(session, "/en/transactions/#{transaction_hash}") + visit(session, "/en/tx/#{transaction_hash}") end end diff --git a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs index 3af69b1ff7..a2221c1003 100644 --- a/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs +++ b/apps/block_scout_web/test/block_scout_web/features/viewing_addresses_test.exs @@ -2,7 +2,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do use BlockScoutWeb.FeatureCase, async: true alias Explorer.Chain.Wei - alias BlockScoutWeb.AddressPage + alias Explorer.Factory + alias BlockScoutWeb.{AddressPage, AddressView} setup do block = insert(:block) @@ -40,7 +41,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do describe "viewing contract creator" do test "see the contract creator and transaction links", %{session: session} do 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) internal_transaction = @@ -52,8 +53,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do created_contract_address: contract ) - address_hash = BlockScoutWeb.AddressView.trimmed_hash(address.hash) - transaction_hash = BlockScoutWeb.AddressView.trimmed_hash(transaction.hash) + address_hash = AddressView.trimmed_hash(address.hash) + transaction_hash = AddressView.trimmed_hash(transaction.hash) session |> 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 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) - another_contract = insert(:address, contract_code: Explorer.Factory.data("contract_code")) + another_contract = insert(:address, contract_code: Factory.data("contract_code")) insert( :internal_transaction, @@ -85,8 +86,8 @@ defmodule BlockScoutWeb.ViewingAddressesTest do created_contract_address: another_contract ) - contract_hash = BlockScoutWeb.AddressView.trimmed_hash(contract.hash) - transaction_hash = BlockScoutWeb.AddressView.trimmed_hash(transaction.hash) + contract_hash = AddressView.trimmed_hash(contract.hash) + transaction_hash = AddressView.trimmed_hash(transaction.hash) session |> AddressPage.visit_page(internal_transaction.created_contract_address) @@ -337,7 +338,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do contract_token_address = insert( :address, - contract_code: Explorer.Factory.data("contract_code") + contract_code: Factory.data("contract_code") ) insert(:token, contract_address: contract_token_address)