From 8927b4a686887f44fe2cd9de777e2c827c948987 Mon Sep 17 00:00:00 2001 From: Peerchemist Date: Fri, 12 Apr 2019 12:00:40 +0200 Subject: [PATCH] implement new style transaction fee calculation --- pypeerassets/transactions.py | 10 ++++++++-- test/test_transactions.py | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pypeerassets/transactions.py b/pypeerassets/transactions.py index b4ba777..042aa28 100644 --- a/pypeerassets/transactions.py +++ b/pypeerassets/transactions.py @@ -214,9 +214,15 @@ def get_next_tx(self, mutable=False): def calculate_tx_fee(tx_size: int) -> Decimal: '''return tx fee from tx size in bytes''' - min_fee = Decimal(0.01) # minimum + per_kb_cost = 0.01 + min_fee = Decimal(0.001) - return Decimal(ceil(tx_size / 1000) * min_fee) + fee = Decimal((tx_size / 1000) * per_kb_cost) + + if fee <= min_fee: + return min_fee + else: + return fee def nulldata_script(data: bytes) -> NulldataScript: diff --git a/test/test_transactions.py b/test/test_transactions.py index 9fb8193..3869aef 100644 --- a/test/test_transactions.py +++ b/test/test_transactions.py @@ -73,7 +73,12 @@ def test_peercoin_tx_unhexilify(): @pytest.mark.parametrize("tx_size", [181, 311]) def test_calculate_transaction_fee(tx_size): - assert round(calculate_tx_fee(tx_size), 2) == round(Decimal(0.01), 2) + if tx_size == 181: + assert calculate_tx_fee(tx_size) == Decimal(0.00181) + if tx_size == 311: + assert calculate_tx_fee(tx_size) == Decimal(0.00311) + if tx_size == 3903: + assert calculate_tx_fee(tx_size) == Decimal(0.03903) @pytest.mark.parametrize("network", ['peercoin'])