Added doctest and removed unnecessary test
MODIFY
apps/omg/lib/omg/fees.ex
apps/omg/lib/omg/fees.ex
@@ -28,8 +28,14 @@ defmodule OMG.Fees do
@type fee_spec_t() :: %{token: Transaction.Payment.currency(), flat_fee: non_neg_integer}
@type fee_t() :: %{Transaction.Payment.currency() => non_neg_integer} | :no_fees_transaction
- @doc """
+ @doc ~S"""
Checks whether the transaction's inputs cover the fees.
+
+ ## Examples
+
+ iex> Fees.covered?(%{"eth" => 2}, %{"eth" => 1, "omg" => 3})
+ true
+
"""
@spec covered?(implicit_paid_fee_by_currency :: map(), fees :: fee_t()) :: boolean()
def covered?(_, :no_fees_transaction), do: true
@@ -44,9 +50,15 @@ defmodule OMG.Fees do
|> Enum.any?()
end
- @doc """
+ @doc ~S"""
Returns the fees to pay for a particular transaction,
and under particular fee specs listed in `fee_map`.
+
+ ## Examples
+
+ iex> OMG.Fees.for_transaction(%OMG.State.Transaction.Recovered{}, %{"eth" => 1, "omg" => 3})
+ %{"eth" => 1, "omg" => 3}
+
"""
@spec for_transaction(Transaction.Recovered.t(), fee_t()) :: fee_t()
def for_transaction(transaction, fee_map) do

MODIFY
apps/omg/test/omg/fees_test.exs
apps/omg/test/omg/fees_test.exs
@@ -23,6 +23,8 @@ defmodule OMG.FeesTest do
alias OMG.Fees
+ doctest OMG.Fees
+
@eth OMG.Eth.RootChain.eth_pseudo_address()
@not_eth <<1::size(160)>>
@@ -36,10 +38,6 @@ defmodule OMG.FeesTest do
assert Fees.covered?(%{@eth => 0}, :no_fees_transaction)
end
- test "returns true when fees are covered by eth" do
- assert Fees.covered?(%{@eth => 2}, @fees)
- end
-
test "returns true when fees are covered by another currency" do
assert Fees.covered?(%{@not_eth => 5}, @fees)
end
@@ -73,13 +71,13 @@ defmodule OMG.FeesTest do
describe "for_transaction/2" do
@tag fixtures: [:alice, :bob]
- test "returns the fee map when not a merge transaction (different addresses)", %{alice: alice, bob: bob} do
+ test "returns the fee map when not a merge transaction", %{alice: alice, bob: bob} do
transaction = create_recovered([{1, 0, 0, alice}], @eth, [{bob, 6}, {alice, 3}])
assert Fees.for_transaction(transaction, @fees) == @fees
end
@tag fixtures: [:alice]
- test "returns :no_fees_transaction for merge transactions with single currency (eth) and same in/out address (free)",
+ test "returns :no_fees_transaction for merge transactions",
%{alice: alice} do
transaction = create_recovered([{1, 0, 0, alice}, {2, 0, 0, alice}], @eth, [{alice, 10}])
assert Fees.for_transaction(transaction, @fees) == :no_fees_transaction
@@ -96,23 +94,5 @@ defmodule OMG.FeesTest do
assert Fees.for_transaction(transaction, @fees) == :no_fees_transaction
end
-
- @tag fixtures: [:alice]
- test "returns :no_fees_transaction for merge transactions with single currency (not eth) and same in/out address (free)",
- %{alice: alice} do
- transaction = create_recovered([{1, 0, 0, alice}, {2, 0, 0, alice}], @not_eth, [{alice, 10}])
- assert Fees.for_transaction(transaction, @fees) == :no_fees_transaction
- end
-
- @tag fixtures: [:alice]
- test "returns fees for merge transactions when not single currency", %{alice: alice} do
- transaction =
- create_recovered(
- [{1, 0, 0, alice}, {1, 0, 1, alice}, {2, 0, 0, alice}, {2, 1, 0, alice}],
- [{alice, @eth, 10}, {alice, @not_eth, 10}]
- )
-
- assert Fees.for_transaction(transaction, @fees) == @fees
- end
end
end

Added doctest and removed unnecessary test