Skip to content

Commit

Permalink
feat: allow configuring disable_block_gas_limit (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jan 17, 2024
1 parent a62550b commit 3df33c1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class FoundryNetworkConfig(PluginConfig):
# Mapping of ecosystem_name => network_name => FoundryForkConfig
fork: Dict[str, Dict[str, FoundryForkConfig]] = {}

"""
Disable the ``call.gas_limit <= block.gas_limit`` constraint.
"""
disable_block_gas_limit: bool = False

auto_mine: bool = True
"""
Automatically mine blocks instead of manually doing so.
Expand Down Expand Up @@ -442,6 +447,9 @@ def build_command(self) -> List[str]:
if self.settings.block_time is not None:
cmd.extend(("--block-time", f"{self.settings.block_time}"))

if self.settings.disable_block_gas_limit:
cmd.append("--disable-block-gas-limit")

return cmd

def set_balance(self, account: AddressType, amount: Union[int, float, str, bytes]):
Expand Down
53 changes: 50 additions & 3 deletions tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from ape.api.accounts import ImpersonatedAccount
from ape.contracts import ContractContainer
from ape.exceptions import ContractLogicError, TransactionError
from ape.types import CallTreeNode, TraceFrame
from ape_ethereum.transactions import TransactionStatusEnum, TransactionType
Expand Down Expand Up @@ -95,7 +96,21 @@ def test_snapshot_and_revert(connected_provider):
assert block_1.hash == block_3.hash


def test_unlock_account(connected_provider, contract_a, accounts):
@pytest.mark.parametrize(
"tx_kwargs",
[
{}, # NO KWARGS CASE: Should default to type 2
{"type": 0},
{"type": 0, "gas_price": 0},
# TODO: Uncomment after ape 0.7.5 is released
# {"type": 1},
# {"type": 1, "gas_price": 0},
{"type": 2},
{"type": 2, "max_priority_fee": 0},
{"type": 2, "base_fee": 0, "max_priority_fee": 0},
],
)
def test_unlock_account(connected_provider, contract_a, accounts, tx_kwargs):
actual = connected_provider.unlock_account(TEST_WALLET_ADDRESS)
assert actual is True

Expand All @@ -108,7 +123,14 @@ def test_unlock_account(connected_provider, contract_a, accounts):

# Ensure can transact.
# NOTE: Using type 0 to avoid needing to set a balance.
receipt_0 = contract_a.methodWithoutArguments(sender=acct, type=0)
acct.balance += 1_000_000_000_000_000_000
receipt_0 = contract_a.methodWithoutArguments(sender=acct, **tx_kwargs)

# Ensure we can deploy.
container = ContractContainer(contract_a.contract_type)
new_contract = container.deploy(acct, acct, sender=acct)
assert new_contract.address != contract_a.address

assert not receipt_0.failed


Expand Down Expand Up @@ -256,9 +278,22 @@ def test_host(temp_config, local_network, host):
assert provider.uri == "https://example.com"


def test_base_fee(connected_provider):
def test_base_fee(connected_provider, temp_config, networks, accounts):
assert connected_provider.base_fee == 0

acct1 = accounts[-1]
acct2 = accounts[-2]

# Show we can se the base-fee.
new_base_fee = 1_000_000
data = {"foundry": {"base_fee": new_base_fee, "host": "http://127.0.0.1:8555"}}
with temp_config(data):
with networks.ethereum.local.use_provider("foundry") as provider:
assert provider.base_fee == new_base_fee

# Show can transact with this base_fee
acct1.transfer(acct2, "1 eth")


def test_auto_mine(connected_provider):
assert connected_provider.auto_mine is True
Expand Down Expand Up @@ -388,3 +423,15 @@ def test_prepare_tx_with_max_gas(tx_type, connected_provider, ethereum, owner):
# NOTE: The local network by default uses max_gas.
actual = connected_provider.prepare_transaction(tx)
assert actual.gas_limit == connected_provider.max_gas


def test_disable_block_gas_limit(temp_config, disconnected_provider):
# Ensure it is disabled by default.
cmd = disconnected_provider.build_command()
assert "--disable-block-gas-limit" not in cmd

# Show we can enable it.
data = {"foundry": {"disable_block_gas_limit": True}}
with temp_config(data):
cmd = disconnected_provider.build_command()
assert "--disable-block-gas-limit" in cmd

0 comments on commit 3df33c1

Please sign in to comment.