Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
don't withdraw small amounts with bigger gas price
Browse files Browse the repository at this point in the history
fixes #4773
  • Loading branch information
etam committed Oct 21, 2019
1 parent ce07f67 commit 0de17f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions golem/ethereum/transactionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ def withdraw(
if not is_address(destination):
raise ValueError("{} is not valid ETH address".format(destination))

if gas_price and amount < gas_price:
raise Exception("Gas price is higer than amount")

log.info(
"Trying to withdraw %f %s to %s",
amount / denoms.ether,
Expand Down
17 changes: 16 additions & 1 deletion tests/golem/ethereum/test_transactionsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,15 @@ def setUp(self):

self.eth_tx = f'0x{"e"*64}'
self.gntb_tx = f'0x{"f"*64}'
self.sci.transfer_eth.return_value = self.eth_tx

def transfer_eth(
to_address: str,
amount: int,
gas_price: Optional[int] = None) -> str:
assert amount > 0
return self.eth_tx

self.sci.transfer_eth.side_effect = transfer_eth
self.sci.convert_gntb_to_gnt.return_value = self.gntb_tx

self.ets._refresh_balances()
Expand Down Expand Up @@ -454,6 +462,13 @@ def test_custom_gas_price_eth(self):
gas_price,
)

def test_gas_price_higher_than_amount(self):
amount = denoms.ether
gas_price = amount+1
with self.assertRaisesRegex(Exception,
"Gas price is higer than amount"):
self.ets.withdraw(amount, self.dest, 'ETH', gas_price)

def test_eth_with_lock(self):
self.ets.lock_funds_for_payments(1, 1)
locked_eth = self.ets.get_locked_eth()
Expand Down

0 comments on commit 0de17f5

Please # to comment.