Skip to content

Commit

Permalink
Convert transaction_fee to decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
koutst committed Dec 19, 2024
1 parent 4fc44dc commit 1c3b621
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/reputation/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import decimal
import re
import time
from datetime import datetime, timedelta
Expand All @@ -10,10 +10,9 @@
from pytz import utc
from rest_framework.test import APITestCase

from purchase.models import RscExchangeRate
from reputation.distributions import Distribution as Dist
from reputation.distributor import Distributor
from reputation.lib import PendingWithdrawal, gwei_to_eth
from reputation.lib import PendingWithdrawal
from reputation.models import Withdrawal
from reputation.tests.helpers import create_deposit, create_withdrawals
from reputation.views.withdrawal_view import WithdrawalViewSet
Expand Down Expand Up @@ -45,6 +44,10 @@ def setUp(self):
etherscan_matcher = re.compile("https://api.etherscan.io/.*")
self.mocker.get(etherscan_matcher, json={"result": {"SafeGasPrice": "30"}})

# Mock calls to basescan
basescan_matcher = re.compile("https://api.basescan.org/.*")
self.mocker.get(basescan_matcher, json={"result": "0x38a5ef"})

# Mock calls to coingecko
coingecko_matcher = re.compile("https://api.coingecko.com/.*")
self.mocker.get(
Expand Down Expand Up @@ -220,7 +223,6 @@ def test_verified_user_can_rewithdraw_rsc_after_24_hours(self):
"transaction_fee": 15,
},
)

self.assertEqual(response.status_code, 201)

def test_unverified_user_cannot_rewithdraw_rsc_within_14_days(self):
Expand Down Expand Up @@ -665,12 +667,7 @@ def test_base_network_transaction_fee_is_lower(self):
# Base fee should be lower than Ethereum fee
self.assertLess(base_fee, eth_fee)

# Base fee should be reasonable (using 1 gwei gas price)
expected_base_gas_fee = gwei_to_eth(1 * 100000) # 1 gwei * 100000 gas
expected_base_rsc = int(
round(RscExchangeRate.eth_to_rsc(expected_base_gas_fee))
)
self.assertEqual(base_fee, expected_base_rsc)
self.assertEqual(base_fee, decimal.Decimal("0.004454994"))

"""
Helper methods
Expand Down
3 changes: 1 addition & 2 deletions src/reputation/views/withdrawal_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from utils.permissions import CreateOrReadOnly, CreateOrUpdateIfAllowed, UserNotSpammer
from utils.throttles import THROTTLE_CLASSES

TRANSACTION_FEE = int(os.environ.get("TRANSACTION_FEE", 100))
NETWORKS = {
"ETHEREUM": {
"provider_url": WEB3_PROVIDER_URL,
Expand Down Expand Up @@ -232,7 +231,7 @@ def calculate_transaction_fee(self, network="ETHEREUM"):

gas_fee_in_eth = gwei_to_eth(float(gas_price) * gas_limit)
rsc = RscExchangeRate.eth_to_rsc(gas_fee_in_eth)
return rsc
return decimal.Decimal(str(rsc))

# 5 minute cache
@method_decorator(cache_page(60 * 5))
Expand Down

0 comments on commit 1c3b621

Please sign in to comment.