From f0c8e35a74832d519fb12cf16620e766ed112a85 Mon Sep 17 00:00:00 2001 From: slush Date: Thu, 12 Sep 2024 01:27:23 -0500 Subject: [PATCH] feat: allow private transaction receipts to bail out before awaiting confirmations that won't show --- src/ape_ethereum/provider.py | 21 ++++++++++++++------- tests/functional/test_provider.py | 12 ++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/ape_ethereum/provider.py b/src/ape_ethereum/provider.py index a9f2807a81..876b912e2d 100644 --- a/src/ape_ethereum/provider.py +++ b/src/ape_ethereum/provider.py @@ -624,6 +624,19 @@ def get_receipt( ) hex_hash = HexBytes(txn_hash) + if transaction := kwargs.get("transaction"): + # perf: If called `send_transaction()`, we should already have the data! + txn = ( + transaction + if isinstance(transaction, dict) + else transaction.model_dump(by_alias=True, mode="json") + ) + + if kwargs.get("private"): + # Bail before confirmation because it won't be on chain yet. + receipt = self._create_receipt(required_confirmations=0, **txn) + return receipt.await_confirmations() # But do need to await nonce increment. + try: receipt_data = dict( self.web3.eth.wait_for_transaction_receipt(hex_hash, timeout=timeout) @@ -641,13 +654,7 @@ def get_receipt( network_config: dict = ecosystem_config.get(self.network.name, {}) max_retries = network_config.get("max_get_transaction_retries", DEFAULT_MAX_RETRIES_TX) - if transaction := kwargs.get("transaction"): - # perf: If called `send_transaction()`, we should already have the data! - txn = ( - transaction - if isinstance(transaction, dict) - else transaction.model_dump(by_alias=True, mode="json") - ) + if transaction: if "effectiveGasPrice" in receipt_data: receipt_data["gasPrice"] = receipt_data["effectiveGasPrice"] diff --git a/tests/functional/test_provider.py b/tests/functional/test_provider.py index e30ae84bbd..70e84785d3 100644 --- a/tests/functional/test_provider.py +++ b/tests/functional/test_provider.py @@ -128,6 +128,18 @@ def test_get_receipt_exists_with_timeout(eth_tester_provider, vyper_contract_ins assert receipt_from_provider.receiver == vyper_contract_instance.address +def test_get_receipt_for_private_bypasses_confirmations( + eth_tester_provider, vyper_contract_instance, owner +): + receipt_from_invoke = vyper_contract_instance.setNumber(888, sender=owner) + receipt_from_provider = eth_tester_provider.get_receipt( + receipt_from_invoke.txn_hash, timeout=0, private=True + ) + assert receipt_from_provider.txn_hash == receipt_from_invoke.txn_hash + assert receipt_from_provider.receiver == vyper_contract_instance.address + assert not receipt_from_provider.confirmed + + def test_get_contracts_logs_all_logs(chain, contract_instance, owner, eth_tester_provider): start_block = chain.blocks.height stop_block = start_block + 100