Skip to content

Commit

Permalink
Merge pull request #798 from eth-brownie/fix-gas-buffer-eoa
Browse files Browse the repository at this point in the history
Do not apply gas buffer to transactions where the receiver is an EOA
  • Loading branch information
iamdefinitelyahuman authored Oct 7, 2020
2 parents 212332c + 60af33b commit e46c395
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion brownie/network/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
25 changes: 20 additions & 5 deletions tests/network/account/test_account_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"))
Expand All @@ -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):
Expand Down

0 comments on commit e46c395

Please sign in to comment.