|
|
@ -3,7 +3,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
alias Explorer.{Chain, Repo} |
|
|
|
|
|
|
|
|
|
|
|
alias Explorer.Chain.{Address, Block, InternalTransaction, Log, Receipt, Transaction} |
|
|
|
alias Explorer.Chain.{Address, Block, InternalTransaction, Log, Receipt, Transaction, Wei} |
|
|
|
|
|
|
|
|
|
|
|
# Constants |
|
|
|
# Constants |
|
|
|
|
|
|
|
|
|
|
@ -155,19 +155,19 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "balance/2" do |
|
|
|
describe "balance/2" do |
|
|
|
test "with Address.t with :wei" do |
|
|
|
test "with Address.t with :wei" do |
|
|
|
assert Chain.balance(%Address{balance: Decimal.new(1)}, :wei) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: %Wei{value: Decimal.new(1)}}, :wei) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: nil}, :wei) == nil |
|
|
|
assert Chain.balance(%Address{balance: nil}, :wei) == nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with Address.t with :gwei" do |
|
|
|
test "with Address.t with :gwei" do |
|
|
|
assert Chain.balance(%Address{balance: Decimal.new(1)}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.balance(%Address{balance: %Wei{value: Decimal.new(1)}}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.balance(%Address{balance: Decimal.new("1e9")}, :gwei) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: %Wei{value: Decimal.new("1e9")}}, :gwei) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: nil}, :gwei) == nil |
|
|
|
assert Chain.balance(%Address{balance: nil}, :gwei) == nil |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with Address.t with :ether" do |
|
|
|
test "with Address.t with :ether" do |
|
|
|
assert Chain.balance(%Address{balance: Decimal.new(1)}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.balance(%Address{balance: %Wei{value: Decimal.new(1)}}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.balance(%Address{balance: Decimal.new("1e18")}, :ether) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: %Wei{value: Decimal.new("1e18")}}, :ether) == Decimal.new(1) |
|
|
|
assert Chain.balance(%Address{balance: nil}, :ether) == nil |
|
|
|
assert Chain.balance(%Address{balance: nil}, :ether) == nil |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
@ -342,17 +342,17 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "fee/2" do |
|
|
|
describe "fee/2" do |
|
|
|
test "without receipt with :wei unit" do |
|
|
|
test "without receipt with :wei unit" do |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: Decimal.new(2), receipt: nil}, :wei) == |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: %Wei{value: Decimal.new(2)}, receipt: nil}, :wei) == |
|
|
|
{:maximum, Decimal.new(6)} |
|
|
|
{:maximum, Decimal.new(6)} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "without receipt with :gwei unit" do |
|
|
|
test "without receipt with :gwei unit" do |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: Decimal.new(2), receipt: nil}, :gwei) == |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: %Wei{value: Decimal.new(2)}, receipt: nil}, :gwei) == |
|
|
|
{:maximum, Decimal.new("6e-9")} |
|
|
|
{:maximum, Decimal.new("6e-9")} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "without receipt with :ether unit" do |
|
|
|
test "without receipt with :ether unit" do |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: Decimal.new(2), receipt: nil}, :ether) == |
|
|
|
assert Chain.fee(%Transaction{gas: Decimal.new(3), gas_price: %Wei{value: Decimal.new(2)}, receipt: nil}, :ether) == |
|
|
|
{:maximum, Decimal.new("6e-18")} |
|
|
|
{:maximum, Decimal.new("6e-18")} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -360,7 +360,7 @@ defmodule Explorer.ChainTest do |
|
|
|
assert Chain.fee( |
|
|
|
assert Chain.fee( |
|
|
|
%Transaction{ |
|
|
|
%Transaction{ |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas_price: Decimal.new(2), |
|
|
|
gas_price: %Wei{value: Decimal.new(2)}, |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
}, |
|
|
|
}, |
|
|
|
:wei |
|
|
|
:wei |
|
|
@ -371,7 +371,7 @@ defmodule Explorer.ChainTest do |
|
|
|
assert Chain.fee( |
|
|
|
assert Chain.fee( |
|
|
|
%Transaction{ |
|
|
|
%Transaction{ |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas_price: Decimal.new(2), |
|
|
|
gas_price: %Wei{value: Decimal.new(2)}, |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
}, |
|
|
|
}, |
|
|
|
:gwei |
|
|
|
:gwei |
|
|
@ -382,7 +382,7 @@ defmodule Explorer.ChainTest do |
|
|
|
assert Chain.fee( |
|
|
|
assert Chain.fee( |
|
|
|
%Transaction{ |
|
|
|
%Transaction{ |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas: Decimal.new(3), |
|
|
|
gas_price: Decimal.new(2), |
|
|
|
gas_price: %Wei{value: Decimal.new(2)}, |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
receipt: %Receipt{gas_used: Decimal.new(2)} |
|
|
|
}, |
|
|
|
}, |
|
|
|
:ether |
|
|
|
:ether |
|
|
@ -392,19 +392,19 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "gas_price/2" do |
|
|
|
describe "gas_price/2" do |
|
|
|
test ":wei unit" do |
|
|
|
test ":wei unit" do |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :wei) == Decimal.new(1) |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new(1)}}, :wei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test ":gwei unit" do |
|
|
|
test ":gwei unit" do |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new(1)}}, :gwei) == Decimal.new("1e-9") |
|
|
|
|
|
|
|
|
|
|
|
assert Chain.gas_price(%Transaction{gas_price: Decimal.new("1e9")}, :gwei) == Decimal.new(1) |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new("1e9")}}, :gwei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test ":ether unit" do |
|
|
|
test ":ether unit" do |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: Decimal.new(1)}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new(1)}}, :ether) == Decimal.new("1e-18") |
|
|
|
|
|
|
|
|
|
|
|
assert Chain.gas_price(%Transaction{gas_price: Decimal.new("1e18")}, :ether) == Decimal.new(1) |
|
|
|
assert Chain.gas_price(%Transaction{gas_price: %Wei{value: Decimal.new("1e18")}}, :ether) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -911,7 +911,7 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
Chain.update_balance(hash, 5) |
|
|
|
Chain.update_balance(hash, 5) |
|
|
|
|
|
|
|
|
|
|
|
expected_balance = Decimal.new(5) |
|
|
|
expected_balance = %Wei{value: Decimal.new(5)} |
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, %Address{balance: ^expected_balance}} = Chain.hash_to_address(hash) |
|
|
|
assert {:ok, %Address{balance: ^expected_balance}} = Chain.hash_to_address(hash) |
|
|
|
end |
|
|
|
end |
|
|
@ -930,7 +930,7 @@ defmodule Explorer.ChainTest do |
|
|
|
test "creates an address if one does not exist" do |
|
|
|
test "creates an address if one does not exist" do |
|
|
|
Chain.update_balance("0xtwizzlers", 88) |
|
|
|
Chain.update_balance("0xtwizzlers", 88) |
|
|
|
|
|
|
|
|
|
|
|
expected_balance = Decimal.new(88) |
|
|
|
expected_balance = %Wei{value: Decimal.new(88)} |
|
|
|
|
|
|
|
|
|
|
|
assert {:ok, %Address{balance: ^expected_balance}} = Chain.hash_to_address("0xtwizzlers") |
|
|
|
assert {:ok, %Address{balance: ^expected_balance}} = Chain.hash_to_address("0xtwizzlers") |
|
|
|
end |
|
|
|
end |
|
|
@ -938,33 +938,33 @@ defmodule Explorer.ChainTest do |
|
|
|
|
|
|
|
|
|
|
|
describe "value/2" do |
|
|
|
describe "value/2" do |
|
|
|
test "with InternalTransaction.t with :wei" do |
|
|
|
test "with InternalTransaction.t with :wei" do |
|
|
|
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :wei) == Decimal.new(1) |
|
|
|
assert Chain.value(%InternalTransaction{value: %Wei{value: Decimal.new(1)}}, :wei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with InternalTransaction.t with :gwei" do |
|
|
|
test "with InternalTransaction.t with :gwei" do |
|
|
|
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.value(%InternalTransaction{value: %Wei{value: Decimal.new(1)}}, :gwei) == Decimal.new("1e-9") |
|
|
|
|
|
|
|
|
|
|
|
assert Chain.value(%InternalTransaction{value: Decimal.new("1e9")}, :gwei) == Decimal.new(1) |
|
|
|
assert Chain.value(%InternalTransaction{value: %Wei{value: Decimal.new("1e9")}}, :gwei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with InternalTransaction.t with :ether" do |
|
|
|
test "with InternalTransaction.t with :ether" do |
|
|
|
assert Chain.value(%InternalTransaction{value: Decimal.new(1)}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.value(%InternalTransaction{value: %Wei{value: Decimal.new(1)}}, :ether) == Decimal.new("1e-18") |
|
|
|
|
|
|
|
|
|
|
|
assert Chain.value(%InternalTransaction{value: Decimal.new("1e18")}, :ether) == Decimal.new(1) |
|
|
|
assert Chain.value(%InternalTransaction{value: %Wei{value: Decimal.new("1e18")}}, :ether) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with Transaction.t with :wei" do |
|
|
|
test "with Transaction.t with :wei" do |
|
|
|
assert Chain.value(%Transaction{value: Decimal.new(1)}, :wei) == Decimal.new(1) |
|
|
|
assert Chain.value(%Transaction{value: %Wei{value: Decimal.new(1)}}, :wei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with Transaction.t with :gwei" do |
|
|
|
test "with Transaction.t with :gwei" do |
|
|
|
assert Chain.value(%Transaction{value: Decimal.new(1)}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.value(%Transaction{value: %Wei{value: Decimal.new(1)}}, :gwei) == Decimal.new("1e-9") |
|
|
|
assert Chain.value(%Transaction{value: Decimal.new("1e9")}, :gwei) == Decimal.new(1) |
|
|
|
assert Chain.value(%Transaction{value: %Wei{value: Decimal.new("1e9")}}, :gwei) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
test "with Transaction.t with :ether" do |
|
|
|
test "with Transaction.t with :ether" do |
|
|
|
assert Chain.value(%Transaction{value: Decimal.new(1)}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.value(%Transaction{value: %Wei{value: Decimal.new(1)}}, :ether) == Decimal.new("1e-18") |
|
|
|
assert Chain.value(%Transaction{value: Decimal.new("1e18")}, :ether) == Decimal.new(1) |
|
|
|
assert Chain.value(%Transaction{value: %Wei{value: Decimal.new("1e18")}}, :ether) == Decimal.new(1) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|