From f2068375f9e56efeda3b523f97d83e956a642656 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Mon, 5 Oct 2020 18:09:25 +0300 Subject: [PATCH 1/2] fix: don't apply gas buffer when sending to EOA --- brownie/network/account.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 60af33b954e1d6919255e16fe765e7b348b1e427 Mon Sep 17 00:00:00 2001 From: Ben Hauser Date: Wed, 7 Oct 2020 15:10:08 +0300 Subject: [PATCH 2/2] test: update/expand tests for gas buffer --- .../network/account/test_account_transfer.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) 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):