Skip to content

Commit

Permalink
Fix circular fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Nov 22, 2023
1 parent de1e9de commit eeacdb7
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: unitary

on: ["push", "pull_request"]
on: ["push"]

jobs:
unitary:
Expand All @@ -21,7 +21,7 @@ jobs:
python-version: 3.11.6

- name: Install Requirements
run: pip install -r requirements.txt
run: pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt

- name: Run Tests
run: pytest
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM python:3.11-slim

WORKDIR /usr/app
RUN pip cache purge
COPY requirements.in ./
COPY requirements.txt ./
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.in
pip install --no-cache-dir -r requirements.txt

COPY . .
CMD pytest
4 changes: 2 additions & 2 deletions contracts/mainnet/MetaRegistry.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve Meta Registry
@license MIT
Expand Down Expand Up @@ -122,7 +122,7 @@ def _get_registry_handlers_from_pool(_pool: address) -> address[MAX_REGISTRIES]:
c += 1

if pool_registry_handler[0] == empty(address):
raise("no registry")
raise "no registry"
return pool_registry_handler


Expand Down
2 changes: 1 addition & 1 deletion contracts/mainnet/registries/BasePoolRegistry.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve BasePool Registry
@license MIT
Expand Down
2 changes: 1 addition & 1 deletion contracts/mainnet/registries/CryptoRegistryV1.vy
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve CryptoSwap Registry
@license MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve Registry Handler for v2 Factory
@license MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve Registry Handler for v2 Crypto Registry
@license MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve Registry Handler for v1 Factory (latest)
@license MIT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @version 0.3.10
#pragma version ^0.3.7
"""
@title Curve Registry Handler for v1 Registry
@license MIT
Expand Down
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
titanoboa==0.1.8
titanoboa[forking-recommended]==0.1.8
black
flake8
isort
Expand Down
14 changes: 9 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pathspec==0.11.2
# via black
pip-tools==7.3.0
# via -r requirements.in
platformdirs==3.11.0
platformdirs==4.0.0
# via
# black
# virtualenv
Expand All @@ -148,7 +148,7 @@ pycryptodome==3.19.0
# vyper
pyflakes==3.1.0
# via flake8
pygments==2.17.1
pygments==2.17.2
# via rich
pyproject-hooks==1.0.0
# via build
Expand Down Expand Up @@ -178,17 +178,21 @@ sortedcontainers==2.4.0
# trie
tabulate==0.9.0
# via -r requirements.in
titanoboa==0.1.8
# via -r requirements.in
titanoboa[forking-recommended]==0.1.8
# via
# -r requirements.in
# titanoboa
toolz==0.12.0
# via cytoolz
trie==2.2.0
# via py-evm
typing-extensions==4.8.0
# via eth-typing
ujson==5.8.0
# via titanoboa
urllib3==2.1.0
# via requests
virtualenv==20.24.6
virtualenv==20.24.7
# via pre-commit
vyper==0.3.10
# via titanoboa
Expand Down
3 changes: 1 addition & 2 deletions scripts/print_missing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ape
from tabulate import tabulate

MISSING = "\033[33m✖\033[0m"
Expand All @@ -22,7 +21,7 @@ def get_non_indexed_view_functions(
}

function_index = get_non_indexed_view_functions(
ape.project.MetaRegistry.selectors, ape.project.MetaRegistry.abi, {}
MetaRegistry.selectors, MetaRegistry.abi, {}
)
registry_coverage = [[PRESENT] * len(function_index)]
registry_names = [
Expand Down
4 changes: 2 additions & 2 deletions scripts/setup_metaregistry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

import click
from eth.constants import ZERO_ADDRESS
from tests.utils import ZERO_ADDRESS
from rich.console import Console as RichConsole

from tests.utils import get_deployed_contract
Expand Down Expand Up @@ -163,7 +163,7 @@ def main(network: str, account: str):
crypto_factory_handler,
]

# setup the metaregistry:
# set up the metaregistry:

total_gas_used = (
0 # gets total gas used for setting up. should be about 5mil gas.
Expand Down
4 changes: 1 addition & 3 deletions tests/fixtures/accounts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import logging
from collections import namedtuple

import pytest
from eth_account import Account
from eth_account.hdaccount import HDPath
Expand All @@ -20,6 +17,7 @@ def accounts(seed) -> list[LocalAccount]:
Generate 10 dev accounts from a seed.
Based on ape's `generate_test_accounts` method:
https://github.com/ApeWorX/ape/blob/9d4b66786/src/ape/utils/testing.py#L28
TODO: replace by boa.env.generate_address()?
"""
def generate_account(index: int, hd_path_format="m/44'/60'/0'/{}") -> LocalAccount:
hd_path = HDPath(hd_path_format.format(index))
Expand Down
12 changes: 6 additions & 6 deletions tests/fixtures/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def base_pool_registry(alice_address):

@pytest.fixture(scope="module", autouse=True)
def populated_base_pool_registry(base_pool_registry, owner, base_pools):
boa.env.eoa = owner
for data in base_pools.values():
boa.env.eoa = owner
base_pool_registry.add_base_pool(
data["pool"],
data["lp_token"],
Expand All @@ -54,6 +54,7 @@ def crypto_registry(
crypto_registry = deploy_contract("CryptoRegistryV1", ADDRESS_PROVIDER, populated_base_pool_registry,
directory="registries", sender=owner)

boa.env.eoa = owner
for _, pool in crypto_registry_pools.items():
crypto_registry.add_pool(
pool["pool"],
Expand All @@ -64,7 +65,6 @@ def crypto_registry(
pool["name"],
pool["base_pool"],
pool["has_positive_rebasing_tokens"],
sender=owner,
)

return crypto_registry
Expand All @@ -85,16 +85,15 @@ def metaregistry(address_provider, owner):
@pytest.fixture(scope="module", autouse=True)
def stable_registry_handler(stable_registry, owner):
return deploy_contract(
"StableRegistryHandler", stable_registry.address,
sender=owner, directory="registry_handlers", override_address=stable_registry.address,
"StableRegistryHandler", stable_registry.address, sender=owner, directory="registry_handlers",
)


@pytest.fixture(scope="module", autouse=True)
def stable_factory_handler(populated_base_pool_registry, stable_factory, owner):
return deploy_contract(
"StableFactoryHandler", stable_factory.address, populated_base_pool_registry.address,
sender=owner, directory="registry_handlers", override_address=stable_factory.address,
sender=owner, directory="registry_handlers",
)


Expand All @@ -109,7 +108,7 @@ def crypto_registry_handler(owner, crypto_registry):
def crypto_factory_handler(populated_base_pool_registry, crypto_factory, owner):
return deploy_contract(
"CryptoFactoryHandler", crypto_factory.address, populated_base_pool_registry.address,
sender=owner, directory="registry_handlers", override_address=crypto_factory.address,
sender=owner, directory="registry_handlers",
)


Expand All @@ -123,6 +122,7 @@ def handlers(stable_registry_handler, stable_factory_handler, crypto_registry_ha
return [stable_registry_handler, stable_factory_handler, crypto_registry_handler, crypto_factory_handler]


# TODO: Get rid of the autouse, it might make some tests slower than needed
@pytest.fixture(scope="module", autouse=True)
def populated_metaregistry(metaregistry, handlers, owner):
for handler in handlers:
Expand Down
7 changes: 4 additions & 3 deletions tests/mainnet/metaregistry/api/test_find_pool_for_coins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import itertools

import ape
from tests.utils import ZERO_ADDRESS


# NOTE: This is the most important method in the metaregistry contract since it will be used
# by integrators to find pools for coin pairs. It finds pools even if the coin pair is not
Expand All @@ -12,7 +13,7 @@ def _get_all_combinations(metaregistry, pool):
pool_coins = [
coin
for coin in metaregistry.get_coins(pool)
if coin != ape.utils.ZERO_ADDRESS
if coin != ZERO_ADDRESS
]
base_combinations = list(itertools.combinations(pool_coins, 2))
all_combinations = base_combinations
Expand All @@ -21,7 +22,7 @@ def _get_all_combinations(metaregistry, pool):
underlying_coins = [
coin
for coin in metaregistry.get_underlying_coins(pool)
if coin != ape.utils.ZERO_ADDRESS
if coin != ZERO_ADDRESS
]
all_combinations = all_combinations + [
(pool_coins[0], coin)
Expand Down
3 changes: 1 addition & 2 deletions tests/mainnet/metaregistry/api/test_get_admin_balances.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import ape
import pytest


Expand All @@ -10,7 +9,7 @@ def pre_test_checks(metaregistry, pool):
try:
if VyperContract(metaregistry.get_lp_token(pool)).totalSupply() == 0:
pytest.skip("lp token supply is zero")
except ape.exceptions.SignatureError:
except SignatureError:
pytest.skip(
f"SignatureError for token {metaregistry.get_lp_token(pool)}: skipping"
)
Expand Down
7 changes: 2 additions & 5 deletions tests/mainnet/metaregistry/api/test_get_balances.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import ape


def test_stable_registry_pools(
populated_metaregistry, stable_registry_pool, stable_registry
):
Expand Down Expand Up @@ -34,7 +31,7 @@ def test_crypto_registry_pools(

try:
actual_output = crypto_registry.get_balances(crypto_registry_pool)
except ape.exceptions.ContractLogicError:
except ContractLogicError:
actual_output = []
pool = curve_pool_v2(crypto_registry_pool)
for i in range(
Expand All @@ -55,7 +52,7 @@ def test_crypto_factory_pools(

try:
actual_output = crypto_factory.get_balances(crypto_factory_pool)
except ape.exceptions.ContractLogicError:
except ContractLogicError:
actual_output = []
pool = curve_pool_v2(crypto_factory_pool)
for i in range(2):
Expand Down
6 changes: 3 additions & 3 deletions tests/mainnet/metaregistry/api/test_get_base_pool.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ape
from tests.utils import ZERO_ADDRESS


def test_all(populated_metaregistry, populated_base_pool_registry, pool):

coins = populated_metaregistry.get_coins(pool)
actual_output = ape.utils.ZERO_ADDRESS
actual_output = ZERO_ADDRESS
for coin in coins:
actual_output = (
populated_base_pool_registry.get_base_pool_for_lp_token(coin)
)
if actual_output != ape.utils.ZERO_ADDRESS:
if actual_output != ZERO_ADDRESS:
break

metaregistry_output = populated_metaregistry.get_base_pool(pool)
Expand Down
12 changes: 6 additions & 6 deletions tests/mainnet/metaregistry/api/test_get_coin_indices.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import itertools
import warnings

import ape
import pytest
from tests.utils import ZERO_ADDRESS


def _reject_pools_with_one_coin(metaregistry, pool):

pool_coins = [
coin
for coin in metaregistry.get_coins(pool)
if coin != ape.utils.ZERO_ADDRESS
if coin != ZERO_ADDRESS
]
if len(list(set(pool_coins))) == 1:
warnings.warn(f"Pool {pool} has only one coin!")
Expand All @@ -26,7 +26,7 @@ def _get_coin_combinations(metaregistry, pool):
pool_coins = [
coin
for coin in metaregistry.get_coins(pool)
if coin != ape.utils.ZERO_ADDRESS
if coin != ZERO_ADDRESS
]

base_combinations = list(itertools.combinations(pool_coins, 2))
Expand All @@ -35,7 +35,7 @@ def _get_coin_combinations(metaregistry, pool):
underlying_coins = [
coin
for coin in metaregistry.get_underlying_coins(pool)
if coin != ape.utils.ZERO_ADDRESS
if coin != ZERO_ADDRESS
]
all_combinations = all_combinations + [
(pool_coins[0], coin) for coin in underlying_coins
Expand All @@ -54,7 +54,7 @@ def _get_coin_indices(pool, coin_a, coin_b, metaregistry, max_coins):
# check coin markets
for x in range(max_coins):
coin = _coins[x]
if coin == ape.utils.ZERO_ADDRESS:
if coin == ZERO_ADDRESS:
# if we reach the end of the coins, reset `found_market` and try again
# with the underlying coins
found_market = False
Expand All @@ -79,7 +79,7 @@ def _get_coin_indices(pool, coin_a, coin_b, metaregistry, max_coins):

for x in range(max_coins):
coin = underlying_coins[x]
if coin == ape.utils.ZERO_ADDRESS:
if coin == ZERO_ADDRESS:
raise "No available market"
if coin == coin_a:
result[0] = x
Expand Down
Loading

0 comments on commit eeacdb7

Please sign in to comment.