Skip to content

Commit

Permalink
fix: unable to send transactions during manual mining in other provid…
Browse files Browse the repository at this point in the history
…ers (#2447)
  • Loading branch information
antazoey authored Dec 24, 2024
1 parent 587fc48 commit dd326c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 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.FAILING if vm_err else TransactionStatusEnum.NO_ERROR,
txn_hash=txn_hash,
**txn_data,
)
Expand Down
4 changes: 3 additions & 1 deletion src/ape_test/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ def send_transaction(self, txn: "TransactionAPI") -> "ReceiptAPI":
"error": vm_err,
"provider": self,
"required_confirmations": required_confirmations,
"status": TransactionStatusEnum.NO_ERROR,
"status": (
TransactionStatusEnum.FAILING if vm_err else TransactionStatusEnum.NO_ERROR
),
"txn_hash": txn_hash,
}
receipt = self.network.ecosystem.decode_receipt(receipt_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 dd326c2

Please sign in to comment.