diff --git a/golem/ethereum/transactionsystem.py b/golem/ethereum/transactionsystem.py index a6d62d255d..08414a302d 100644 --- a/golem/ethereum/transactionsystem.py +++ b/golem/ethereum/transactionsystem.py @@ -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, diff --git a/tests/golem/ethereum/test_transactionsystem.py b/tests/golem/ethereum/test_transactionsystem.py index dd3af138ee..d73ffae6a5 100644 --- a/tests/golem/ethereum/test_transactionsystem.py +++ b/tests/golem/ethereum/test_transactionsystem.py @@ -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() @@ -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()