@@ -504,6 +504,7 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
504504 if sender :
505505 sender = self .conversion_manager .convert (txn .sender , AddressType )
506506
507+ vm_err = None
507508 if sender and sender in self .unlocked_accounts :
508509 # Allow for an unsigned transaction
509510 txn = self .prepare_transaction (txn )
@@ -526,7 +527,7 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
526527 if "nonce too low" in str (vm_err ):
527528 # Add additional nonce information
528529 new_err_msg = f"Nonce '{ txn .nonce } ' is too low"
529- raise VirtualMachineError (
530+ vm_err = VirtualMachineError (
530531 new_err_msg ,
531532 base_err = vm_err .base_err ,
532533 code = vm_err .code ,
@@ -536,7 +537,9 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
536537 contract_address = vm_err .contract_address ,
537538 )
538539
539- raise vm_err from err
540+ txn_hash = txn .txn_hash
541+ if txn .raise_on_revert :
542+ raise vm_err from err
540543
541544 receipt = self .get_receipt (
542545 txn_hash .hex (),
@@ -546,6 +549,8 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
546549 else self .network .required_confirmations
547550 ),
548551 )
552+ if vm_err :
553+ receipt .error = vm_err
549554
550555 if receipt .failed :
551556 txn_dict = receipt .transaction .model_dump (mode = "json" , by_alias = True )
@@ -563,11 +568,14 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
563568 self .web3 .eth .call (txn_params )
564569 except Exception as err :
565570 vm_err = self .get_virtual_machine_error (err , txn = receipt )
566- raise vm_err from err
571+ receipt .error = vm_err
572+ if txn .raise_on_revert :
573+ raise vm_err from err
567574
568- # If we get here, for some reason the tx-replay did not produce
569- # a VM error.
570- receipt .raise_for_status ()
575+ if txn .raise_on_revert :
576+ # If we get here, for some reason the tx-replay did not produce
577+ # a VM error.
578+ receipt .raise_for_status ()
571579
572580 self .chain_manager .history .append (receipt )
573581 return receipt
@@ -709,15 +717,15 @@ def set_storage(self, address: AddressType, slot: int, value: HexBytes):
709717 ],
710718 )
711719
712- def _eth_call (self , arguments : list ) -> HexBytes :
720+ def _eth_call (self , arguments : list , raise_on_revert : bool = True ) -> HexBytes :
713721 # Overridden to handle unique Foundry pickiness.
714722 txn_dict = copy (arguments [0 ])
715723 if isinstance (txn_dict .get ("type" ), int ):
716724 txn_dict ["type" ] = HexBytes (txn_dict ["type" ]).hex ()
717725
718726 txn_dict .pop ("chainId" , None )
719727 arguments [0 ] = txn_dict
720- return super ()._eth_call (arguments )
728+ return super ()._eth_call (arguments , raise_on_revert = raise_on_revert )
721729
722730
723731class FoundryForkProvider (FoundryProvider ):
0 commit comments