diff --git a/brownie/network/account.py b/brownie/network/account.py index dc42336ad..c08d6df87 100644 --- a/brownie/network/account.py +++ b/brownie/network/account.py @@ -362,7 +362,7 @@ def _gas_limit( if isinstance(gas_limit, bool) or gas_limit in (None, "auto"): gas_buffer = gas_buffer or CONFIG.active_network["settings"]["gas_buffer"] gas_limit = self.estimate_gas(to, amount, gas_price, data or "") - if gas_buffer != 1: + if gas_limit > 21000 and gas_buffer != 1: gas_limit = Wei(gas_limit * gas_buffer) return min(gas_limit, Chain().block_gas_limit) diff --git a/tests/network/account/test_account_transfer.py b/tests/network/account/test_account_transfer.py index 7a939423c..c0e0ca980 100644 --- a/tests/network/account/test_account_transfer.py +++ b/tests/network/account/test_account_transfer.py @@ -2,10 +2,17 @@ import pytest -# from brownie import network, accounts, config, web3 +from brownie import compile_source from brownie.exceptions import VirtualMachineError from brownie.network.transaction import TransactionReceipt +code = """ +pragma solidity ^0.6.0; +contract Foo { + fallback () external payable {} +} +""" + def test_to_string(accounts): """Can send to a string""" @@ -140,11 +147,18 @@ def test_gas_limit_manual(accounts): def test_gas_buffer_manual(accounts, config): + """gas limit is set correctly when specified in the call""" + config.active_network["settings"]["gas_limit"] = None + foo = compile_source(code).Foo.deploy({"from": accounts[0]}) + tx = accounts[0].transfer(foo, 1000, gas_buffer=1.337) + assert int(tx.gas_used * 1.337) == tx.gas_limit + + +def test_gas_buffer_send_to_eoa(accounts, config): """gas limit is set correctly when specified in the call""" config.active_network["settings"]["gas_limit"] = None tx = accounts[0].transfer(accounts[1], 1000, gas_buffer=1.337) - assert tx.gas_limit == int(21000 * 1.337) - assert tx.gas_used == 21000 + assert tx.gas_limit == 21000 @pytest.mark.parametrize("gas_limit", (True, False, None, "auto")) @@ -153,8 +167,9 @@ def test_gas_limit_automatic(accounts, config, gas_limit, gas_buffer): """gas limit is set correctly using web3.eth.estimateGas""" config.active_network["settings"]["gas_limit"] = gas_limit config.active_network["settings"]["gas_buffer"] = gas_buffer - tx = accounts[0].transfer(accounts[1], 1000) - assert tx.gas_limit == int(21000 * gas_buffer) + foo = compile_source(code).Foo.deploy({"from": accounts[0]}) + tx = accounts[0].transfer(foo, 1000) + assert int(tx.gas_used * gas_buffer) == tx.gas_limit def test_gas_limit_config(accounts, config):