Skip to content

Commit

Permalink
Fix pre-commit and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Nov 22, 2023
1 parent 3589c72 commit 40a298a
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 81 deletions.
4 changes: 3 additions & 1 deletion scripts/print_missing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import boa
from tabulate import tabulate

MISSING = "\033[33m✖\033[0m"
Expand All @@ -20,8 +21,9 @@ def get_non_indexed_view_functions(
if registry_selectors[k] in view_fns
}

metaregistry = boa.load_partial("contracts/mainnet/MetaRegistry.vy")
function_index = get_non_indexed_view_functions(
MetaRegistry.selectors, MetaRegistry.abi, {}
metaregistry.selectors, metaregistry.abi, {}
)
registry_coverage = [[PRESENT] * len(function_index)]
registry_names = [
Expand Down
5 changes: 1 addition & 4 deletions scripts/setup_metaregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ def cli():
pass


@cli.command(cls=NetworkBoundCommand)
@network_option()
@account_option()
def main(network: str, account: str):
# admin only: only admin of ADDRESSPROVIDER's proxy admin can do the following:
address_provider = get_deployed_contract(
Expand All @@ -146,7 +143,7 @@ def main(network: str, account: str):

if network == "ethereum:mainnet-fork":
RICH_CONSOLE.log("Simulation mode.")
account = accounts[proxy_admin.admins(1)]
account = proxy_admin.admins(1)

# deployed contracts:
base_pool_registry = get_deployed_contract(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def pytest_sessionstart():
# connect to the network. TODO: use Drpc-Key header instead of GET param
boa.env.fork(url=environ["RPC_ETHEREUM"])

# store instance of registries globally, so we don't have to recreate multiple times when generating tests.
# store registries globally, so we don't have to recreate multiple times when generating tests.
# TODO: Can we move these to fixtures?
STABLE_REGISTRY_POOLS = get_contract_pools(
"StableRegistry", "0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5"
Expand Down
9 changes: 0 additions & 9 deletions tests/fixtures/contracts.py

This file was deleted.

24 changes: 18 additions & 6 deletions tests/mainnet/metaregistry/api/test_get_admin_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@
import pytest
from eth.codecs.abi.exceptions import DecodeError

from tests.utils import get_lp_contract
from tests.utils import get_deployed_token_contract


def pre_test_checks(metaregistry, pool):
if sum(metaregistry.get_balances(pool)) == 0:
pytest.skip("empty pool: skipping")

try:
if get_lp_contract(metaregistry.get_lp_token(pool)).totalSupply() == 0:
if (
get_deployed_token_contract(
metaregistry.get_lp_token(pool)
).totalSupply()
== 0
):
pytest.skip("LP token supply is zero")
except DecodeError as err: # TODO: Document why this happens
pytest.skip(
f"{type(err).__name__} for token {metaregistry.get_lp_token(pool)}: Skipping because of {err.msg}"
f"{type(err).__name__} for token {metaregistry.get_lp_token(pool)}: "
f"Skipping because of {err.msg}"
)


def test_stable_registry_pools(
populated_metaregistry, stable_registry_pool, stable_registry
):
Expand All @@ -30,7 +37,9 @@ def test_stable_registry_pools(
assert output == metaregistry_output[i]


def test_stable_factory_pools(populated_metaregistry, stable_factory_pool, curve_pool):
def test_stable_factory_pools(
populated_metaregistry, stable_factory_pool, curve_pool
):
pre_test_checks(populated_metaregistry, stable_factory_pool)

pool = curve_pool(stable_factory_pool)
Expand All @@ -47,14 +56,17 @@ def test_stable_factory_pools(populated_metaregistry, stable_factory_pool, curve
def _get_crypto_pool_admin_fees(
populated_metaregistry, pool, fee_receiver, alice_address
):
lp_token = get_lp_contract(populated_metaregistry.get_lp_token(pool))
lp_token = get_deployed_token_contract(
populated_metaregistry.get_lp_token(pool)
)
fee_receiver_token_balance_before = lp_token.balanceOf(fee_receiver)

with boa.env.anchor():
pool.claim_admin_fees(sender=alice_address)

claimed_lp_token_as_fee = (
lp_token.balanceOf(fee_receiver) - fee_receiver_token_balance_before
lp_token.balanceOf(fee_receiver)
- fee_receiver_token_balance_before
)
total_supply_lp_token = lp_token.totalSupply()
frac_admin_fee = int(
Expand Down
2 changes: 1 addition & 1 deletion tests/mainnet/metaregistry/api/test_get_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_crypto_registry_pools(
):
try:
actual_output = crypto_registry.get_balances(crypto_registry_pool)
except ContractLogicError:
except KeyError: # TODO: Pick right exception
actual_output = []
pool = curve_pool_v2(crypto_registry_pool)
for i in range(
Expand Down
2 changes: 0 additions & 2 deletions tests/mainnet/metaregistry/api/test_get_gauge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import boa

from tests.utils import ZERO_ADDRESS


Expand Down
36 changes: 17 additions & 19 deletions tests/mainnet/metaregistry/api/test_get_pool_name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from tests.utils import ZERO_ADDRESS
from tests.utils import ZERO_ADDRESS, get_deployed_token_contract


def test_stable_registry_pools(
Expand All @@ -24,40 +24,38 @@ def test_stable_factory_pools(populated_metaregistry, stable_factory_pool):
list(filter((ZERO_ADDRESS).__ne__, pool_registry_handlers))
)

name = populated_metaregistry.get_pool_name(stable_factory_pool)
if num_registry_handlers == 1:
assert (
populated_metaregistry.get_pool_name(stable_factory_pool)
== VyperContract(stable_factory_pool).name()
)

elif num_registry_handlers == 2:
assert name == get_deployed_token_contract(stable_factory_pool).name()
else:
with pytest.raises(AssertionError):
assert (
populated_metaregistry.get_pool_name(stable_factory_pool)
== VyperContract(stable_factory_pool).name()
name == get_deployed_token_contract(stable_factory_pool).name()
)

pool_name2 = populated_metaregistry.get_pool_name(
stable_factory_pool, 1
)
assert (
populated_metaregistry.get_pool_name(stable_factory_pool, 1)
== VyperContract(stable_factory_pool).name()
pool_name2
== get_deployed_token_contract(stable_factory_pool).name()
)

else:
raise
assert num_registry_handlers in (1, 2)


def test_crypto_registry_pools(
populated_metaregistry, crypto_registry_pool, crypto_registry
):
assert populated_metaregistry.get_pool_name(
crypto_registry_pool
) == crypto_registry.get_pool_name(crypto_registry_pool)
pool_name = populated_metaregistry.get_pool_name(crypto_registry_pool)
assert pool_name == crypto_registry.get_pool_name(crypto_registry_pool)


def test_crypto_factory_pools(
populated_metaregistry, crypto_factory_pool, crypto_factory
):
assert (
populated_metaregistry.get_pool_name(crypto_factory_pool)
== VyperContract(crypto_factory.get_token(crypto_factory_pool)).name()
pool_name = populated_metaregistry.get_pool_name(crypto_factory_pool)
contract = get_deployed_token_contract(
crypto_factory.get_token(crypto_factory_pool)
)
assert pool_name == contract.name()
10 changes: 6 additions & 4 deletions tests/mainnet/metaregistry/api/test_get_underlying_balances.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import warnings

import boa
import pytest

from tests.utils import ZERO_ADDRESS
from tests.utils import ZERO_ADDRESS, get_deployed_token_contract

EXCEPTION_POOLS = ["0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27"]

Expand All @@ -30,10 +29,13 @@ def _get_underlying_balances(

if base_pool != ZERO_ADDRESS:
basepool_lp_token_balance = balances[idx]
coin_contract = VyperContract(coin)
coin_contract = get_deployed_token_contract(coin)
try:
lp_token_supply = coin_contract.totalSupply()
except (KeyError, AttributeError): # TODO: Pick the right exception
except (
KeyError,
AttributeError,
): # TODO: Pick the right exception
assert "totalSupply" not in [
i.name
for i in coin_contract.contract_type.view_methods
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import boa
import pytest

from tests.utils import ZERO_ADDRESS
from tests.utils import ZERO_ADDRESS, get_deployed_token_contract

EXCEPTIONS = {
# eth: ankreth pool returns [18, 0] when it should return:
Expand Down Expand Up @@ -32,7 +31,9 @@ def _test_underlying_decimals_getter(metaregistry, registry, pool):
continue

try:
token_contract = VyperContract(underlying_coins[i])
token_contract = get_deployed_token_contract(
underlying_coins[i]
)
actual_output.append(token_contract.decimals())
except KeyError: # TODO: Pick the right exception
pytest.skip("Unverified contract. Skipping test.")
Expand Down
7 changes: 5 additions & 2 deletions tests/mainnet/metaregistry/api/test_get_virtual_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import boa
import pytest

from tests.utils import ZERO_ADDRESS
from tests.utils import ZERO_ADDRESS, get_deployed_token_contract

# ---- sanity checks since vprice getters can revert for specific pools states ----

Expand Down Expand Up @@ -37,7 +37,10 @@ def _check_skem_tokens_with_weird_decimals(

if (
coin_decimals[i] == 0
and VyperContract(metaregistry.get_coins(pool)[0]).decimals() == 0
and get_deployed_token_contract(
metaregistry.get_coins(pool)[0]
).decimals()
== 0
):
with boa.env.anchor():
metaregistry.get_virtual_price_from_lp_token(lp_token)
Expand Down
12 changes: 9 additions & 3 deletions tests/mainnet/registries/test_add_remove_basepool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
def test_revert_unauthorised_add_base_pool(
owner, unauthorised_address, base_pools
):
base_pool_registry = deploy_contract("BasePoolRegistry", directory="registries", sender=owner)
base_pool_registry = deploy_contract(
"BasePoolRegistry", directory="registries", sender=owner
)
base_pool_data = base_pools["tripool"]
with boa.reverts():
base_pool_registry.add_base_pool(
Expand All @@ -20,7 +22,9 @@ def test_revert_unauthorised_add_base_pool(


def test_add_basepool(owner, base_pools, tokens):
base_pool_registry = deploy_contract("BasePoolRegistry", directory="registries", sender=owner)
base_pool_registry = deploy_contract(
"BasePoolRegistry", directory="registries", sender=owner
)
base_pool_count = base_pool_registry.base_pool_count()
base_pool_data = base_pools["tripool"]
tripool = base_pool_data["pool"]
Expand Down Expand Up @@ -60,7 +64,9 @@ def test_add_basepool(owner, base_pools, tokens):


def test_add_basepool_with_legacy_abi(owner, base_pools, tokens):
base_pool_registry = deploy_contract("BasePoolRegistry", directory="registries", sender=owner)
base_pool_registry = deploy_contract(
"BasePoolRegistry", directory="registries", sender=owner
)

base_pool_data = base_pools["sbtc"]
assert base_pool_data["is_legacy"]
Expand Down
18 changes: 14 additions & 4 deletions tests/mainnet/registries/test_add_remove_metapool.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ def test_add_metapool(
base_pools,
tokens,
):
crypto_registry = deploy_contract("CryptoRegistryV1", address_provider, populated_base_pool_registry,
directory="registries", sender=owner)
crypto_registry = deploy_contract(
"CryptoRegistryV1",
address_provider,
populated_base_pool_registry,
directory="registries",
sender=owner,
)

pool_count = crypto_registry.pool_count()
assert pool_count == 0
Expand Down Expand Up @@ -205,8 +210,13 @@ def test_remove_metapool(
base_pools,
tokens,
):
crypto_registry = deploy_contract("CryptoRegistryV1", address_provider, populated_base_pool_registry,
directory="registries", sender=owner)
crypto_registry = deploy_contract(
"CryptoRegistryV1",
address_provider,
populated_base_pool_registry,
directory="registries",
sender=owner,
)

# add EURT3CRV pool
eurt3crv = crypto_registry_pools["eurt3crv"]
Expand Down
18 changes: 14 additions & 4 deletions tests/mainnet/registries/test_add_remove_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ def test_add_pool(
owner,
tokens,
):
crypto_registry = deploy_contract("CryptoRegistryV1", address_provider, populated_base_pool_registry,
directory="registries", sender=owner)
crypto_registry = deploy_contract(
"CryptoRegistryV1",
address_provider,
populated_base_pool_registry,
directory="registries",
sender=owner,
)

pool_count = crypto_registry.pool_count()
assert pool_count == 0
Expand Down Expand Up @@ -152,8 +157,13 @@ def test_remove_pool(
max_coins,
tokens,
):
crypto_registry = deploy_contract("CryptoRegistryV1", address_provider, populated_base_pool_registry,
directory="registries", sender=owner)
crypto_registry = deploy_contract(
"CryptoRegistryV1",
address_provider,
populated_base_pool_registry,
directory="registries",
sender=owner,
)

# add pool to be removed:
tricrypto2 = crypto_registry_pools["tricrypto2"]
Expand Down
Loading

0 comments on commit 40a298a

Please sign in to comment.