Skip to content

Commit

Permalink
test: update/expand tests for gas buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Oct 7, 2020
1 parent f206837 commit 60af33b
Showing 1 changed file with 20 additions and 5 deletions.
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 60af33b

Please sign in to comment.