Skip to content

If hardhat forks takes longer than expected to start, ape crashes #111

Description

@sajal

Environment information

  • ape and plugin versions:
$ ape --version
0.5.5.dev9+gec67e5a8

$ ape plugins list
Installed Plugins:
  hardhat     0.5.2
  vyper       0.5.1
  alchemy     0.5.2
  polygon     0.5.1a1
  • Python Version: 3.10.4
  • OS: linux : Linux sajal-thinkpad 5.15.0-39-generic #42-Ubuntu SMP Thu Jun 9 23:42:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What went wrong?

When using hardhat in forking mode (eth mainnet) with following config

hardhat:
  fork:
    ethereum:
      mainnet:
        upstream_provider: alchemy
        block_number: 15936703
  fork_request_timeout: 1200

and following test case

import ape

import pytest

def test_vitalik_balance():
    assert ape.api.address.Address("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045").balance == 739992029493125111147

with following command WEB3_ETHEREUM_MAINNET_ALCHEMY_API_KEY="REMOVED" ape test --network :mainnet-fork:hardhat -v DEBUG tests/test_Fork.py

The result is random.

How can it be fixed?

My thoughts are that sometimes hardhat takes longer than expected(especially given that I'm 300ms away from alchemy) to start listening on port 8545 and connection refused error is not handled anywhere. Some experiments shows that if we catch the error here things work fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions