generated from ApeWorX/project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add back forking and tests
- Loading branch information
1 parent
f283078
commit 1355aa8
Showing
5 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
from ape import plugins | ||
|
||
from .provider import TenderlyGatewayProvider | ||
from .provider import TenderlyForkProvider, TenderlyGatewayProvider | ||
|
||
NETWORKS = { | ||
"ethereum": [ | ||
"mainnet", | ||
"goerli", | ||
"sepolia", | ||
("mainnet", TenderlyGatewayProvider), | ||
("mainnet-fork", TenderlyForkProvider), | ||
("goerli", TenderlyGatewayProvider), | ||
("sepolia", TenderlyGatewayProvider), | ||
], | ||
"fantom": [ | ||
("opera-fork", TenderlyForkProvider), | ||
], | ||
} | ||
|
||
|
||
@plugins.register(plugins.ProviderPlugin) | ||
def providers(): | ||
for ecosystem_name in NETWORKS: | ||
for network_name in NETWORKS[ecosystem_name]: | ||
yield ecosystem_name, network_name, TenderlyGatewayProvider | ||
for network_name, provider in NETWORKS[ecosystem_name]: | ||
yield ecosystem_name, network_name, provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ape | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def networks(): | ||
return ape.networks | ||
|
||
|
||
@pytest.fixture | ||
def accounts(): | ||
return ape.accounts | ||
|
||
|
||
@pytest.fixture | ||
def Contract(): | ||
return ape.Contract | ||
|
||
|
||
@pytest.fixture | ||
def mainnet_fork(networks): | ||
return networks.ethereum.mainnet_fork | ||
|
||
|
||
@pytest.fixture | ||
def mainnet_fork_provider(mainnet_fork): | ||
with mainnet_fork.use_provider("tenderly") as provider: | ||
yield provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
|
||
import pytest | ||
from ape.exceptions import ConfigError | ||
|
||
from ape_tenderly.provider import TENDERLY_FORK_ID | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def connected_eth_mainnet_provider(mainnet_fork_provider): | ||
""" | ||
See README for info on how to set the environment variable. | ||
Else, tests will not run. | ||
""" | ||
if TENDERLY_FORK_ID not in os.environ: | ||
pytest.fail(f"{TENDERLY_FORK_ID} environment variable is required to run tests.") | ||
|
||
return mainnet_fork_provider | ||
|
||
|
||
@pytest.fixture | ||
def unset_fork_id(mainnet_fork_provider): | ||
fork_id = os.environ.pop(TENDERLY_FORK_ID) | ||
was_cached = "fork_id" in mainnet_fork_provider.__dict__ | ||
if was_cached: | ||
del mainnet_fork_provider.__dict__["fork_id"] | ||
|
||
yield | ||
|
||
os.environ[TENDERLY_FORK_ID] = fork_id | ||
if was_cached: | ||
mainnet_fork_provider.__dict__["fork_id"] = fork_id | ||
|
||
|
||
def test_fork_id_and_uri(connected_eth_mainnet_provider): | ||
provider = connected_eth_mainnet_provider | ||
assert provider.fork_id | ||
assert provider.uri | ||
|
||
|
||
def test_fork_id_missing(mainnet_fork_provider, unset_fork_id): | ||
with pytest.raises(ConfigError, match="No valid tenderly fork ID found."): | ||
_ = mainnet_fork_provider.fork_id |