From 2be49c64d52779dde4fb3ac956f7453e2d24e263 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 10:12:52 -0600 Subject: [PATCH 1/7] fix: issue with base fee and impers accts --- ape_foundry/provider.py | 1 + tests/test_provider.py | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index ab68051..faa4d85 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -434,6 +434,7 @@ def build_command(self) -> List[str]: f"{self.settings.base_fee}", "--gas-price", f"{self.settings.gas_price}", + "--disable-block-gas-limit", ] if not self.settings.auto_mine: diff --git a/tests/test_provider.py b/tests/test_provider.py index e0a6413..5e0b739 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -95,7 +95,8 @@ 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_type", (0, 1, 2)) +def test_unlock_account(connected_provider, contract_a, accounts, tx_type): actual = connected_provider.unlock_account(TEST_WALLET_ADDRESS) assert actual is True @@ -108,7 +109,8 @@ 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, type=tx_type) assert not receipt_0.failed From 668d5ed16135e45a0413a8557a9c2c092779159f Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 10:20:41 -0600 Subject: [PATCH 2/7] test: another test --- tests/test_provider.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_provider.py b/tests/test_provider.py index 5e0b739..ddba17a 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -95,7 +95,7 @@ def test_snapshot_and_revert(connected_provider): assert block_1.hash == block_3.hash -@pytest.mark.parametrize("tx_type", (0, 1, 2)) +@pytest.mark.parametrize("tx_type", (None, 0, 1, 2)) def test_unlock_account(connected_provider, contract_a, accounts, tx_type): actual = connected_provider.unlock_account(TEST_WALLET_ADDRESS) assert actual is True @@ -110,7 +110,11 @@ def test_unlock_account(connected_provider, contract_a, accounts, tx_type): # Ensure can transact. # NOTE: Using type 0 to avoid needing to set a balance. acct.balance += 1_000_000_000_000_000_000 - receipt_0 = contract_a.methodWithoutArguments(sender=acct, type=tx_type) + + # Also testing the case where `type` is omitted completely. + tx_kwargs = {"type": tx_type} if tx_type is not None else {} + + receipt_0 = contract_a.methodWithoutArguments(sender=acct, **tx_kwargs) assert not receipt_0.failed From 9a3c7b3ecbb8d5677035f6f4bce9ffed48f4a06f Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 12:05:53 -0600 Subject: [PATCH 3/7] fix: undo and add more tests --- ape_foundry/provider.py | 1 - tests/test_provider.py | 18 ++++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index faa4d85..ab68051 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -434,7 +434,6 @@ def build_command(self) -> List[str]: f"{self.settings.base_fee}", "--gas-price", f"{self.settings.gas_price}", - "--disable-block-gas-limit", ] if not self.settings.auto_mine: diff --git a/tests/test_provider.py b/tests/test_provider.py index ddba17a..3a16c5a 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -95,8 +95,18 @@ def test_snapshot_and_revert(connected_provider): assert block_1.hash == block_3.hash -@pytest.mark.parametrize("tx_type", (None, 0, 1, 2)) -def test_unlock_account(connected_provider, contract_a, accounts, tx_type): +@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 @@ -110,10 +120,6 @@ def test_unlock_account(connected_provider, contract_a, accounts, tx_type): # Ensure can transact. # NOTE: Using type 0 to avoid needing to set a balance. acct.balance += 1_000_000_000_000_000_000 - - # Also testing the case where `type` is omitted completely. - tx_kwargs = {"type": tx_type} if tx_type is not None else {} - receipt_0 = contract_a.methodWithoutArguments(sender=acct, **tx_kwargs) assert not receipt_0.failed From 46535939d57805e41061d17349f3818afd99108a Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 12:14:54 -0600 Subject: [PATCH 4/7] feat: config to disable block lmt --- ape_foundry/provider.py | 8 ++++++++ tests/test_provider.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index ab68051..48c68c1 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -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. @@ -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]): diff --git a/tests/test_provider.py b/tests/test_provider.py index 3a16c5a..3f2e883 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -400,3 +400,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 From ec80edef0f3649ee4981db447e0d99fbfcac5f83 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 12:33:41 -0600 Subject: [PATCH 5/7] test: inc failing part --- tests/test_provider.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/test_provider.py b/tests/test_provider.py index 3f2e883..6531c6e 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -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 @@ -121,6 +122,12 @@ def test_unlock_account(connected_provider, contract_a, accounts, tx_kwargs): # NOTE: Using type 0 to avoid needing to set a balance. 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 @@ -268,9 +275,25 @@ 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") + + # TODO: THIS IS FAILING, THIS IS THE REPORTED BUG + acct1.transfer(acct2, "1 eth", max_priority_fee=0) + def test_auto_mine(connected_provider): assert connected_provider.auto_mine is True From 955624abdffb0f3730eabb5db48d1ffe1d9c83d6 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 12:33:44 -0600 Subject: [PATCH 6/7] test: inc failing part --- tests/test_provider.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test_provider.py b/tests/test_provider.py index 6531c6e..9ef1fda 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -96,17 +96,20 @@ def test_snapshot_and_revert(connected_provider): assert block_1.hash == block_3.hash -@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}, -]) +@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 From 077d528d5ec091a61ba0f36a6467ac871db4a2a6 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Wed, 17 Jan 2024 13:41:39 -0600 Subject: [PATCH 7/7] test: del weird part --- tests/test_provider.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_provider.py b/tests/test_provider.py index 9ef1fda..b572dfc 100644 --- a/tests/test_provider.py +++ b/tests/test_provider.py @@ -294,9 +294,6 @@ def test_base_fee(connected_provider, temp_config, networks, accounts): # Show can transact with this base_fee acct1.transfer(acct2, "1 eth") - # TODO: THIS IS FAILING, THIS IS THE REPORTED BUG - acct1.transfer(acct2, "1 eth", max_priority_fee=0) - def test_auto_mine(connected_provider): assert connected_provider.auto_mine is True