Closed 0xkorin closed 1 year ago
So I figured out what is happening here. I apologize, it is a bit confusing! I would like to improve this.
Your default network is a local hardhat node, as configured in your config.
When ape test
first starts up, it spins up a local hardhat node.
You have NOT specified a different port for your mainnet-fork versus your local. If you plan on running multiple nodes like this, you need to tell it different ports or else it will think it is connecting to an already-running existing node.
And that is exactly what is happening: mainnet-fork hardhat connects to the local hardhat thinking it is mainnet fork when it is not, it never did the fork...
To fix for your project, you can configure hardhat to use a different port for mainnet fork. The updated config that works is like this:
hardhat:
host: auto
^ now the port used by the local hardhat will differ from the port used by the forked-network hardhat.
I am going to think about if there is anything else we can do before closing this.
I think the problem is in ape-hardhat and other similar providers.
We need to ensure we are connecting to a fork.
I will fix the issue there will a good message showing how to use auto
and then can close this
I suppose another thing we need to do in ape-hardhat is allow setting a hosts (ports) per network individually, instead of using auto, in the case you need these to be consistent.
Environment information
ape
and plugin versions:ape-config.yaml
(NOTE: do not post anything private like RPC urls or secrets!):What went wrong?
When running a test in a forked mainnet using the
use_network
pytest mark, ape seems to think that no contract is deployed at the address. As a consequence, both these tests below fail. However, if we remove the marks and instead runape test --network ethereum:mainnet-fork
, both tests pass. I have tried multiple addresses of contracts that are deployed on the actual mainnet, and none of them pass the test.The second tests fails with
ape.exceptions.ContractError: Unable to make contract call. '0xB9fC157394Af804a3578134A6585C0dc9cc990d4' is not a contract on network 'mainnet-fork'.
This is the output of
print(networks.provider)
: