-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ape-compiled Contracts not being recognized in test suite #2262
Comments
Additional note: It looks like ape has trouble even identifying previously-identified contracts in test functions. Trace from an error where the contract was identified, but still throws 'contract may need verification' error in tests: E ape.exceptions.ContractNotFoundError: Failed to get contract type for address '0x5C3A8b...'. Contract may need verification. contract is properly identified when exported from conftest.py function: <Identified Contract 0x5C3A8b...> Contract was also deployed via ape. ape shouldn't require verification for contracts that were compiled within Ape -- whether they are deployed by ape (as in this case) or via a contract. contract types and ABIs should be properly exported from when fixtures are set up to deploy and export contract types and ABIs. |
I wonder if isolation has to do with it? (edit: because Ape's contract caching system doesn't care if you are using |
I am attempting to reproduce here: antazoey/ape-playground#5 |
I was able to successfully run the tests with --disable-isolation. However, there are some tests that need to run in isolation, as they change state. I'm using chain.snapshot() and chain.restore() to run tests in isolation given the flag. |
are you sending transactions within your |
Hmm, this doesn't ring true to me. Scoping does work, except when using parametrized fixtures. |
I see the test you've set up here. Thanks for this. I see that you're doing a contract deployment (via a factory contract), and the export is working. Is there a way for you to test this with a different pattern, similar to what i'm using? here it is: -set up a dummy contract (deployer) contractB = project.ContractB.at(contractBAddress) return contracts through the conftest.py function and then run a test using those contracts. |
i tried this with scope="session" and scope="module". both fail when --disable-isolation flag is not provided. |
@davoice-321 I made the updates! But I haven't hit the problem yet. |
Do you happen to have to minimal repro for us? |
hi. i don't have a minimal repo unfortunately. I've been able to overcome the issue by running tests with --disable-isolation |
Environment information
ape
and plugin versions:ape-config.yaml
(NOTE: do not post anything private like RPC urls or secrets!):What went wrong?
ABI and type of contract-deployed contracts are not being read during testing
Situation
-I'm using conftest.py to set up a deployment for a series of contracts.
2 of the contracts are deployed using owner.deploy()
2 of the contracts are deployed through a contract that was compiled using Ape
Using the contract-deployed contracts works in the following instances:
When the contracts are deployed and used in a script (ape run)
When the contracts are deployed and used in a conftest.py function (i'm assuming because running this function is like running a script)
The contracts are being outputted from the conftest.py function. Expected behavior is that the ABI and type of contract-deployed contracts are read properly during testing.
Here is the output from the conftest.py function re: the contracts (printing the contracts in the test function).
<Identified Contract1 0x68b9...>, <Unnamed contract 0xe94b0...>, <Unnamed contract 0xCcd7A...>, <Identified Contract2 0x539a46F...>)
Both unnamed contracts were compiled with Ape and should be identifiable.
Unnamed contracts are being identified within conftest.py by directly referencing the ABI. In addition, one of the unnamed contracts is calling an initialization function within the conftest.py function. That function runs without error indicating that the ABI is successfully being referenced properly in the context of the conftest.py function.
How contracts are being identified.
token_abi_path = os.environ["token_abi_path"]
contract_1= Contract(address, abi=token_abi_path)
contract_abi = project.Contract.contract_type.abi
contract_2 = Contract(address_2, abi=contract_abi)
Note that the contract addresses for the contract-deployed contracts are being emitted via events. which is how they are being captured to link the address to the ABI:
deployment_events = contract1.decode_logs()
contract_1_address = deployment_events[-1]._Token
contract_2_address = deployment_events[2].contractAddress
I tried this using a tenderly fork and a mainnet-fork
Error trace from Tenderly Fork
self = <Node (Tenderly/v1.0.0) chain_id=1337>, rpc = 'debug_setHead', parameters = ['0x13a5715']
E ape.exceptions.ProviderError: method not found
../venv/lib/python3.11/site-packages/ape_ethereum/provider.py:1130: ProviderError
Error trace from mainnet fork
FAILED tests/test.py::test_1 - ape.exceptions.ContractNotFoundError: Failed to get contract type for address '0xe2f7b5...'. Contract may need verification.
How can it be fixed?
Ensure ABIs and types for contract-deployed contracts used in scripts and conftest.py functions are exported properly in testing.
The text was updated successfully, but these errors were encountered: