Skip to content

Commit

Permalink
fix: missing err
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 19, 2023
1 parent 492b76d commit fe47bd3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ def send_transaction(self, txn: TransactionAPI) -> ReceiptAPI:
vm_err = self.get_virtual_machine_error(err, txn=receipt)
raise vm_err from err

# If we get here, for some reason the tx-replay did not produce
# a VM error.
receipt.raise_for_status()

logger.info(f"Confirmed {receipt.txn_hash} (total fees paid = {receipt.total_fees_paid})")
self.chain_manager.history.append(receipt)
return receipt
Expand Down
15 changes: 15 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,31 @@ def contract_type(request, get_contract_type) -> ContractType:
return get_contract_type(name)


@pytest.fixture
def vyper_contract_type(get_contract_type) -> ContractType:
return get_contract_type("vyper_contract")


@pytest.fixture
def contract_container(contract_type) -> ContractContainer:
return ContractContainer(contract_type=contract_type)


@pytest.fixture
def vyper_contract_container(vyper_contract_type) -> ContractContainer:
return ContractContainer(contract_type=vyper_contract_type)


@pytest.fixture
def contract_instance(owner, contract_container, connected_provider):
return owner.deploy(contract_container)


@pytest.fixture
def vyper_contract_instance(owner, vyper_contract_container, connected_provider):
return owner.deploy(vyper_contract_container)


@pytest.fixture
def error_contract_container(get_contract_type):
ct = get_contract_type("has_error")
Expand Down
47 changes: 46 additions & 1 deletion tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import pytest
from ape.api.accounts import ImpersonatedAccount
from ape.exceptions import ContractLogicError
from ape.exceptions import ContractLogicError, TransactionError
from ape.types import CallTreeNode, TraceFrame
from ape_ethereum.transactions import TransactionStatusEnum
from eth_pydantic_types import HashBytes32
from eth_utils import to_int
from evm_trace import CallType
from hexbytes import HexBytes
Expand Down Expand Up @@ -313,3 +315,46 @@ def test_remote_host_using_env_var(temp_config, networks, no_anvil_bin):
del os.environ["APE_FOUNDRY_HOST"]
else:
os.environ["APE_FOUNDRY_HOST"] = original


def test_send_transaction_when_no_error_and_receipt_fails(
mocker, connected_provider, owner, vyper_contract_instance
):
mock_web3 = mocker.MagicMock()
mock_transaction = mocker.MagicMock()
mock_transaction.required_confirmations = 0
mock_transaction.sender = owner.address

start_web3 = connected_provider._web3
connected_provider._web3 = mock_web3

try:
# NOTE: Value is meaningless.
tx_hash = HashBytes32.__eth_pydantic_validate__(123**36)

# Sending tx "works" meaning no vm error.
mock_web3.eth.send_raw_transaction.return_value = tx_hash

# Getting a receipt "works", but you get a failed one.
receipt_data = {
"failed": True,
"blockNumber": 0,
"txnHash": tx_hash.hex(),
"status": TransactionStatusEnum.FAILING.value,
"sender": owner.address,
"receiver": vyper_contract_instance.address,
"input": b"",
"gasUsed": 123,
"gasLimit": 100,
}
mock_web3.eth.wait_for_transaction_receipt.return_value = receipt_data

# Attempting to replay the tx does not produce any error.
mock_web3.eth.call.return_value = HexBytes("")

# Execute test.
with pytest.raises(TransactionError):
connected_provider.send_transaction(mock_transaction)

finally:
connected_provider._web3 = start_web3

0 comments on commit fe47bd3

Please sign in to comment.