Skip to content

Commit

Permalink
Merge pull request blockscout#23 from mrsmkl/fix_unit_tests
Browse files Browse the repository at this point in the history
fixing unit tests
  • Loading branch information
nambrot committed Nov 6, 2019
2 parents 8be64ad + c66d27e commit 6a7f184
Show file tree
Hide file tree
Showing 26 changed files with 104 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
elixir 1.9.1-otp-22
erlang 22.0
erlang 22.0.7
nodejs 10.11.0
4 changes: 2 additions & 2 deletions apps/block_scout_web/lib/block_scout_web/views/wei_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ defmodule BlockScoutWeb.WeiHelpers do
"10,000 Gwei"
iex> format_wei_value(%Wei{value: Decimal.new(1, 10, 21)}, :ether)
"10,000 Ether"
"10,000 cGLD"
# With formatting options
iex> format_wei_value(
...> %Wei{value: Decimal.new(1000500000000000000)},
...> :ether
...> )
"1.0005 Ether"
"1.0005 cGLD"
iex> format_wei_value(
...> %Wei{value: Decimal.new(10)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2561,6 +2561,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"value" => %{"type" => "string"},
"gas" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"isError" => %{"type" => "string"},
"txreceipt_status" => %{"type" => "string"},
"input" => %{"type" => "string"},
Expand Down Expand Up @@ -2620,6 +2622,8 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"transactionIndex" => %{"type" => "string"},
"gas" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"gasUsed" => %{"type" => "string"},
"cumulativeGasUsed" => %{"type" => "string"},
"input" => %{"type" => "string"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"timeStamp" => datetime_to_hex(block.timestamp),
"gasPrice" => decimal_to_hex(transaction.gas_price.value),
"gasUsed" => decimal_to_hex(transaction.gas_used),
"feeRecipient" => "",
"gasCurrency" => "",
"logIndex" => integer_to_hex(log.index),
"transactionHash" => "#{transaction.hash}",
"transactionIndex" => integer_to_hex(transaction.index)
Expand Down Expand Up @@ -446,6 +448,8 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"gasPrice" => decimal_to_hex(transaction.gas_price.value),
"gasUsed" => decimal_to_hex(transaction.gas_used),
"logIndex" => integer_to_hex(log1.index),
"feeRecipient" => "",
"gasCurrency" => "",
"transactionHash" => "#{transaction.hash}",
"transactionIndex" => integer_to_hex(transaction.index)
}
Expand Down Expand Up @@ -807,6 +811,8 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"blockNumber" => %{"type" => "string"},
"timeStamp" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"gasUsed" => %{"type" => "string"},
"logIndex" => %{"type" => "string"},
"transactionHash" => %{"type" => "string"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest do
"gasLimit" => "#{transaction.gas}",
"gasUsed" => "#{transaction.gas_used}",
"gasPrice" => "#{transaction.gas_price.value}",
"gasCurrency" => "#{transaction.gas_currency_hash}",
"gasFeeRecipient" => "#{transaction.gas_fee_recipient_hash}",
"logs" => [
%{
"address" => "#{address.hash}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule BlockScoutWeb.ViewingAddressesTest do

session
|> AddressPage.visit_page(address)
|> assert_text(AddressPage.balance(), "0.0000000000000005 Ether")
|> assert_text(AddressPage.balance(), "0.0000000000000005 cGLD")
end

describe "viewing contract creator" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ defmodule BlockScoutWeb.AddressCoinBalanceViewTest do
test "format the wei value in ether" do
wei = Wei.from(Decimal.new(1_340_000_000), :gwei)

assert AddressCoinBalanceView.format(wei) == "1.34 Ether"
assert AddressCoinBalanceView.format(wei) == "1.34 cGLD"
end

test "format negative values" do
wei = Wei.from(Decimal.new(-1_340_000_000), :gwei)

assert AddressCoinBalanceView.format(wei) == "-1.34 Ether"
assert AddressCoinBalanceView.format(wei) == "-1.34 cGLD"
end
end

Expand Down Expand Up @@ -50,13 +50,13 @@ defmodule BlockScoutWeb.AddressCoinBalanceViewTest do
test "format positive values" do
value = Decimal.new(1_340_000_000_000_000_000)

assert AddressCoinBalanceView.format_delta(value) == "1.34 Ether"
assert AddressCoinBalanceView.format_delta(value) == "1.34 cGLD"
end

test "format negative values" do
value = Decimal.new(-1_340_000_000_000_000_000)

assert AddressCoinBalanceView.format_delta(value) == "1.34 Ether"
assert AddressCoinBalanceView.format_delta(value) == "1.34 cGLD"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule BlockScoutWeb.BlockViewTest do

block = Repo.preload(block, :rewards)

assert BlockView.combined_rewards_value(block) == "3.000042 Ether"
assert BlockView.combined_rewards_value(block) == "3.000042 cGLD"
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule BlockScoutWeb.LayoutViewTest do
end

test "use the default logo when there is no env configured for it" do
assert LayoutView.logo() == "/images/blockscout_logo.svg"
assert LayoutView.logo() == "/images/celo_logo.svg"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ defmodule BlockScoutWeb.TransactionViewTest do
gas_used: nil
)

expected_value = "Max of 0.009 Ether"
expected_value = "Max of 0.009 cGLD"
assert expected_value == TransactionView.formatted_fee(transaction, denomination: :ether)
end

test "with fee" do
{:ok, gas_price} = Wei.cast(3_000_000_000)
transaction = build(:transaction, gas_price: gas_price, gas_used: Decimal.from_float(1_034_234.0))

expected_value = "0.003102702 Ether"
expected_value = "0.003102702 cGLD"
assert expected_value == TransactionView.formatted_fee(transaction, denomination: :ether)
end
end
Expand Down
8 changes: 4 additions & 4 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transactions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ defmodule EthereumJSONRPC.Transactions do
from_address_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
gas: 4700000,
gas_price: 100000000000,
gas_currency: nil,
gas_fee_recipient: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
gas_currency_hash: nil,
gas_fee_recipient_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
hash: "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
index: 0,
input: "0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102db8061005e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a72305820a9c628775efbfbc17477a472413c01ee9b33881f550c59d21bee9928835c854b0029",
Expand Down Expand Up @@ -81,8 +81,8 @@ defmodule EthereumJSONRPC.Transactions do
...> from_address_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
...> gas: 4700000,
...> gas_price: 100000000000,
...> gas_currency: nil,
...> gas_fee_recipient: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
...> gas_currency_hash: nil,
...> gas_fee_recipient_hash: "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
...> hash: "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
...> index: 0,
...> input: "0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102db8061005e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a72305820a9c628775efbfbc17477a472413c01ee9b33881f550c59d21bee9928835c854b0029",
Expand Down
18 changes: 15 additions & 3 deletions apps/ethereum_jsonrpc/test/ethereum_jsonrpc/geth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ defmodule EthereumJSONRPC.GethTest do
"from" => "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
"gas" => "0x3d0900",
"gasPrice" => "0x3b9aca00",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"hash" => "0x2b8cfd76a31b942e51b6265c791c860e2840b11f8c2fcfa1c9dfe53dea4c3102",
"input" =>
"0xc47e300d000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000030af6932dec7c4eaf4b966059e74cc7a1767ba93e62f2d83a7dba5bb785b6efd25e8ab7d2e8798e7ecc27df96380d77a0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000b29e5229b86fbb3a8e45e406b64226c3d49389804a6f7449325fae232d6623000000000000000000000000000000000000000000000000000000000000006097e4c1ed443f430b1d8ad66e565a960fade76e3e177b4120186bdad2fcfa43e134de3abdc0272c9433af94833fec73260c261cf41422e83d958787b62144478bc44ab84d1ddba7a462d355057f3be8ab914a195ac1a637c4fb8503c441dadb45",
Expand All @@ -112,6 +114,8 @@ defmodule EthereumJSONRPC.GethTest do
"blockHash" => "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber" => nil,
"from" => "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"gas" => "0x3d0900",
"gasPrice" => "0x3b9aca00",
"hash" => "0x7c3ea924740e996bf552a8dded903ba4258b69d30bf5e6dca6ec86ebc60b8151",
Expand All @@ -129,6 +133,8 @@ defmodule EthereumJSONRPC.GethTest do
"blockHash" => "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockNumber" => nil,
"from" => "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"gas" => "0x3d0900",
"gasPrice" => "0x3b9aca00",
"hash" => "0xe699a58ef4986f2dbdc102acf73b35392aff9ce43fd226000526955e19c0b06e",
Expand Down Expand Up @@ -156,8 +162,10 @@ defmodule EthereumJSONRPC.GethTest do
from_address_hash: "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
gas: 4_000_000,
gas_price: 1_000_000_000,
gas_currency_hash: "0x0",
gas_fee_recipient_hash: "0x0",
hash: "0x2b8cfd76a31b942e51b6265c791c860e2840b11f8c2fcfa1c9dfe53dea4c3102",
index: 0,
index: nil,
input:
"0xc47e300d000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000030af6932dec7c4eaf4b966059e74cc7a1767ba93e62f2d83a7dba5bb785b6efd25e8ab7d2e8798e7ecc27df96380d77a0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000b29e5229b86fbb3a8e45e406b64226c3d49389804a6f7449325fae232d6623000000000000000000000000000000000000000000000000000000000000006097e4c1ed443f430b1d8ad66e565a960fade76e3e177b4120186bdad2fcfa43e134de3abdc0272c9433af94833fec73260c261cf41422e83d958787b62144478bc44ab84d1ddba7a462d355057f3be8ab914a195ac1a637c4fb8503c441dadb45",
nonce: 4656,
Expand All @@ -176,8 +184,10 @@ defmodule EthereumJSONRPC.GethTest do
from_address_hash: "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
gas: 4_000_000,
gas_price: 1_000_000_000,
gas_currency_hash: "0x0",
gas_fee_recipient_hash: "0x0",
hash: "0x7c3ea924740e996bf552a8dded903ba4258b69d30bf5e6dca6ec86ebc60b8151",
index: 0,
index: nil,
input:
"0xc47e300d000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000030a25723bca32f88a73abc7eb153cee248effd563d87efe12e08e8a33f74047afc28c30ab9c74bddeb6f0558628b8bf200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020009c56025b2796cdc72f91836278a471590b774462adddd1c87a0b6f84b787990000000000000000000000000000000000000000000000000000000000000060aa53b46c8b57aed7c4c0fdf3f650ec3bb330591929bc813610656882e3203157c22b50d0d0b0316a8712c00fe4f0e0c509613114f5d24c0419a4e8188f2489678b05dccf72a67957785e8e250092c8787f049f7e20b1414a633595a56c98ff82",
nonce: 4657,
Expand All @@ -196,8 +206,10 @@ defmodule EthereumJSONRPC.GethTest do
from_address_hash: "0xc99f4e9cff697ca6717ad9ce8ba4a138e0e55109",
gas: 4_000_000,
gas_price: 1_000_000_000,
gas_currency_hash: "0x0",
gas_fee_recipient_hash: "0x0",
hash: "0xe699a58ef4986f2dbdc102acf73b35392aff9ce43fd226000526955e19c0b06e",
index: 0,
index: nil,
input:
"0xc47e300d000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000308eb3ed9e686f6bc1fe2d8ce3fea37fb3a66a9c67b91ef15ba6bd7da0eed73288f72577edea2b7ded5855ca8a56b1e01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000051afe6c51e2175a62afbd66d293e8a7509943d5cd6f851f59923a61a186e80000000000000000000000000000000000000000000000000000000000000060a063498e8db2e75e0a193de89ad2947111d677c9501e75c34a64fcee8fe5a7c7607929fc6bce943d64f1039e1d1f325f02d1e5d71f86ca976c9ab79d19f0fd0e530a5210fbe131087ba1f1b3c92abc4a0dd7c8a47c3c276fac3e09bca964fd74",
nonce: 4658,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ defmodule EthereumJSONRPC.TransactionsTest do
"from" => "0xe8ddc5c7a2d2f0d7a9798459c0104fdf5e987aca",
"gas" => "0x0",
"gasPrice" => "0x0",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"hash" => "0x3a3eb134e6792ce9403ea4188e5e79693de9e4c94e499db132be086400da79e6",
"input" =>
"0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506102db8061005e6000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680630900f01014610067578063445df0ac146100a05780638da5cb5b146100c9578063fdacd5761461011e575b600080fd5b341561007257600080fd5b61009e600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091905050610141565b005b34156100ab57600080fd5b6100b3610224565b6040518082815260200191505060405180910390f35b34156100d457600080fd5b6100dc61022a565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561012957600080fd5b61013f600480803590602001909190505061024f565b005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610220578190508073ffffffffffffffffffffffffffffffffffffffff1663fdacd5766001546040518263ffffffff167c010000000000000000000000000000000000000000000000000000000002815260040180828152602001915050600060405180830381600087803b151561020b57600080fd5b6102c65a03f1151561021c57600080fd5b5050505b5050565b60015481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102ac57806001819055505b505600a165627a7a72305820a9c628775efbfbc17477a472413c01ee9b33881f550c59d21bee9928835c854b0029",
Expand Down
4 changes: 4 additions & 0 deletions apps/ethereum_jsonrpc/test/ethereum_jsonrpc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ defmodule EthereumJSONRPCTest do
"from" => "0x0",
"gas" => "0x0",
"gasPrice" => "0x0",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"hash" => transaction_hash,
"input" => "0x",
"nonce" => "0x0",
Expand Down Expand Up @@ -628,6 +630,8 @@ defmodule EthereumJSONRPCTest do
"from" => "0x0",
"gas" => "0x0",
"gasPrice" => "0x0",
"gasCurrency" => "0x0",
"gasFeeRecipient" => "0x0",
"hash" => "0x73c5599001f77bd570e32c4a5e63157200747910a502fae009821767c36b2ac9",
"input" => "0x",
"nonce" => "0x0",
Expand Down

0 comments on commit 6a7f184

Please sign in to comment.