From b9160f2175cd6633a2f08d8ed30fc33b395529b8 Mon Sep 17 00:00:00 2001 From: saneery Date: Tue, 14 May 2019 16:27:59 +0300 Subject: [PATCH 1/6] calculate staked ratio after insert pools --- .../chain/import/runner/staking_pools.ex | 16 +- .../import/runner/staking_pools_test.exs | 138 ++++++++++-------- 2 files changed, 90 insertions(+), 64 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index aaf5d7242e..17a13dd5bc 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -62,7 +62,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do {:ok, _} = Import.insert_changes_list( repo, - changes_list, + stakes_ratio(changes_list), conflict_target: {:unsafe_fragment, "(address_hash) where \"primary\" = true"}, on_conflict: on_conflict, for: Address.Name, @@ -85,4 +85,18 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do ] ) end + + # Calculates staked ratio for each pool + defp stakes_ratio(pools) do + active_pools = Enum.filter(pools, & &1.metadata[:is_active]) + + stakes_total = Enum.reduce(pools, 0, fn pool, acc -> + acc + pool.metadata[:staked_amount] + end) + + Enum.map(active_pools, fn pool -> + staked_ratio = pool.metadata[:staked_amount] / stakes_total + put_in(pool, [:metadata, :staked_ratio], staked_ratio) + end) + end end diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs index d5bc6ecfca..5f5ec5a3be 100644 --- a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs @@ -6,80 +6,92 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do describe "run/1" do test "insert new pools list" do - pools = [ - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>> - }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ + pools = + [pool1, pool2, pool3] = [ + %{ + address_hash: %Explorer.Chain.Hash{ byte_count: 20, - bytes: <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>> + bytes: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>> }, - retries_count: 1, - staked_amount: 0, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - }, - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<170, 148, 182, 135, 211, 249, 85, 42, 69, 59, 129, 178, 131, 76, 165, 55, 120, 152, 13, 192>> + metadata: %{ + banned_unitil: 0, + delegators_count: 0, + is_active: true, + is_banned: false, + is_validator: true, + mining_address: %Explorer.Chain.Hash{ + byte_count: 20, + bytes: <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>> + }, + retries_count: 1, + staked_amount: 25, + was_banned_count: 0, + was_validator_count: 1 + }, + name: "anonymous", + primary: true }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ + %{ + address_hash: %Explorer.Chain.Hash{ byte_count: 20, - bytes: <<117, 223, 66, 56, 58, 254, 107, 245, 25, 74, 168, 250, 14, 155, 61, 95, 158, 134, 148, 65>> + bytes: <<170, 148, 182, 135, 211, 249, 85, 42, 69, 59, 129, 178, 131, 76, 165, 55, 120, 152, 13, 192>> }, - retries_count: 1, - staked_amount: 0, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - }, - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<49, 44, 35, 14, 125, 109, 176, 82, 36, 246, 2, 8, 166, 86, 227, 84, 28, 92, 66, 186>> + metadata: %{ + banned_unitil: 0, + delegators_count: 0, + is_active: true, + is_banned: false, + is_validator: true, + mining_address: %Explorer.Chain.Hash{ + byte_count: 20, + bytes: <<117, 223, 66, 56, 58, 254, 107, 245, 25, 74, 168, 250, 14, 155, 61, 95, 158, 134, 148, 65>> + }, + retries_count: 1, + staked_amount: 25, + was_banned_count: 0, + was_validator_count: 1 + }, + name: "anonymous", + primary: true }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ + %{ + address_hash: %Explorer.Chain.Hash{ byte_count: 20, - bytes: <<82, 45, 243, 150, 174, 112, 160, 88, 189, 105, 119, 132, 8, 99, 15, 219, 2, 51, 137, 178>> + bytes: <<49, 44, 35, 14, 125, 109, 176, 82, 36, 246, 2, 8, 166, 86, 227, 84, 28, 92, 66, 186>> }, - retries_count: 1, - staked_amount: 0, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - } - ] + metadata: %{ + banned_unitil: 0, + delegators_count: 0, + is_active: true, + is_banned: false, + is_validator: true, + mining_address: %Explorer.Chain.Hash{ + byte_count: 20, + bytes: <<82, 45, 243, 150, 174, 112, 160, 88, 189, 105, 119, 132, 8, 99, 15, 219, 2, 51, 137, 178>> + }, + retries_count: 1, + staked_amount: 0, + was_banned_count: 0, + was_validator_count: 1 + }, + name: "anonymous", + primary: true + } + ] assert {:ok, %{insert_staking_pools: list}} = run_changes(pools) assert Enum.count(list) == Enum.count(pools) + + saved_list = + Explorer.Chain.Address.Name + |> Repo.all() + |> Enum.reduce(%{}, fn pool, acc -> + Map.put(acc, pool.address_hash, pool) + end) + + assert saved_list[pool1.address_hash].metadata["staked_ratio"] == 0.5 + assert saved_list[pool2.address_hash].metadata["staked_ratio"] == 0.5 + assert saved_list[pool3.address_hash].metadata["staked_ratio"] == 0.0 end end From 822986c13554a75a022291cade4a00cb22dfa831 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 15 May 2019 12:19:57 +0300 Subject: [PATCH 2/6] format --- .../lib/explorer/chain/import/runner/staking_pools.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index 17a13dd5bc..95c3c62e55 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -90,9 +90,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do defp stakes_ratio(pools) do active_pools = Enum.filter(pools, & &1.metadata[:is_active]) - stakes_total = Enum.reduce(pools, 0, fn pool, acc -> - acc + pool.metadata[:staked_amount] - end) + stakes_total = + Enum.reduce(pools, 0, fn pool, acc -> + acc + pool.metadata[:staked_amount] + end) Enum.map(active_pools, fn pool -> staked_ratio = pool.metadata[:staked_amount] / stakes_total From 3a44d6caf4012f8c4ee0630f49e4e0c591dbfb09 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 15 May 2019 12:21:23 +0300 Subject: [PATCH 3/6] add entry to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 864fb2099e..31183dc8ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - [#1920](https://github.com/poanetwork/blockscout/pull/1920) - fix: remove source code fields from list endpoint - [#1876](https://github.com/poanetwork/blockscout/pull/1876) - async calculate a count of blocks - [#1941](https://github.com/poanetwork/blockscout/pull/1941) - feat: add on demand fetching and stale attr to rpc +- [#1957](https://github.com/poanetwork/blockscout/pull/1957) - Calculate stakes ratio before insert pools ### Fixes From e993c95e4bf6258db602cafb0728ebba68786197 Mon Sep 17 00:00:00 2001 From: saneery Date: Wed, 15 May 2019 12:55:02 +0300 Subject: [PATCH 4/6] handle case when total stakes is zero --- .../explorer/lib/explorer/chain/import/runner/staking_pools.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex index 95c3c62e55..457175a9e4 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex @@ -96,7 +96,8 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do end) Enum.map(active_pools, fn pool -> - staked_ratio = pool.metadata[:staked_amount] / stakes_total + staked_ratio = if stakes_total > 0, do: pool.metadata[:staked_amount] / stakes_total, else: 0 + put_in(pool, [:metadata, :staked_ratio], staked_ratio) end) end From 6c85f8b7e4b1949b9d1072ebbc957bc785dc6eed Mon Sep 17 00:00:00 2001 From: zachdaniel Date: Wed, 15 May 2019 14:28:05 -0400 Subject: [PATCH 5/6] feat: display init for selfdestructed contracts. --- CHANGELOG.md | 1 + .../templates/address_contract/index.html.eex | 58 +++++++++++++------ .../views/address_contract_view.ex | 13 +++++ apps/block_scout_web/priv/gettext/default.pot | 53 ++++++++++++----- .../priv/gettext/en/LC_MESSAGES/default.po | 57 ++++++++++++------ .../chain/internal_transaction/result.ex | 2 +- .../chain/internal_transaction_test.exs | 4 +- 7 files changed, 134 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed6b6014d..6131176923 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - [#1876](https://github.com/poanetwork/blockscout/pull/1876) - async calculate a count of blocks - [#1941](https://github.com/poanetwork/blockscout/pull/1941) - feat: add on demand fetching and stale attr to rpc - [#1952](https://github.com/poanetwork/blockscout/pull/1952) - feat: exclude empty contracts by default +- [#1954](https://github.com/poanetwork/blockscout/pull/1954) - feat: use creation init on self destruct ### Fixes 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 560440fb4e..b7b2282682 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 @@ -1,18 +1,25 @@ +<% contract_creation_code = contract_creation_code(@address) %> +
<%= render BlockScoutWeb.AddressView, "overview.html", assigns %>
<%= render BlockScoutWeb.AddressView, "_tabs.html", assigns %>
- <%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> - <%= link( - gettext("Verify & Publish"), - to: address_verify_contract_path(@conn, :new, @address.hash), - class: "button button-primary button-sm float-right ml-3", - "data-test": "verify_and_publish" - ) %> + <%= if match?({:selfdestructed, _}, contract_creation_code) do %> +
+ <%= gettext("Verify & Publish") %> +
+ <% else %> + <%= if !BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %> + <%= link( + gettext("Verify & Publish"), + to: address_verify_contract_path(@conn, :new, @address.hash), + class: "button button-primary button-sm float-right ml-3", + "data-test": "verify_and_publish" + ) %> + <% end %> <% end %> - <%= if BlockScoutWeb.AddressView.smart_contract_verified?(@address) do %>
@@ -56,15 +63,32 @@ <% end %>
-
-

<%= gettext "Contract creation code" %>

- -
-
-
<%= @address.contract_code %>
-
+ <%= case contract_creation_code do %> + <% {:selfdestructed, transaction_init} -> %> +
+

<%= gettext "Contract Creation Code" %>

+ +
+
+

<%= gettext "Contracts that self destruct in their constructors have no contract code published and cannot be verified." %>

+

<%= gettext "Displaying the init data provided of the creating transaction." %>

+
+
+
<%= transaction_init %>
+
+ <% {:ok, contract_code} -> %> +
+

<%= gettext "Contract Byte Code" %>

+ +
+
+
<%= contract_code %>
+
+ <% end %>
diff --git a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex index 27dbd1b559..4dc99a2a68 100644 --- a/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex +++ b/apps/block_scout_web/lib/block_scout_web/views/address_contract_view.ex @@ -1,6 +1,8 @@ defmodule BlockScoutWeb.AddressContractView do use BlockScoutWeb, :view + alias Explorer.Chain.{Address, Data, InternalTransaction} + def render("scripts.html", %{conn: conn}) do render_scripts(conn, "address_contract/code_highlighting.js") end @@ -34,4 +36,15 @@ defmodule BlockScoutWeb.AddressContractView do {value, String.pad_leading(to_string(line), max_digits, " ")} end) end + + def contract_creation_code(%Address{ + contract_code: %Data{bytes: <<>>}, + contracts_creation_internal_transaction: %InternalTransaction{init: init} + }) do + {:selfdestructed, init} + end + + def contract_creation_code(%Address{contract_code: contract_code}) do + {:ok, contract_code} + end end diff --git a/apps/block_scout_web/priv/gettext/default.pot b/apps/block_scout_web/priv/gettext/default.pot index 7922c7d2f0..1a6f16d7b1 100644 --- a/apps/block_scout_web/priv/gettext/default.pot +++ b/apps/block_scout_web/priv/gettext/default.pot @@ -228,7 +228,7 @@ msgid "Compiler" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:23 +#: lib/block_scout_web/templates/address_contract/index.html.eex:30 msgid "Compiler version" msgstr "" @@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:46 +#: lib/block_scout_web/templates/address_contract/index.html.eex:53 msgid "Contract ABI" msgstr "" @@ -289,17 +289,12 @@ msgid "Contract Name" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:60 -msgid "Contract creation code" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:19 +#: lib/block_scout_web/templates/address_contract/index.html.eex:26 msgid "Contract name:" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:34 +#: lib/block_scout_web/templates/address_contract/index.html.eex:41 msgid "Contract source code" msgstr "" @@ -621,7 +616,7 @@ msgid "Older" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:27 +#: lib/block_scout_web/templates/address_contract/index.html.eex:34 msgid "Optimization enabled" msgstr "" @@ -982,7 +977,8 @@ msgid "Value" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:9 +#: lib/block_scout_web/templates/address_contract/index.html.eex:11 +#: lib/block_scout_web/templates/address_contract/index.html.eex:16 msgid "Verify & Publish" msgstr "" @@ -1047,7 +1043,7 @@ msgid "at" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_contract_view.ex:20 +#: lib/block_scout_web/views/address_contract_view.ex:22 msgid "false" msgstr "" @@ -1065,7 +1061,7 @@ msgid "string" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_contract_view.ex:19 +#: lib/block_scout_web/views/address_contract_view.ex:21 msgid "true" msgstr "" @@ -1509,17 +1505,17 @@ msgid "Support" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:48 +#: lib/block_scout_web/templates/address_contract/index.html.eex:55 msgid "Copy ABI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:62 +#: lib/block_scout_web/templates/address_contract/index.html.eex:71 msgid "Copy Contract Creation Code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:36 +#: lib/block_scout_web/templates/address_contract/index.html.eex:43 msgid "Copy Source Code" msgstr "" @@ -1745,3 +1741,28 @@ msgstr "" #: lib/block_scout_web/templates/common_components/_pagination_container.html.eex:37 msgid "of" msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:83 +msgid "Contract Byte Code" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:69 +msgid "Contract Creation Code" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:75 +msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:85 +msgid "Copy Contract Byte Code" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:76 +msgid "Displaying the init data provided of the creating transaction." +msgstr "" diff --git a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po index 8925a95acf..2f8d4a3d47 100644 --- a/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po +++ b/apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po @@ -228,7 +228,7 @@ msgid "Compiler" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:23 +#: lib/block_scout_web/templates/address_contract/index.html.eex:30 msgid "Compiler version" msgstr "" @@ -256,7 +256,7 @@ msgid "Connection Lost, click to load newer validations" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:46 +#: lib/block_scout_web/templates/address_contract/index.html.eex:53 msgid "Contract ABI" msgstr "" @@ -289,17 +289,12 @@ msgid "Contract Name" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:60 -msgid "Contract creation code" -msgstr "" - -#, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:19 +#: lib/block_scout_web/templates/address_contract/index.html.eex:26 msgid "Contract name:" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:34 +#: lib/block_scout_web/templates/address_contract/index.html.eex:41 msgid "Contract source code" msgstr "" @@ -621,7 +616,7 @@ msgid "Older" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:27 +#: lib/block_scout_web/templates/address_contract/index.html.eex:34 msgid "Optimization enabled" msgstr "" @@ -982,7 +977,8 @@ msgid "Value" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:9 +#: lib/block_scout_web/templates/address_contract/index.html.eex:11 +#: lib/block_scout_web/templates/address_contract/index.html.eex:16 msgid "Verify & Publish" msgstr "" @@ -1047,7 +1043,7 @@ msgid "at" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_contract_view.ex:20 +#: lib/block_scout_web/views/address_contract_view.ex:22 msgid "false" msgstr "" @@ -1065,7 +1061,7 @@ msgid "string" msgstr "" #, elixir-format -#: lib/block_scout_web/views/address_contract_view.ex:19 +#: lib/block_scout_web/views/address_contract_view.ex:21 msgid "true" msgstr "" @@ -1357,7 +1353,7 @@ msgid "Loading balances" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:23 +#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:22 #: lib/block_scout_web/templates/chain/show.html.eex:13 msgid "Loading chart" msgstr "" @@ -1368,7 +1364,7 @@ msgid "There is no coin history for this address." msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:26 +#: lib/block_scout_web/templates/address_coin_balance/index.html.eex:25 #: lib/block_scout_web/templates/chain/show.html.eex:16 msgid "There was a problem loading the chart." msgstr "" @@ -1509,17 +1505,17 @@ msgid "Support" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:48 +#: lib/block_scout_web/templates/address_contract/index.html.eex:55 msgid "Copy ABI" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:62 +#: lib/block_scout_web/templates/address_contract/index.html.eex:71 msgid "Copy Contract Creation Code" msgstr "" #, elixir-format -#: lib/block_scout_web/templates/address_contract/index.html.eex:36 +#: lib/block_scout_web/templates/address_contract/index.html.eex:43 msgid "Copy Source Code" msgstr "" @@ -1745,3 +1741,28 @@ msgstr "" #: lib/block_scout_web/templates/common_components/_pagination_container.html.eex:37 msgid "of" msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_contract/index.html.eex:83 +msgid "Contract Byte Code" +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_contract/index.html.eex:69 +msgid "Contract Creation Code" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:75 +msgid "Contracts that self destruct in their constructors have no contract code published and cannot be verified." +msgstr "" + +#, elixir-format, fuzzy +#: lib/block_scout_web/templates/address_contract/index.html.eex:85 +msgid "Copy Contract Byte Code" +msgstr "" + +#, elixir-format +#: lib/block_scout_web/templates/address_contract/index.html.eex:76 +msgid "Displaying the init data provided of the creating transaction." +msgstr "" diff --git a/apps/explorer/lib/explorer/chain/internal_transaction/result.ex b/apps/explorer/lib/explorer/chain/internal_transaction/result.ex index 5b4e3102fc..c4c680e7d4 100644 --- a/apps/explorer/lib/explorer/chain/internal_transaction/result.ex +++ b/apps/explorer/lib/explorer/chain/internal_transaction/result.ex @@ -19,7 +19,7 @@ defmodule Explorer.Chain.InternalTransaction.Result do {key, to_string(hash)} end - defp entry_to_raw({"code", _} = entry), do: entry + defp entry_to_raw({"code", code}), do: {"code", Data.to_string(code)} defp entry_to_raw({key, decimal}) when key in ~w(gasUsed) do integer = diff --git a/apps/explorer/test/explorer/chain/internal_transaction_test.exs b/apps/explorer/test/explorer/chain/internal_transaction_test.exs index 54ace519bd..fc3977a998 100644 --- a/apps/explorer/test/explorer/chain/internal_transaction_test.exs +++ b/apps/explorer/test/explorer/chain/internal_transaction_test.exs @@ -1,7 +1,7 @@ defmodule Explorer.Chain.InternalTransactionTest do use Explorer.DataCase - alias Explorer.Chain.{InternalTransaction, Wei} + alias Explorer.Chain.{Data, InternalTransaction, Wei} alias Explorer.Factory import EthereumJSONRPC, only: [integer_to_quantity: 1] @@ -173,7 +173,7 @@ defmodule Explorer.Chain.InternalTransactionTest do end test "it correctly formats a create" do - contract_code = Factory.contract_code_info().bytecode + {:ok, contract_code} = Data.cast(Factory.contract_code_info().bytecode) contract_address = Factory.address_hash() from = Factory.address_hash() gas = 50_000 From a68c822b8408e3e06022cab9208531b145351724 Mon Sep 17 00:00:00 2001 From: saneery Date: Mon, 20 May 2019 18:30:42 +0300 Subject: [PATCH 6/6] staking pools factory --- .../import/runner/staking_pools_test.exs | 82 ++----------------- apps/explorer/test/support/factory.ex | 20 +++++ 2 files changed, 27 insertions(+), 75 deletions(-) diff --git a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs index 5f5ec5a3be..af25368679 100644 --- a/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs +++ b/apps/explorer/test/explorer/chain/import/runner/staking_pools_test.exs @@ -1,83 +1,14 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do use Explorer.DataCase + import Explorer.Factory + alias Ecto.Multi alias Explorer.Chain.Import.Runner.StakingPools describe "run/1" do test "insert new pools list" do - pools = - [pool1, pool2, pool3] = [ - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<11, 47, 94, 47, 60, 189, 134, 78, 170, 44, 100, 46, 55, 105, 193, 88, 35, 97, 202, 246>> - }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<187, 202, 168, 212, 130, 137, 187, 31, 252, 249, 128, 141, 154, 164, 177, 210, 21, 5, 76, 120>> - }, - retries_count: 1, - staked_amount: 25, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - }, - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<170, 148, 182, 135, 211, 249, 85, 42, 69, 59, 129, 178, 131, 76, 165, 55, 120, 152, 13, 192>> - }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<117, 223, 66, 56, 58, 254, 107, 245, 25, 74, 168, 250, 14, 155, 61, 95, 158, 134, 148, 65>> - }, - retries_count: 1, - staked_amount: 25, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - }, - %{ - address_hash: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<49, 44, 35, 14, 125, 109, 176, 82, 36, 246, 2, 8, 166, 86, 227, 84, 28, 92, 66, 186>> - }, - metadata: %{ - banned_unitil: 0, - delegators_count: 0, - is_active: true, - is_banned: false, - is_validator: true, - mining_address: %Explorer.Chain.Hash{ - byte_count: 20, - bytes: <<82, 45, 243, 150, 174, 112, 160, 88, 189, 105, 119, 132, 8, 99, 15, 219, 2, 51, 137, 178>> - }, - retries_count: 1, - staked_amount: 0, - was_banned_count: 0, - was_validator_count: 1 - }, - name: "anonymous", - primary: true - } - ] + pools = [pool1, pool2, pool3, pool4] = build_list(4, :staking_pool) assert {:ok, %{insert_staking_pools: list}} = run_changes(pools) assert Enum.count(list) == Enum.count(pools) @@ -89,9 +20,10 @@ defmodule Explorer.Chain.Import.Runner.StakingPoolsTest do Map.put(acc, pool.address_hash, pool) end) - assert saved_list[pool1.address_hash].metadata["staked_ratio"] == 0.5 - assert saved_list[pool2.address_hash].metadata["staked_ratio"] == 0.5 - assert saved_list[pool3.address_hash].metadata["staked_ratio"] == 0.0 + assert saved_list[pool1.address_hash].metadata["staked_ratio"] == 0.25 + assert saved_list[pool2.address_hash].metadata["staked_ratio"] == 0.25 + assert saved_list[pool3.address_hash].metadata["staked_ratio"] == 0.25 + assert saved_list[pool4.address_hash].metadata["staked_ratio"] == 0.25 end end diff --git a/apps/explorer/test/support/factory.ex b/apps/explorer/test/support/factory.ex index 4c030a4db1..115b07e066 100644 --- a/apps/explorer/test/support/factory.ex +++ b/apps/explorer/test/support/factory.ex @@ -609,4 +609,24 @@ defmodule Explorer.Factory do user: build(:user) } end + + def staking_pool_factory do + %{ + address_hash: address_hash(), + metadata: %{ + banned_unitil: 0, + delegators_count: 0, + is_active: true, + is_banned: false, + is_validator: true, + mining_address: address_hash(), + retries_count: 1, + staked_amount: 25, + was_banned_count: 0, + was_validator_count: 1 + }, + name: "anonymous", + primary: true + } + end end