From af729f104a720d95730549aa7dd346e5eae34434 Mon Sep 17 00:00:00 2001 From: "bl@ckode" Date: Thu, 9 Jun 2022 11:16:01 +0530 Subject: [PATCH] Update tx value fee and related test cases --- lib/archethic/mining/fee.ex | 22 +------------------ test/archethic/mining/fee_test.exs | 22 +++++++++---------- .../api/transaction_controller_test.exs | 2 +- 3 files changed, 13 insertions(+), 33 deletions(-) diff --git a/lib/archethic/mining/fee.ex b/lib/archethic/mining/fee.ex index 568535fbd..ffcf5f3c6 100644 --- a/lib/archethic/mining/fee.ex +++ b/lib/archethic/mining/fee.ex @@ -14,7 +14,6 @@ defmodule Archethic.Mining.Fee do alias Archethic.TransactionChain.TransactionData.NFTLedger alias Archethic.TransactionChain.TransactionData.UCOLedger - @min_tx_fee_in_usd 0.1 @unit_uco 100_000_000 @doc """ @@ -43,7 +42,6 @@ defmodule Archethic.Mining.Fee do 0 true -> - transaction_value = 0.01 / uco_price_in_usd nb_recipients = get_number_recipients(tx) nb_bytes = get_transaction_size(tx) nb_storage_nodes = get_number_replicas(tx) @@ -51,7 +49,6 @@ defmodule Archethic.Mining.Fee do trunc( do_calculate( uco_price_in_usd, - transaction_value, nb_bytes, nb_storage_nodes, nb_recipients @@ -89,14 +86,13 @@ defmodule Archethic.Mining.Fee do defp do_calculate( uco_price_in_usd, - transaction_value, nb_bytes, nb_storage_nodes, nb_recipients ) do # TODO: determine the fee for smart contract execution - value_cost = fee_for_value(uco_price_in_usd, transaction_value) + value_cost = 0.01 / uco_price_in_usd storage_cost = fee_for_storage( @@ -110,22 +106,6 @@ defmodule Archethic.Mining.Fee do value_cost + storage_cost + replication_cost end - # if transaction value less than minimum transaction value => txn fee is minimum txn fee - defp fee_for_value(uco_price_in_usd, transaction_value_in_uco) - when transaction_value_in_uco <= @min_tx_fee_in_usd / uco_price_in_usd * 1000 do - get_min_transaction_fee(uco_price_in_usd) - end - - defp fee_for_value(uco_price_in_usd, transaction_value_in_uco) do - min_tx_fee = get_min_transaction_fee(uco_price_in_usd) - min_tx_value = min_tx_fee * 1_000 - min_tx_fee * (transaction_value_in_uco / min_tx_value) - end - - defp get_min_transaction_fee(uco_price_in_usd) do - @min_tx_fee_in_usd / uco_price_in_usd - end - defp fee_for_storage(uco_price_in_usd, nb_bytes, nb_storage_nodes) do price_per_byte = 1.0e-8 / uco_price_in_usd price_per_storage_node = price_per_byte * nb_bytes diff --git a/test/archethic/mining/fee_test.exs b/test/archethic/mining/fee_test.exs index c541e3d65..6d2a2a6c5 100644 --- a/test/archethic/mining/fee_test.exs +++ b/test/archethic/mining/fee_test.exs @@ -20,7 +20,7 @@ defmodule Archethic.Mining.FeeTest do test "should return a fee less than amount to send for a single transfer" do # 0.050048 UCO for 1 UCO at $0.2 - assert 50_048_000 = + assert 5_048_000 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -45,7 +45,7 @@ defmodule Archethic.Mining.FeeTest do test "should increase fee when the amount increases for single transfer " do # 0.050048 UCO for 1 UCO - assert 5_004_800 == + assert 5_04_800 == %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -68,7 +68,7 @@ defmodule Archethic.Mining.FeeTest do |> Fee.calculate(2.0) # 0.060048 UCO for 60 UCO - assert 6_004_800 = + assert 504_800 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -93,7 +93,7 @@ defmodule Archethic.Mining.FeeTest do test "should decrease the fee when the amount stays the same but the price of UCO increases" do # 0.050048 UCO for 1 UCO at $ 2.0 - assert 5_004_800 = + assert 504_800 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -116,7 +116,7 @@ defmodule Archethic.Mining.FeeTest do |> Fee.calculate(2.0) # 0.0100096 UCO for 1 UCO at $10.0 - assert 1_000_960 = + assert 1_00_960 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -141,7 +141,7 @@ defmodule Archethic.Mining.FeeTest do test "sending multiple transfers should cost more than sending a single big transfer" do # 1.00048 UCO for 1_000 UCO - assert 100_048_000 = + assert 5_048_000 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -164,7 +164,7 @@ defmodule Archethic.Mining.FeeTest do |> Fee.calculate(0.2) # 501.1028775.UCO for 1000 transfer of 1 UCO - assert 50_110_287_750 = + assert 50_015_287_750 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -190,7 +190,7 @@ defmodule Archethic.Mining.FeeTest do test "should increase the fee when the transaction size increases" do # 0.5 UCO to store 1KB - assert 50_287_750 = + assert 5_287_749 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -204,7 +204,7 @@ defmodule Archethic.Mining.FeeTest do |> Fee.calculate(0.2) # 25.5 UCO to store 10MB - assert 2_550_037_750 = + assert 2_505_037_750 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -220,7 +220,7 @@ defmodule Archethic.Mining.FeeTest do test "should cost more with more replication nodes" do # 50 nodes: 0.050048 UCO - assert 5_004_800 = + assert 504_800 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, @@ -245,7 +245,7 @@ defmodule Archethic.Mining.FeeTest do add_nodes(100) # 150 nodes: 0.050144 UCO - assert 5_014_400 = + assert 5_14_400 = %Transaction{ address: <<0::8, :crypto.strong_rand_bytes(32)::binary>>, type: :transfer, diff --git a/test/archethic_web/controllers/api/transaction_controller_test.exs b/test/archethic_web/controllers/api/transaction_controller_test.exs index 0945ef1f4..927758a22 100644 --- a/test/archethic_web/controllers/api/transaction_controller_test.exs +++ b/test/archethic_web/controllers/api/transaction_controller_test.exs @@ -54,7 +54,7 @@ defmodule ArchethicWeb.API.TransactionControllerTest do }) assert %{ - "fee" => 0.50001325, + "fee" => 0.05001324, "rates" => %{ "eur" => 0.2, "usd" => 0.2