From e42a7cfb10679aa3a55163f8b1f2a13db4311969 Mon Sep 17 00:00:00 2001 From: Tim Mecklem Date: Thu, 19 Jul 2018 14:55:36 -0400 Subject: [PATCH] Set up contract verification test with `create` internal transaction Co-authored-by: stamates --- apps/explorer/test/support/factory.ex | 13 ++++--------- .../address_contract_verification_test.exs | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 018264f964..b301a23f2b 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -29,13 +29,6 @@ defmodule Explorer.Factory do } end - def contract_address_factory do - %Address{ - hash: address_hash(), - contract_code: Map.fetch!(contract_code_info(), :bytecode) - } - end - def contract_code_info do %{ bytecode: @@ -187,9 +180,11 @@ defmodule Explorer.Factory do gas = Enum.random(21_000..100_000) gas_used = Enum.random(0..gas) + contract_code = Map.fetch!(contract_code_info(), :bytecode) + %InternalTransaction{ - created_contract_code: data(:internal_transaction_created_contract_code), - created_contract_address: build(:address), + created_contract_code: contract_code, + created_contract_address: build(:address, contract_code: contract_code), from_address: build(:address), gas: gas, gas_used: gas_used, diff --git a/apps/explorer_web/test/explorer_web/features/address_contract_verification_test.exs b/apps/explorer_web/test/explorer_web/features/address_contract_verification_test.exs index e859112c02..74e2d0eafc 100644 --- a/apps/explorer_web/test/explorer_web/features/address_contract_verification_test.exs +++ b/apps/explorer_web/test/explorer_web/features/address_contract_verification_test.exs @@ -4,6 +4,7 @@ defmodule ExplorerWeb.AddressContractVerificationTest do import Wallaby.Query alias Plug.Conn + alias Explorer.Chain.Address alias Explorer.Factory setup do @@ -19,17 +20,26 @@ defmodule ExplorerWeb.AddressContractVerificationTest do %{name: name, source_code: source_code, bytecode: bytecode, version: version} = Factory.contract_code_info() - contract_address = insert(:contract_address, contract_code: bytecode) + transaction = :transaction |> insert() |> with_block() + address = %Address{hash: address_hash} = insert(:address, contract_code: bytecode) + + insert( + :internal_transaction_create, + created_contract_address: address, + created_contract_code: bytecode, + index: 0, + transaction: transaction + ) session - |> visit("/en/addresses/#{contract_address.hash}/contract_verifications/new") + |> 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\/#{contract_address.hash}\/contracts/ + assert current_path(session) =~ ~r/\/en\/addresses\/#{address_hash}\/contracts/ end test "with invalid data shows error messages", %{session: session, bypass: bypass} do