Skip to content

Commit

Permalink
fix: handle manual mining in base eth provider
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 24, 2024
1 parent 587fc48 commit e09a191
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/ape_ethereum/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,12 +1051,13 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
# Signature is excluded from the model fields, so we have to include it manually.
txn_data["signature"] = txn.signature

if vm_err:
manual_mining = not getattr(self, "auto_mine", True)
if vm_err or manual_mining:
receipt = self._create_receipt(
block_number=-1, # Not in a block.
error=vm_err,
required_confirmations=required_confirmations,
status=TransactionStatusEnum.FAILING,
status=TransactionStatusEnum.NO_ERROR,
txn_hash=txn_hash,
**txn_data,
)
Expand Down
20 changes: 19 additions & 1 deletion tests/functional/geth/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,27 @@ def test_start_from_ws_uri(process_factory_patch, project, geth_provider, key):


@geth_process_test
def test_auto_mine(geth_provider):
def test_auto_mine(geth_provider, geth_account, geth_contract):
assert geth_provider.auto_mine is True

class MyEthereumTestProvider(EthereumNodeProvider):
"""
Simulates a provider like ape-foundry w/ auto-mine disabled.
"""

@property
def auto_mine(self) -> bool:
return False

provider = MyEthereumTestProvider(network=geth_provider.network)
provider._web3 = geth_provider.web3 # Borrow connection.

tx = geth_contract.setNumber.as_transaction(123)
tx = geth_account.prepare_transaction(tx)
tx = geth_account.sign_transaction(tx)
receipt = provider.send_transaction(tx)
assert not receipt.confirmed


@geth_process_test
def test_geth_dev_from_uri_http(data_folder):
Expand Down

0 comments on commit e09a191

Please sign in to comment.