diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..09362ae --- /dev/null +++ b/.dockerignore @@ -0,0 +1,78 @@ +# Git +.gitignore +.gitattributes + + +# CI +.codeclimate.yml +.travis.yml +.taskcluster.yml + +# Docker +docker-compose.yml +Dockerfile +.docker +.dockerignore + +# Byte-compiled / optimized / DLL files +**/__pycache__/ +**/*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.cache +nosetests.xml +coverage.xml + +# PyBuilder +target/ + +# Virtual environment +.env +.venv/ +venv/ + +# PyCharm +.idea + +# Python mode for VIM +.ropeproject +**/.ropeproject + +# Vim swap files +**/*.swp + +# VS Code +.vscode/ diff --git a/.gitignore b/.gitignore index 500de94..866cf27 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ __pycache__/ .DS_Store venv/ bvenv/ -.env \ No newline at end of file +.env diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7d6119c..b3cc8b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,4 +23,4 @@ repos: args: ["--profile", "black", --line-length=79] default_language_version: - python: python3.10 + python: python3.11 diff --git a/Dockerfile b/Dockerfile index 38c6a94..d00544c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.11-slim +FROM python:3.11-slim as base WORKDIR /usr/app RUN pip cache purge @@ -6,5 +6,11 @@ COPY requirements.txt ./ RUN pip install --upgrade pip && \ pip install --no-cache-dir -r requirements.txt +FROM base as pre-commit +RUN apt-get update && apt-get install git +COPY . . +CMD pre-commit run --all-files + +FROM base as test COPY . . CMD pytest diff --git a/contracts/mainnet/abi/AddressProvider.json b/contracts/mainnet/abi/AddressProvider.json index 734cd08..d5a3cca 100644 --- a/contracts/mainnet/abi/AddressProvider.json +++ b/contracts/mainnet/abi/AddressProvider.json @@ -306,4 +306,4 @@ "type": "function", "gas": 12168 } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/CryptoFactory.json b/contracts/mainnet/abi/CryptoFactory.json index f8c5747..951ef0d 100644 --- a/contracts/mainnet/abi/CryptoFactory.json +++ b/contracts/mainnet/abi/CryptoFactory.json @@ -632,4 +632,4 @@ } ] } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/CryptoRegistry.json b/contracts/mainnet/abi/CryptoRegistry.json index 486ef19..fb0feba 100644 --- a/contracts/mainnet/abi/CryptoRegistry.json +++ b/contracts/mainnet/abi/CryptoRegistry.json @@ -598,4 +598,4 @@ ], "gas": 3366 } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/GaugeController.json b/contracts/mainnet/abi/GaugeController.json index 12179c6..669aecb 100644 --- a/contracts/mainnet/abi/GaugeController.json +++ b/contracts/mainnet/abi/GaugeController.json @@ -819,4 +819,4 @@ "type": "function", "gas": 2490 } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/ProxyAdmin.json b/contracts/mainnet/abi/ProxyAdmin.json index d4bc6c0..a2f15e2 100644 --- a/contracts/mainnet/abi/ProxyAdmin.json +++ b/contracts/mainnet/abi/ProxyAdmin.json @@ -201,4 +201,4 @@ } ] } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/StableFactory.json b/contracts/mainnet/abi/StableFactory.json index d6697ca..ca8bfd7 100644 --- a/contracts/mainnet/abi/StableFactory.json +++ b/contracts/mainnet/abi/StableFactory.json @@ -1060,4 +1060,4 @@ ], "gas": 3708 } -] \ No newline at end of file +] diff --git a/contracts/mainnet/abi/StableRegistry.json b/contracts/mainnet/abi/StableRegistry.json index ac50894..0dd9b2c 100644 --- a/contracts/mainnet/abi/StableRegistry.json +++ b/contracts/mainnet/abi/StableRegistry.json @@ -937,4 +937,4 @@ ], "gas": 2288 } -] \ No newline at end of file +] diff --git a/docker-compose.yaml b/docker-compose.yaml index 385d6ca..c1dd6ef 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,18 @@ -version: '3.1' +version: '3.8' services: test: build: ./ container_name: metaregistry-test env_file: .env + volumes: + - ./:/usr/app + + pre-commit: + build: + context: ./ + target: pre-commit + container_name: metaregistry-pre-commit + command: pre-commit run --all-files + volumes: + - ./:/usr/app diff --git a/scripts/boa_scripts/set_up_registries.py b/scripts/boa_scripts/set_up_registries.py index 1a3cb6b..d6c56c4 100644 --- a/scripts/boa_scripts/set_up_registries.py +++ b/scripts/boa_scripts/set_up_registries.py @@ -18,11 +18,12 @@ def deploy_factory_handler(): - pass -def set_up_registries(network: str, url: str, account: str, fork: bool = False): +def set_up_registries( + network: str, url: str, account: str, fork: bool = False +): """ Set up registries for the Curve StableSwapNG factory. :param network: Network to deploy to. @@ -41,8 +42,14 @@ def set_up_registries(network: str, url: str, account: str, fork: bool = False): boa.set_env(NetworkEnv(url)) boa.env.add_account(Account.from_key(os.environ[account])) - data = next((data for _network, data in deploy_utils.curve_dao_network_settings.items() - if _network in network), None) + data = next( + ( + data + for _network, data in deploy_utils.curve_dao_network_settings.items() + if _network in network + ), + None, + ) owner = data.dao_ownership_contract fee_receiver = data.fee_receiver_address @@ -68,8 +75,9 @@ def set_up_registries(network: str, url: str, account: str, fork: bool = False): ) if is_new_deployment: - - logger.info(f"Adding a new registry provider entry at id: {max_id + 1}") + logger.info( + f"Adding a new registry provider entry at id: {max_id + 1}" + ) # we're adding a new id with accounts.use_sender(account) as account: @@ -81,7 +89,6 @@ def set_up_registries(network: str, url: str, account: str, fork: bool = False): ) else: - assert address_provider.get_id_info(index).description == description logger.info( @@ -111,7 +118,6 @@ def set_up_registries(network: str, url: str, account: str, fork: bool = False): ].base_pool_registry_address if metaregistry_address: - metaregistry = Contract(metaregistry_address) boss = Contract(metaregistry.owner()) diff --git a/scripts/change_registry_handler.py b/scripts/change_registry_handler.py index a68f2fe..7896e61 100644 --- a/scripts/change_registry_handler.py +++ b/scripts/change_registry_handler.py @@ -39,7 +39,6 @@ def main(): - # admin only: only admin of ADDRESSPROVIDER's proxy admin can do the following: address_provider = AddressProvider.at(ADDRESS_PROVIDER) address_provider_admin = address_provider.admin() diff --git a/scripts/deploy.py b/scripts/deploy.py index 76cdf05..51cfc6e 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -19,7 +19,6 @@ def cli(): @network_option() @account_option() def main(network, account): - # deploy basepool registry: base_pool_registry = account.deploy(project.BasePoolRegistry) diff --git a/scripts/deploy_crypto_registry_handler.py b/scripts/deploy_crypto_registry_handler.py index 8ca850c..0c25040 100644 --- a/scripts/deploy_crypto_registry_handler.py +++ b/scripts/deploy_crypto_registry_handler.py @@ -15,7 +15,6 @@ def cli(): @network_option() @account_option() def main(network, account): - print( "Crypto Registry Handler constructor arguments: ", encode(["address"], [CRYPTO_REGISTRY_ADDRESS]).hex(), diff --git a/scripts/setup_metaregistry.py b/scripts/setup_metaregistry.py index 4e41fe8..b86af5c 100644 --- a/scripts/setup_metaregistry.py +++ b/scripts/setup_metaregistry.py @@ -1,10 +1,9 @@ import sys import click -from tests.utils import ZERO_ADDRESS from rich.console import Console as RichConsole -from tests.utils import get_deployed_contract +from tests.utils import ZERO_ADDRESS, get_deployed_contract RICH_CONSOLE = RichConsole(file=sys.stdout) @@ -138,24 +137,39 @@ def cli(): @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('AddressProvider', ADDRESS_PROVIDER) + address_provider = get_deployed_contract( + "AddressProvider", ADDRESS_PROVIDER + ) address_provider_admin = address_provider.admin() - proxy_admin = get_deployed_contract('ProxyAdmin', address_provider_admin) + proxy_admin = get_deployed_contract("ProxyAdmin", address_provider_admin) if network == "ethereum:mainnet-fork": RICH_CONSOLE.log("Simulation mode.") account = accounts[proxy_admin.admins(1)] # deployed contracts: - base_pool_registry = get_deployed_contract('BasePoolRegistry', "0xDE3eAD9B2145bBA2EB74007e58ED07308716B725") - crypto_registry = get_deployed_contract('CryptoRegistryV1', "0x9a32aF1A11D9c937aEa61A3790C2983257eA8Bc0") - stable_registry_handler = get_deployed_contract('StableRegistryHandler', "0x46a8a9CF4Fc8e99EC3A14558ACABC1D93A27de68") - stable_factory_handler = get_deployed_contract('StableFactoryHandler', "0x127db66E7F0b16470Bec194d0f496F9Fa065d0A9") - crypto_registry_handler = get_deployed_contract('CryptoRegistryHandler', "0x5f493fEE8D67D3AE3bA730827B34126CFcA0ae94") - crypto_factory_handler = get_deployed_contract('CryptoFactoryHandler', "0xC4F389020002396143B863F6325aA6ae481D19CE") - metaregistry = get_deployed_contract('MetaRegistry', "0xF98B45FA17DE75FB1aD0e7aFD971b0ca00e379fC") + base_pool_registry = get_deployed_contract( + "BasePoolRegistry", "0xDE3eAD9B2145bBA2EB74007e58ED07308716B725" + ) + crypto_registry = get_deployed_contract( + "CryptoRegistryV1", "0x9a32aF1A11D9c937aEa61A3790C2983257eA8Bc0" + ) + stable_registry_handler = get_deployed_contract( + "StableRegistryHandler", "0x46a8a9CF4Fc8e99EC3A14558ACABC1D93A27de68" + ) + stable_factory_handler = get_deployed_contract( + "StableFactoryHandler", "0x127db66E7F0b16470Bec194d0f496F9Fa065d0A9" + ) + crypto_registry_handler = get_deployed_contract( + "CryptoRegistryHandler", "0x5f493fEE8D67D3AE3bA730827B34126CFcA0ae94" + ) + crypto_factory_handler = get_deployed_contract( + "CryptoFactoryHandler", "0xC4F389020002396143B863F6325aA6ae481D19CE" + ) + metaregistry = get_deployed_contract( + "MetaRegistry", "0xF98B45FA17DE75FB1aD0e7aFD971b0ca00e379fC" + ) registry_handlers = [ stable_registry_handler, stable_factory_handler, @@ -172,7 +186,6 @@ def main(network: str, account: str): # populate base pool registry: base_pool_index = 0 for _, data in BASE_POOLS.items(): - # check if base pool already exists in the registry: entry_at_index = base_pool_registry.base_pool_list( base_pool_index @@ -210,7 +223,6 @@ def main(network: str, account: str): # populate crypto registry: crypto_pool_index = 0 for _, pool in CRYPTO_REGISTRY_POOLS.items(): - # check if base pool already exists in the registry: entry_at_index = crypto_registry.pool_list(crypto_pool_index).lower() if entry_at_index == pool["pool"].lower(): @@ -248,7 +260,6 @@ def main(network: str, account: str): # populate metaregistry: registry_handler_index = 0 for registry_handler in registry_handlers: - # check if base pool already exists in the registry: entry_at_index = metaregistry.get_registry( registry_handler_index diff --git a/tests/conftest.py b/tests/conftest.py index bd9aa58..1c83303 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,14 +29,24 @@ def pytest_sessionstart(): global ALL_POOLS # connect to the network. TODO: use Drpc-Key header instead of GET param - boa.env.fork(f"https://lb.drpc.org/ogrpc?network=ethereum&dkey={environ['DRPC_KEY']}") + boa.env.fork( + f"https://lb.drpc.org/ogrpc?network=ethereum&dkey={environ['DRPC_KEY']}" + ) # store instance of 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") - STABLE_FACTORY_POOLS = get_contract_pools("StableFactory", "0xB9fC157394Af804a3578134A6585C0dc9cc990d4") - CRYPTO_REGISTRY_POOLS = get_contract_pools("CryptoRegistry", "0x8F942C20D02bEfc377D41445793068908E2250D0") - CRYPTO_FACTORY_POOLS = get_contract_pools("CryptoFactory", "0xF18056Bbd320E96A48e3Fbf8bC061322531aac99") + STABLE_REGISTRY_POOLS = get_contract_pools( + "StableRegistry", "0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5" + ) + STABLE_FACTORY_POOLS = get_contract_pools( + "StableFactory", "0xB9fC157394Af804a3578134A6585C0dc9cc990d4" + ) + CRYPTO_REGISTRY_POOLS = get_contract_pools( + "CryptoRegistry", "0x8F942C20D02bEfc377D41445793068908E2250D0" + ) + CRYPTO_FACTORY_POOLS = get_contract_pools( + "CryptoFactory", "0xF18056Bbd320E96A48e3Fbf8bC061322531aac99" + ) ALL_POOLS = ( STABLE_REGISTRY_POOLS diff --git a/tests/fixtures/accounts.py b/tests/fixtures/accounts.py index 2119c8e..99775b3 100644 --- a/tests/fixtures/accounts.py +++ b/tests/fixtures/accounts.py @@ -11,6 +11,7 @@ def seed() -> bytes: return Mnemonic.to_seed("test") + @pytest.fixture(scope="session") def accounts(seed) -> list[LocalAccount]: """ @@ -19,13 +20,17 @@ def accounts(seed) -> list[LocalAccount]: 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: + + def generate_account( + index: int, hd_path_format="m/44'/60'/0'/{}" + ) -> LocalAccount: hd_path = HDPath(hd_path_format.format(index)) private_key = f"0x{hd_path.derive(seed).hex()}" return Account.from_key(private_key) return [generate_account(index) for index in range(10)] + @pytest.fixture(scope="session") def alice_address(accounts): return accounts[0].address @@ -43,5 +48,7 @@ def random_address(accounts): @pytest.fixture(scope="module") def owner(accounts): - address_provider = get_deployed_contract('AddressProvider', "0x0000000022D53366457F9d5E68Ec105046FC4383") + address_provider = get_deployed_contract( + "AddressProvider", "0x0000000022D53366457F9d5E68Ec105046FC4383" + ) return address_provider.admin() diff --git a/tests/fixtures/constants.py b/tests/fixtures/constants.py index 5001718..a6a3920 100644 --- a/tests/fixtures/constants.py +++ b/tests/fixtures/constants.py @@ -1,12 +1,10 @@ import pytest - ZERO_ADDRESS = "0x0000000000000000000000000000000000000000" @pytest.fixture(scope="module") def base_pools(): - base_pool_data = {} base_pool_data["tripool"] = { "pool": "0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7", @@ -40,7 +38,6 @@ def base_pools(): @pytest.fixture(scope="module") def crypto_registry_pools(base_pools): - pool_data = {} pool_data["tricrypto2"] = { "pool": "0xD51a44d3FaE010294C616388b506AcdA1bfAAE46", diff --git a/tests/fixtures/contracts.py b/tests/fixtures/contracts.py index b7192f2..f0a2522 100644 --- a/tests/fixtures/contracts.py +++ b/tests/fixtures/contracts.py @@ -3,7 +3,7 @@ @pytest.fixture(scope="module") def address_provider_contract(accounts): - address_provider = get_deployed_contract('AddressProvider', - "0x0000000022D53366457F9d5E68Ec105046FC4383" + address_provider = get_deployed_contract( + "AddressProvider", "0x0000000022D53366457F9d5E68Ec105046FC4383" ) return accounts[address_provider.admin()] diff --git a/tests/fixtures/deployments.py b/tests/fixtures/deployments.py index e393835..9b4027e 100644 --- a/tests/fixtures/deployments.py +++ b/tests/fixtures/deployments.py @@ -2,34 +2,44 @@ import pytest from boa.vyper.contract import VyperContract -from tests.utils import get_deployed_contract, deploy_contract +from tests.utils import deploy_contract, get_deployed_contract ADDRESS_PROVIDER = "0x0000000022D53366457F9d5E68Ec105046FC4383" @pytest.fixture(scope="module", autouse=True) def gauge_controller() -> VyperContract: - return get_deployed_contract('GaugeController', "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB") + return get_deployed_contract( + "GaugeController", "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB" + ) @pytest.fixture(scope="module", autouse=True) def stable_registry() -> VyperContract: - return get_deployed_contract('StableRegistry', "0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5") + return get_deployed_contract( + "StableRegistry", "0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5" + ) @pytest.fixture(scope="module", autouse=True) def stable_factory() -> VyperContract: - return get_deployed_contract('StableFactory', "0xB9fC157394Af804a3578134A6585C0dc9cc990d4") + return get_deployed_contract( + "StableFactory", "0xB9fC157394Af804a3578134A6585C0dc9cc990d4" + ) @pytest.fixture(scope="module", autouse=True) def crypto_factory() -> VyperContract: - return get_deployed_contract('CryptoFactory', "0xF18056Bbd320E96A48e3Fbf8bC061322531aac99") + return get_deployed_contract( + "CryptoFactory", "0xF18056Bbd320E96A48e3Fbf8bC061322531aac99" + ) @pytest.fixture(scope="module", autouse=True) def base_pool_registry(alice_address): - return deploy_contract("BasePoolRegistry", sender=alice_address, directory="registries") + return deploy_contract( + "BasePoolRegistry", sender=alice_address, directory="registries" + ) @pytest.fixture(scope="module", autouse=True) @@ -51,8 +61,13 @@ def populated_base_pool_registry(base_pool_registry, owner, base_pools): def crypto_registry( populated_base_pool_registry, owner, crypto_registry_pools ): - 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, + ) boa.env.eoa = owner for _, pool in crypto_registry_pools.items(): @@ -72,7 +87,7 @@ def crypto_registry( @pytest.fixture(scope="module", autouse=True) def address_provider(crypto_registry, owner): - contract = get_deployed_contract('AddressProvider', ADDRESS_PROVIDER) + contract = get_deployed_contract("AddressProvider", ADDRESS_PROVIDER) contract.set_address(5, crypto_registry, sender=owner) return contract @@ -85,41 +100,69 @@ 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", + "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): +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", + "StableFactoryHandler", + stable_factory.address, + populated_base_pool_registry.address, + sender=owner, + directory="registry_handlers", ) @pytest.fixture(scope="module", autouse=True) def crypto_registry_handler(owner, crypto_registry): return deploy_contract( - "CryptoRegistryHandler", crypto_registry.address, sender=owner, directory="registry_handlers", + "CryptoRegistryHandler", + crypto_registry.address, + sender=owner, + directory="registry_handlers", ) @pytest.fixture(scope="module", autouse=True) -def crypto_factory_handler(populated_base_pool_registry, crypto_factory, owner): +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", + "CryptoFactoryHandler", + crypto_factory.address, + populated_base_pool_registry.address, + sender=owner, + directory="registry_handlers", ) @pytest.fixture(scope="module") -def registries(stable_registry, stable_factory, crypto_registry, crypto_factory): +def registries( + stable_registry, stable_factory, crypto_registry, crypto_factory +): return [stable_registry, stable_factory, crypto_registry, crypto_factory] @pytest.fixture(scope="module") -def handlers(stable_registry_handler, stable_factory_handler, crypto_registry_handler, crypto_factory_handler): - return [stable_registry_handler, stable_factory_handler, crypto_registry_handler, crypto_factory_handler] +def handlers( + stable_registry_handler, + stable_factory_handler, + crypto_registry_handler, + crypto_factory_handler, +): + 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 diff --git a/tests/fixtures/functions.py b/tests/fixtures/functions.py index 0acbddd..0d2f0ce 100644 --- a/tests/fixtures/functions.py +++ b/tests/fixtures/functions.py @@ -5,14 +5,13 @@ from tests.utils import get_deployed_contract - # ---- Factories ---- @pytest.fixture(scope="module") def curve_pool(project) -> Callable: def _initialise(_pool: str) -> VyperContract: - return get_deployed_contract('CurvePool', _pool) + return get_deployed_contract("CurvePool", _pool) return _initialise @@ -20,7 +19,7 @@ def _initialise(_pool: str) -> VyperContract: @pytest.fixture(scope="module") def curve_pool_v2(project) -> Callable: def _initialise(_pool: str) -> VyperContract: - return get_deployed_contract('CurvePoolV2', _pool) + return get_deployed_contract("CurvePoolV2", _pool) return _initialise @@ -28,6 +27,6 @@ def _initialise(_pool: str) -> VyperContract: @pytest.fixture(scope="module") def liquidity_gauge(project) -> Callable: def _initialise(_gauge: str) -> VyperContract: - return get_deployed_contract('LiquidityGauge', _gauge) + return get_deployed_contract("LiquidityGauge", _gauge) return _initialise diff --git a/tests/mainnet/metaregistry/api/test_find_pool_for_coins.py b/tests/mainnet/metaregistry/api/test_find_pool_for_coins.py index 5222659..db8f661 100644 --- a/tests/mainnet/metaregistry/api/test_find_pool_for_coins.py +++ b/tests/mainnet/metaregistry/api/test_find_pool_for_coins.py @@ -2,18 +2,14 @@ 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 # a direct coin pair, but has a path through a metapool. def _get_all_combinations(metaregistry, pool): - pool_coins = [ - coin - for coin in metaregistry.get_coins(pool) - if coin != ZERO_ADDRESS + coin for coin in metaregistry.get_coins(pool) if coin != ZERO_ADDRESS ] base_combinations = list(itertools.combinations(pool_coins, 2)) all_combinations = base_combinations @@ -34,7 +30,6 @@ def _get_all_combinations(metaregistry, pool): def test_all(populated_metaregistry, pool): - combinations = _get_all_combinations(populated_metaregistry, pool) for combination in combinations: pools_containing_pair = populated_metaregistry.find_pools_for_coins( diff --git a/tests/mainnet/metaregistry/api/test_get_admin_balances.py b/tests/mainnet/metaregistry/api/test_get_admin_balances.py index 7c4e131..2cd30bc 100644 --- a/tests/mainnet/metaregistry/api/test_get_admin_balances.py +++ b/tests/mainnet/metaregistry/api/test_get_admin_balances.py @@ -2,7 +2,6 @@ def pre_test_checks(metaregistry, pool): - if sum(metaregistry.get_balances(pool)) == 0: pytest.skip("empty pool: skipping") @@ -18,7 +17,6 @@ def pre_test_checks(metaregistry, pool): def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - pre_test_checks(populated_metaregistry, stable_registry_pool) actual_output = stable_registry.get_admin_balances(stable_registry_pool) @@ -34,7 +32,6 @@ def test_stable_factory_pools( stable_factory_pool, curve_pool, ): - pre_test_checks(populated_metaregistry, stable_factory_pool) pool = curve_pool(stable_factory_pool) @@ -51,7 +48,6 @@ def test_stable_factory_pools( def _get_crypto_pool_admin_fees( populated_metaregistry, pool, fee_receiver, project, alice_address, chain ): - lp_token = VyperContract(populated_metaregistry.get_lp_token(pool)) fee_receiver_token_balance_before = lp_token.balanceOf(fee_receiver) @@ -84,13 +80,17 @@ def test_crypto_registry_pools( chain, project, ): - pre_test_checks(populated_metaregistry, crypto_registry_pool) pool = curve_pool_v2(crypto_registry_pool) fee_receiver = pool.admin_fee_receiver() admin_balances = _get_crypto_pool_admin_fees( - populated_metaregistry, pool, fee_receiver, project, alice_address, chain + populated_metaregistry, + pool, + fee_receiver, + project, + alice_address, + chain, ) metaregistry_output = populated_metaregistry.get_admin_balances(pool) @@ -107,13 +107,17 @@ def test_crypto_factory_pools( chain, project, ): - pre_test_checks(populated_metaregistry, crypto_factory_pool) pool = curve_pool_v2(crypto_factory_pool) fee_receiver = crypto_factory.fee_receiver() admin_balances = _get_crypto_pool_admin_fees( - populated_metaregistry, pool, fee_receiver, project, alice_address, chain + populated_metaregistry, + pool, + fee_receiver, + project, + alice_address, + chain, ) metaregistry_output = populated_metaregistry.get_admin_balances(pool) diff --git a/tests/mainnet/metaregistry/api/test_get_balances.py b/tests/mainnet/metaregistry/api/test_get_balances.py index 5f437b1..ebb5631 100644 --- a/tests/mainnet/metaregistry/api/test_get_balances.py +++ b/tests/mainnet/metaregistry/api/test_get_balances.py @@ -1,7 +1,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - actual_output = stable_registry.get_balances(stable_registry_pool) metaregistry_output = populated_metaregistry.get_balances( stable_registry_pool @@ -13,7 +12,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - actual_output = stable_factory.get_balances(stable_factory_pool) metaregistry_output = populated_metaregistry.get_balances( stable_factory_pool @@ -28,7 +26,6 @@ def test_crypto_registry_pools( crypto_registry, curve_pool_v2, ): - try: actual_output = crypto_registry.get_balances(crypto_registry_pool) except ContractLogicError: @@ -49,7 +46,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, crypto_factory, curve_pool_v2 ): - try: actual_output = crypto_factory.get_balances(crypto_factory_pool) except ContractLogicError: diff --git a/tests/mainnet/metaregistry/api/test_get_base_pool.py b/tests/mainnet/metaregistry/api/test_get_base_pool.py index 02cd692..7aca16c 100644 --- a/tests/mainnet/metaregistry/api/test_get_base_pool.py +++ b/tests/mainnet/metaregistry/api/test_get_base_pool.py @@ -2,7 +2,6 @@ def test_all(populated_metaregistry, populated_base_pool_registry, pool): - coins = populated_metaregistry.get_coins(pool) actual_output = ZERO_ADDRESS for coin in coins: diff --git a/tests/mainnet/metaregistry/api/test_get_coin_indices.py b/tests/mainnet/metaregistry/api/test_get_coin_indices.py index f4b7e59..83c4efe 100644 --- a/tests/mainnet/metaregistry/api/test_get_coin_indices.py +++ b/tests/mainnet/metaregistry/api/test_get_coin_indices.py @@ -2,15 +2,13 @@ import warnings 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 != ZERO_ADDRESS + coin for coin in metaregistry.get_coins(pool) if coin != ZERO_ADDRESS ] if len(list(set(pool_coins))) == 1: warnings.warn(f"Pool {pool} has only one coin!") @@ -18,15 +16,12 @@ def _reject_pools_with_one_coin(metaregistry, pool): def _get_coin_combinations(metaregistry, pool): - # skip tests if pool has only one coin: _reject_pools_with_one_coin(metaregistry, pool) is_meta = metaregistry.is_meta(pool) pool_coins = [ - coin - for coin in metaregistry.get_coins(pool) - if coin != ZERO_ADDRESS + coin for coin in metaregistry.get_coins(pool) if coin != ZERO_ADDRESS ] base_combinations = list(itertools.combinations(pool_coins, 2)) @@ -73,7 +68,6 @@ def _get_coin_indices(pool, coin_a, coin_b, metaregistry, max_coins): found_market = True if not found_market and metaregistry.is_meta(pool): - # check underlying coin markets underlying_coins = metaregistry.get_underlying_coins(pool) @@ -97,9 +91,7 @@ def _get_coin_indices(pool, coin_a, coin_b, metaregistry, max_coins): def _test_coin_indices(coin_a, coin_b, metaregistry, pool, max_coins): - if coin_a != coin_b: - metaregistry_output = metaregistry.get_coin_indices( pool, coin_a, coin_b ) @@ -118,7 +110,6 @@ def _test_coin_indices(coin_a, coin_b, metaregistry, pool, max_coins): def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, max_coins ): - all_combinations = _get_coin_combinations( populated_metaregistry, stable_registry_pool ) @@ -138,7 +129,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, max_coins ): - all_combinations = _get_coin_combinations( populated_metaregistry, stable_factory_pool ) @@ -158,7 +148,6 @@ def test_stable_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, max_coins ): - all_combinations = _get_coin_combinations( populated_metaregistry, crypto_registry_pool ) @@ -178,7 +167,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, max_coins ): - all_combinations = _get_coin_combinations( populated_metaregistry, crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_coins.py b/tests/mainnet/metaregistry/api/test_get_coins.py index 30c164e..2ca2a65 100644 --- a/tests/mainnet/metaregistry/api/test_get_coins.py +++ b/tests/mainnet/metaregistry/api/test_get_coins.py @@ -1,7 +1,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - metaregistry_output = populated_metaregistry.get_coins( stable_registry_pool ) @@ -13,7 +12,6 @@ def test_stable_registry_pools( def test_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - metaregistry_output = populated_metaregistry.get_coins(stable_factory_pool) actual_output = list(stable_factory.get_coins(stable_factory_pool)) for idx, coin in enumerate(actual_output): @@ -23,7 +21,6 @@ def test_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - metaregistry_output = populated_metaregistry.get_coins( crypto_registry_pool ) @@ -35,7 +32,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, crypto_factory ): - metaregistry_output = populated_metaregistry.get_coins(crypto_factory_pool) actual_output = list(crypto_factory.get_coins(crypto_factory_pool)) for idx, coin in enumerate(actual_output): diff --git a/tests/mainnet/metaregistry/api/test_get_decimals.py b/tests/mainnet/metaregistry/api/test_get_decimals.py index 780da92..242258d 100644 --- a/tests/mainnet/metaregistry/api/test_get_decimals.py +++ b/tests/mainnet/metaregistry/api/test_get_decimals.py @@ -1,7 +1,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - metaregistry_output = populated_metaregistry.get_decimals( stable_registry_pool ) @@ -13,7 +12,6 @@ def test_stable_registry_pools( def test_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - metaregistry_output = populated_metaregistry.get_decimals( stable_factory_pool ) @@ -25,7 +23,6 @@ def test_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - metaregistry_output = populated_metaregistry.get_decimals( crypto_registry_pool ) @@ -37,7 +34,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, crypto_factory ): - metaregistry_output = populated_metaregistry.get_decimals( crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_fees.py b/tests/mainnet/metaregistry/api/test_get_fees.py index 18647f3..255d5be 100644 --- a/tests/mainnet/metaregistry/api/test_get_fees.py +++ b/tests/mainnet/metaregistry/api/test_get_fees.py @@ -39,7 +39,6 @@ def test_crypto_registry_pools( crypto_registry, curve_pool_v2, ): - if sum(crypto_registry.get_balances(crypto_registry_pool)) == 0: with boa.reverts(): curve_pool_v2(crypto_registry_pool).fee() @@ -62,7 +61,6 @@ def test_crypto_factory_pools( crypto_factory, curve_pool_v2, ): - if sum(crypto_factory.get_balances(crypto_factory_pool)) == 0: with ape.reverts(): curve_pool_v2(crypto_factory_pool).fee() diff --git a/tests/mainnet/metaregistry/api/test_get_gauge.py b/tests/mainnet/metaregistry/api/test_get_gauge.py index 08e0230..ddc1a9a 100644 --- a/tests/mainnet/metaregistry/api/test_get_gauge.py +++ b/tests/mainnet/metaregistry/api/test_get_gauge.py @@ -1,9 +1,9 @@ import boa + from tests.utils import ZERO_ADDRESS def _is_dao_onboarded_gauge(_gauge, gauge_controller, liquidity_gauge): - try: gauge_controller.gauge_types(_gauge) except ape.exceptions.VirtualMachineError: @@ -22,7 +22,6 @@ def _get_factory_gauge( liquidity_gauge, default_gauge_type: int = 0, ): - gauge = registry.get_gauge(pool) # we check if the gauge is dao onboarded, else @@ -45,7 +44,6 @@ def test_stable_registry_pools( stable_registry_pool, stable_registry, ): - actual_output = stable_registry.get_gauges(stable_registry_pool) metaregistry_output_gauge = populated_metaregistry.get_gauge( stable_registry_pool @@ -65,7 +63,6 @@ def test_stable_factory_pools( gauge_controller, liquidity_gauge, ): - actual_output = _get_factory_gauge( stable_factory, stable_factory_pool, gauge_controller, liquidity_gauge ) @@ -99,7 +96,6 @@ def test_stable_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - actual_output = crypto_registry.get_gauges(crypto_registry_pool) metaregistry_output_gauge = populated_metaregistry.get_gauge( crypto_registry_pool @@ -119,7 +115,6 @@ def test_crypto_factory_pools( gauge_controller, liquidity_gauge, ): - # warning: gauge_type == 5 : this is true only for crypto pools on ethereum actual_output = _get_factory_gauge( crypto_factory, diff --git a/tests/mainnet/metaregistry/api/test_get_lp_token.py b/tests/mainnet/metaregistry/api/test_get_lp_token.py index 351b6bc..1d9e47c 100644 --- a/tests/mainnet/metaregistry/api/test_get_lp_token.py +++ b/tests/mainnet/metaregistry/api/test_get_lp_token.py @@ -1,7 +1,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - actual_output = stable_registry.get_lp_token(stable_registry_pool) metaregistry_output = populated_metaregistry.get_lp_token( stable_registry_pool @@ -10,7 +9,6 @@ def test_stable_registry_pools( def test_stable_factory_pools(populated_metaregistry, stable_factory_pool): - metaregistry_output = populated_metaregistry.get_lp_token( stable_factory_pool ) @@ -22,7 +20,6 @@ def test_stable_factory_pools(populated_metaregistry, stable_factory_pool): def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - actual_output = crypto_registry.get_lp_token(crypto_registry_pool) metaregistry_output = populated_metaregistry.get_lp_token( crypto_registry_pool @@ -33,7 +30,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, crypto_factory ): - actual_output = crypto_factory.get_token(crypto_factory_pool) metaregistry_output = populated_metaregistry.get_lp_token( crypto_factory_pool diff --git a/tests/mainnet/metaregistry/api/test_get_n_coins.py b/tests/mainnet/metaregistry/api/test_get_n_coins.py index f858a95..0c35d2b 100644 --- a/tests/mainnet/metaregistry/api/test_get_n_coins.py +++ b/tests/mainnet/metaregistry/api/test_get_n_coins.py @@ -2,22 +2,17 @@ def _get_n_coins_for_pool(registry, pool): - actual_output = registry.get_n_coins(pool) # registry returns tuple, we want the first one (since the second) # index is about basepool n coins if not isinstance(actual_output, int): - actual_output = registry.get_n_coins(pool)[0] # registry returns 0 value for n coins: something's not right on the # registry's side. find n_coins via registry.get_coins: elif actual_output == 0: - coins = registry.get_coins(pool) - actual_output = sum( - [1 for coin in coins if coin != ZERO_ADDRESS] - ) + actual_output = sum([1 for coin in coins if coin != ZERO_ADDRESS]) return actual_output @@ -25,7 +20,6 @@ def _get_n_coins_for_pool(registry, pool): def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - actual_output = _get_n_coins_for_pool( stable_registry, stable_registry_pool ) @@ -39,7 +33,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - actual_output = _get_n_coins_for_pool(stable_factory, stable_factory_pool) metaregistry_output = populated_metaregistry.get_n_coins( @@ -51,7 +44,6 @@ def test_stable_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - actual_output = _get_n_coins_for_pool( crypto_registry, crypto_registry_pool ) @@ -65,11 +57,8 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, crypto_factory ): - coins = crypto_factory.get_coins(crypto_factory_pool) - actual_output = sum( - [1 for coin in coins if coin != ZERO_ADDRESS] - ) + actual_output = sum([1 for coin in coins if coin != ZERO_ADDRESS]) metaregistry_output = populated_metaregistry.get_n_coins( crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_n_underlying_coins.py b/tests/mainnet/metaregistry/api/test_get_n_underlying_coins.py index 7933411..9b042af 100644 --- a/tests/mainnet/metaregistry/api/test_get_n_underlying_coins.py +++ b/tests/mainnet/metaregistry/api/test_get_n_underlying_coins.py @@ -2,18 +2,15 @@ def _get_num_coins(registry, pool, base_pool_registry): - coins = registry.get_coins(pool) num_coins = 0 for coin in coins: - if coin == ZERO_ADDRESS: break base_pool = base_pool_registry.get_base_pool_for_lp_token(coin) if base_pool != ZERO_ADDRESS: - basepool_coins = base_pool_registry.get_coins(base_pool) num_bp_coins = sum( [1 for i in basepool_coins if i != ZERO_ADDRESS] @@ -21,7 +18,6 @@ def _get_num_coins(registry, pool, base_pool_registry): num_coins += num_bp_coins else: - num_coins += 1 return num_coins @@ -33,7 +29,6 @@ def test_stable_registry_pools( stable_registry, populated_base_pool_registry, ): - metaregistry_output = populated_metaregistry.get_n_underlying_coins( stable_registry_pool ) @@ -50,7 +45,6 @@ def test_stable_factory_pools( stable_factory, populated_base_pool_registry, ): - metaregistry_output = populated_metaregistry.get_n_underlying_coins( stable_factory_pool ) @@ -67,7 +61,6 @@ def test_crypto_registry_pools( crypto_registry, populated_base_pool_registry, ): - metaregistry_output = populated_metaregistry.get_n_underlying_coins( crypto_registry_pool ) @@ -84,7 +77,6 @@ def test_crypto_factory_pools( crypto_factory, populated_base_pool_registry, ): - metaregistry_output = populated_metaregistry.get_n_underlying_coins( crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_pool_asset_type.py b/tests/mainnet/metaregistry/api/test_get_pool_asset_type.py index 73909ee..706bf87 100644 --- a/tests/mainnet/metaregistry/api/test_get_pool_asset_type.py +++ b/tests/mainnet/metaregistry/api/test_get_pool_asset_type.py @@ -6,7 +6,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - assert populated_metaregistry.get_pool_asset_type( stable_registry_pool ) == stable_registry.get_pool_asset_type(stable_registry_pool) @@ -26,12 +25,10 @@ def test_stable_factory_pools( def test_crypto_registry_pools(populated_metaregistry, crypto_registry_pool): - assert ( populated_metaregistry.get_pool_asset_type(crypto_registry_pool) == 4 ) def test_crypto_factory_pools(populated_metaregistry, crypto_factory_pool): - assert populated_metaregistry.get_pool_asset_type(crypto_factory_pool) == 4 diff --git a/tests/mainnet/metaregistry/api/test_get_pool_name.py b/tests/mainnet/metaregistry/api/test_get_pool_name.py index 1c4018b..1e7df87 100644 --- a/tests/mainnet/metaregistry/api/test_get_pool_name.py +++ b/tests/mainnet/metaregistry/api/test_get_pool_name.py @@ -1,18 +1,17 @@ import pytest + from tests.utils import ZERO_ADDRESS def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - assert populated_metaregistry.get_pool_name( stable_registry_pool ) == stable_registry.get_pool_name(stable_registry_pool) def test_stable_factory_pools(populated_metaregistry, stable_factory_pool): - # same issues where a pool that was first in a registry got ported over to the # factory incorrectly. so we try different handler indices to check if we get # the right result: @@ -26,16 +25,13 @@ def test_stable_factory_pools(populated_metaregistry, 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: - with pytest.raises(AssertionError): - assert ( populated_metaregistry.get_pool_name(stable_factory_pool) == VyperContract(stable_factory_pool).name() @@ -47,14 +43,12 @@ def test_stable_factory_pools(populated_metaregistry, stable_factory_pool): ) else: - raise 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) @@ -63,7 +57,6 @@ def test_crypto_registry_pools( 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() diff --git a/tests/mainnet/metaregistry/api/test_get_pool_params.py b/tests/mainnet/metaregistry/api/test_get_pool_params.py index f8c96f0..43fd164 100644 --- a/tests/mainnet/metaregistry/api/test_get_pool_params.py +++ b/tests/mainnet/metaregistry/api/test_get_pool_params.py @@ -1,7 +1,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - actual_pool_params = [0] * 20 actual_pool_params[0] = stable_registry.get_A(stable_registry_pool) metaregistry_output = populated_metaregistry.get_pool_params( @@ -14,7 +13,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - metaregistry_output = populated_metaregistry.get_pool_params( stable_factory_pool ) @@ -30,7 +28,6 @@ def test_crypto_registry_pools( crypto_registry, curve_pool_v2, ): - metaregistry_output = populated_metaregistry.get_pool_params( crypto_registry_pool ) @@ -50,7 +47,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, curve_pool_v2 ): - metaregistry_output = populated_metaregistry.get_pool_params( crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_underlying_balances.py b/tests/mainnet/metaregistry/api/test_get_underlying_balances.py index cd1b041..9205e4f 100644 --- a/tests/mainnet/metaregistry/api/test_get_underlying_balances.py +++ b/tests/mainnet/metaregistry/api/test_get_underlying_balances.py @@ -2,13 +2,13 @@ import boa import pytest + from tests.utils import ZERO_ADDRESS EXCEPTION_POOLS = ["0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27"] def pre_test_checks(metaregistry, pool): - if sum(metaregistry.get_balances(pool)) == 0: pytest.skip(f"Empty pool: {pool}") @@ -16,24 +16,19 @@ def pre_test_checks(metaregistry, pool): def _get_underlying_balances( metaregistry, pool, registry, base_pool_registry, max_coins ): - actual_output = [0] * max_coins try: - actual_output = registry.get_underlying_balances(pool) # registry getter borks, so we need to get balances the hard way: except (ape.exceptions.ContractLogicError, AttributeError): - coins = metaregistry.get_coins(pool) balances = metaregistry.get_balances(pool) for idx, coin in enumerate(coins): - base_pool = base_pool_registry.get_base_pool_for_lp_token(coin) if base_pool != ZERO_ADDRESS: - basepool_lp_token_balance = balances[idx] coin_contract = VyperContract(coin) try: @@ -52,7 +47,6 @@ def _get_underlying_balances( base_pool_balances = metaregistry.get_balances(base_pool) for idy, balance in enumerate(base_pool_balances): - if coin == ZERO_ADDRESS: break actual_output[idx] = balance * ratio_in_pool @@ -67,7 +61,6 @@ def _get_underlying_balances( def _test_underlying_balances_getter( metaregistry, pool, registry, base_pool_registry, max_coins ): - actual_output = _get_underlying_balances( metaregistry, pool, registry, base_pool_registry, max_coins ) @@ -75,18 +68,14 @@ def _test_underlying_balances_getter( underlying_decimals = metaregistry.get_underlying_decimals(pool) for idx, registry_value in enumerate(actual_output): - try: - assert registry_value == pytest.approx( metaregistry_output[idx] * 10 ** (18 - underlying_decimals[idx]) ) except AssertionError: - if pool in EXCEPTION_POOLS: - warnings.warn("Skipping test for pool: {}".format(pool)) pytest.skip( "Unresolved output from Borky pool: {}".format(pool) @@ -151,7 +140,6 @@ def test_crypto_factory_pools( crypto_factory, max_coins, ): - pre_test_checks(populated_metaregistry, crypto_factory_pool) _test_underlying_balances_getter( diff --git a/tests/mainnet/metaregistry/api/test_get_underlying_coins.py b/tests/mainnet/metaregistry/api/test_get_underlying_coins.py index 4146bcd..e57af26 100644 --- a/tests/mainnet/metaregistry/api/test_get_underlying_coins.py +++ b/tests/mainnet/metaregistry/api/test_get_underlying_coins.py @@ -2,30 +2,26 @@ import boa from boa import BoaError + from tests.utils import ZERO_ADDRESS def _get_underlying_coins( registry, base_pool_registry_updated, pool, max_coins ): - coins = registry.get_coins(pool) underlying_coins = [ZERO_ADDRESS] * max_coins for idx, coin in enumerate(coins): - base_pool = base_pool_registry_updated.get_base_pool_for_lp_token(coin) if base_pool == ZERO_ADDRESS: - underlying_coins[idx] = coin else: - basepool_coins = base_pool_registry_updated.get_coins(base_pool) for bp_coin in basepool_coins: - if bp_coin == ZERO_ADDRESS: break @@ -38,9 +34,7 @@ def _get_underlying_coins( def _check_fetched_underlying_coins(registry, pool, underlying_coins): - try: - registry_underlying_coins = registry.get_underlying_coins(pool) if registry_underlying_coins != underlying_coins: warnings.warn(f"Pool {pool} might be a lending pool.") @@ -71,7 +65,6 @@ def test_stable_registry_pools( stable_registry, max_coins, ): - metaregistry_output = populated_metaregistry.get_underlying_coins( stable_registry_pool ) @@ -96,7 +89,6 @@ def test_stable_factory_pools( stable_factory, max_coins, ): - metaregistry_output = populated_metaregistry.get_underlying_coins( stable_factory_pool ) @@ -121,7 +113,6 @@ def test_crypto_registry_pools( crypto_registry, max_coins, ): - metaregistry_output = populated_metaregistry.get_underlying_coins( crypto_registry_pool ) @@ -146,7 +137,6 @@ def test_crypto_factory_pools( crypto_factory, max_coins, ): - metaregistry_output = populated_metaregistry.get_underlying_coins( crypto_factory_pool ) diff --git a/tests/mainnet/metaregistry/api/test_get_underlying_decimals.py b/tests/mainnet/metaregistry/api/test_get_underlying_decimals.py index 97e0383..c4f23bf 100644 --- a/tests/mainnet/metaregistry/api/test_get_underlying_decimals.py +++ b/tests/mainnet/metaregistry/api/test_get_underlying_decimals.py @@ -1,5 +1,6 @@ import boa import pytest + from tests.utils import ZERO_ADDRESS EXCEPTIONS = { @@ -16,7 +17,6 @@ def _test_underlying_decimals_getter(metaregistry, registry, pool): - metaregistry_output = metaregistry.get_underlying_decimals(pool) assert metaregistry_output[1] != 0 # there has to be a second coin! @@ -27,7 +27,6 @@ def _test_underlying_decimals_getter(metaregistry, registry, pool): underlying_coins = metaregistry.get_underlying_coins(pool) actual_output = [] for i in range(len(underlying_coins)): - if underlying_coins[i] == ZERO_ADDRESS: actual_output.append(0) continue diff --git a/tests/mainnet/metaregistry/api/test_get_virtual_price.py b/tests/mainnet/metaregistry/api/test_get_virtual_price.py index 5fe807a..b7ca097 100644 --- a/tests/mainnet/metaregistry/api/test_get_virtual_price.py +++ b/tests/mainnet/metaregistry/api/test_get_virtual_price.py @@ -2,17 +2,15 @@ import boa import pytest -from tests.utils import ZERO_ADDRESS +from tests.utils import ZERO_ADDRESS # ---- sanity checks since vprice getters can revert for specific pools states ---- def _check_pool_has_no_liquidity(metaregistry, pool, pool_balances, lp_token): - # skip if pool has little to no liquidity, since vprice queries will most likely bork: if sum(pool_balances) == 0: - with ape.reverts(): metaregistry.get_virtual_price_from_lp_token(lp_token) @@ -28,12 +26,10 @@ def _check_pool_has_no_liquidity(metaregistry, pool, pool_balances, lp_token): def _check_skem_tokens_with_weird_decimals( metaregistry, pool, lp_token, pool_balances, coins, coin_decimals ): - # check if pool balances after accounting for decimals is legible. # some scam tokens can have weird token properties (e.g. ELONX) pool_balances_float = [] for i in range(len(pool_balances)): - if coins[i] == ZERO_ADDRESS: break @@ -60,7 +56,6 @@ def _check_pool_is_depegged( coin_decimals, lp_token, ): - for i in range(len(pool_balances)): # check if pool balances are skewed: vprice calc will bork if one of the coin # balances is close to zero. @@ -77,14 +72,15 @@ def _check_pool_is_depegged( f"skewed pool: {pool} as num coins (decimals divided) at index {i} is " f"{pool_balances[i] / 10 ** coin_decimals[i]}" ) - except AssertionError: # ok to catch this assertion error since we continue testing + except ( + AssertionError + ): # ok to catch this assertion error since we continue testing warnings.warn( "pool virtual price getter did not revert. continuing test" ) def pre_test_checks(metaregistry, pool): - pool_balances = metaregistry.get_balances(pool) lp_token = metaregistry.get_lp_token(pool) @@ -115,7 +111,6 @@ def pre_test_checks(metaregistry, pool): def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - # if checks fail, pytest skips, else lp_token is returned: lp_token = pre_test_checks(populated_metaregistry, stable_registry_pool) actual_output = stable_registry.get_virtual_price_from_lp_token(lp_token) @@ -128,7 +123,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, curve_pool ): - # if checks fail, pytest skips, else lp_token is returned: lp_token = pre_test_checks(populated_metaregistry, stable_factory_pool) @@ -146,7 +140,6 @@ def test_stable_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - # if checks fail, pytest skips, else lp_token is returned: lp_token = pre_test_checks(populated_metaregistry, crypto_registry_pool) actual_output = crypto_registry.get_virtual_price_from_lp_token(lp_token) @@ -159,7 +152,6 @@ def test_crypto_registry_pools( def test_crypto_factory_pools( populated_metaregistry, crypto_factory_pool, curve_pool ): - # if checks fail, pytest skips, else lp_token is returned: lp_token = pre_test_checks(populated_metaregistry, crypto_factory_pool) actual_output = curve_pool(crypto_factory_pool).get_virtual_price() diff --git a/tests/mainnet/metaregistry/api/test_pool_is_metapool.py b/tests/mainnet/metaregistry/api/test_pool_is_metapool.py index 5393737..4847596 100644 --- a/tests/mainnet/metaregistry/api/test_pool_is_metapool.py +++ b/tests/mainnet/metaregistry/api/test_pool_is_metapool.py @@ -4,7 +4,6 @@ def test_stable_registry_pools( populated_metaregistry, stable_registry_pool, stable_registry ): - actual_output = stable_registry.is_meta(stable_registry_pool) metaregistry_output = populated_metaregistry.is_meta(stable_registry_pool) assert actual_output == metaregistry_output @@ -13,7 +12,6 @@ def test_stable_registry_pools( def test_stable_factory_pools( populated_metaregistry, stable_factory_pool, stable_factory ): - actual_output = stable_factory.is_meta(stable_factory_pool) metaregistry_output = populated_metaregistry.is_meta(stable_factory_pool) assert actual_output == metaregistry_output @@ -22,7 +20,6 @@ def test_stable_factory_pools( def test_crypto_registry_pools( populated_metaregistry, crypto_registry_pool, crypto_registry ): - actual_output = crypto_registry.is_meta(crypto_registry_pool) metaregistry_output = populated_metaregistry.is_meta(crypto_registry_pool) assert actual_output == metaregistry_output diff --git a/tests/mainnet/metaregistry/test_base_registry_tracking.py b/tests/mainnet/metaregistry/test_base_registry_tracking.py index 93cbcc8..20e6ee2 100644 --- a/tests/mainnet/metaregistry/test_base_registry_tracking.py +++ b/tests/mainnet/metaregistry/test_base_registry_tracking.py @@ -34,8 +34,7 @@ def test_new_crypto_factory_pool( assert ( metaregistry.get_coins(new_pool) - == [tokens["dai"], lp_tokens["cvxFXSFXS-f"]] - + [ZERO_ADDRESS] * 6 + == [tokens["dai"], lp_tokens["cvxFXSFXS-f"]] + [ZERO_ADDRESS] * 6 ) assert test_pool_name in metaregistry.get_pool_name(new_pool) assert metaregistry.get_pool_from_lp_token(lp_token) == new_pool diff --git a/tests/mainnet/registries/test_add_remove_basepool.py b/tests/mainnet/registries/test_add_remove_basepool.py index abe0e06..516d55c 100644 --- a/tests/mainnet/registries/test_add_remove_basepool.py +++ b/tests/mainnet/registries/test_add_remove_basepool.py @@ -1,11 +1,11 @@ import boa + from tests.utils import ZERO_ADDRESS def test_revert_unauthorised_add_base_pool( owner, unauthorised_address, base_pools ): - base_pool_registry = ape.project.BasePoolRegistry.deploy(sender=owner) base_pool_data = base_pools["tripool"] @@ -22,7 +22,6 @@ def test_revert_unauthorised_add_base_pool( def test_add_basepool(owner, base_pools, tokens): - base_pool_registry = ape.project.BasePoolRegistry.deploy(sender=owner) base_pool_count = base_pool_registry.base_pool_count() @@ -64,7 +63,6 @@ def test_add_basepool(owner, base_pools, tokens): def test_add_basepool_with_legacy_abi(owner, base_pools, tokens): - base_pool_registry = ape.project.BasePoolRegistry.deploy(sender=owner) base_pool_data = base_pools["sbtc"] @@ -95,7 +93,6 @@ def test_add_basepool_with_legacy_abi(owner, base_pools, tokens): def test_revert_unauthorised_remove_base_pool( populated_base_pool_registry, unauthorised_address, base_pools ): - tripool_address = base_pools["tripool"]["pool"] assert ( @@ -109,7 +106,6 @@ def test_revert_unauthorised_remove_base_pool( def test_remove_base_pool(populated_base_pool_registry, owner, base_pools): - tripool_address = base_pools["tripool"]["pool"] tripool_lp_token = base_pools["tripool"]["lp_token"] diff --git a/tests/mainnet/registries/test_add_remove_metapool.py b/tests/mainnet/registries/test_add_remove_metapool.py index ae12b1c..d127c40 100644 --- a/tests/mainnet/registries/test_add_remove_metapool.py +++ b/tests/mainnet/registries/test_add_remove_metapool.py @@ -1,4 +1,5 @@ import boa + from tests.utils import ZERO_ADDRESS @@ -11,7 +12,6 @@ def test_add_metapool( base_pools, tokens, ): - crypto_registry = ape.project.CryptoRegistryV1.deploy( address_provider, populated_base_pool_registry, sender=owner ) @@ -160,7 +160,6 @@ def test_add_metapool( ] for coin_a in coins: for coin_b in coins: - # if both coins are the same, then it should return ZERO_ADDRESS: if coin_a == coin_b: assert ( @@ -207,7 +206,6 @@ def test_remove_metapool( base_pools, tokens, ): - crypto_registry = ape.project.CryptoRegistryV1.deploy( address_provider, populated_base_pool_registry, sender=owner ) @@ -253,18 +251,12 @@ def test_remove_metapool( ) # one pool should be gone assert crypto_registry.get_zap(eurt3crv["pool"]) == ZERO_ADDRESS - assert ( - crypto_registry.get_lp_token(eurt3crv["pool"]) - == ZERO_ADDRESS - ) + assert crypto_registry.get_lp_token(eurt3crv["pool"]) == ZERO_ADDRESS assert ( crypto_registry.get_pool_from_lp_token(eurt3crv["lp_token"]) == ZERO_ADDRESS ) - assert ( - crypto_registry.get_base_pool(eurt3crv["pool"]) - == ZERO_ADDRESS - ) + assert crypto_registry.get_base_pool(eurt3crv["pool"]) == ZERO_ADDRESS assert not crypto_registry.is_meta(eurt3crv["pool"]) assert crypto_registry.get_pool_name(eurt3crv["pool"]) == "" @@ -274,17 +266,11 @@ def test_remove_metapool( assert crypto_registry.get_underlying_decimals(eurt3crv["pool"]) == [0] * 8 # gauge checks: - assert ( - crypto_registry.get_gauges(eurt3crv["pool"])[0][0] - == ZERO_ADDRESS - ) + assert crypto_registry.get_gauges(eurt3crv["pool"])[0][0] == ZERO_ADDRESS assert crypto_registry.get_gauges(eurt3crv["pool"])[1][0] == 0 # coin checks: - assert ( - crypto_registry.get_coins(eurt3crv["pool"]) - == [ZERO_ADDRESS] * 8 - ) + assert crypto_registry.get_coins(eurt3crv["pool"]) == [ZERO_ADDRESS] * 8 assert ( crypto_registry.get_underlying_coins(eurt3crv["pool"]) == [ZERO_ADDRESS] * 8 @@ -300,7 +286,6 @@ def test_remove_metapool( # find pool for coins: for coin_a in coins: for coin_b in coins: - assert crypto_registry.get_coin_indices( eurt3crv["pool"], coin_a, coin_b ) == ( diff --git a/tests/mainnet/registries/test_add_remove_pool.py b/tests/mainnet/registries/test_add_remove_pool.py index 08cf4d3..ce0ffe8 100644 --- a/tests/mainnet/registries/test_add_remove_pool.py +++ b/tests/mainnet/registries/test_add_remove_pool.py @@ -1,11 +1,11 @@ import boa + from tests.utils import ZERO_ADDRESS def test_revert_unauthorised_add_pool( crypto_registry, unauthorised_address, crypto_registry_pools ): - pool_data = crypto_registry_pools["tricrypto2"] with ape.reverts(): @@ -25,7 +25,6 @@ def test_revert_unauthorised_add_pool( def test_revert_add_existing_pool( crypto_registry, owner, crypto_registry_pools ): - pool_data = crypto_registry_pools["tricrypto2"] with ape.reverts(): @@ -49,7 +48,6 @@ def test_add_pool( owner, tokens, ): - crypto_registry = ape.project.CryptoRegistryV1.deploy( address_provider.address, populated_base_pool_registry, sender=owner ) @@ -82,10 +80,7 @@ def test_add_pool( crypto_registry.get_pool_from_lp_token(pool_data["lp_token"]) == pool_data["pool"] ) - assert ( - crypto_registry.get_base_pool(pool_data["pool"]) - == ZERO_ADDRESS - ) + assert crypto_registry.get_base_pool(pool_data["pool"]) == ZERO_ADDRESS assert not crypto_registry.is_meta(pool_data["pool"]) assert crypto_registry.get_pool_name(pool_data["pool"]) == "tricrypto2" @@ -143,7 +138,6 @@ def test_add_pool( def test_revert_unauthorised_remove_pool( crypto_registry, unauthorised_address, crypto_registry_pools ): - with ape.reverts(): crypto_registry.remove_pool( crypto_registry_pools["tricrypto2"]["pool"], @@ -159,7 +153,6 @@ def test_remove_pool( max_coins, tokens, ): - crypto_registry = ape.project.CryptoRegistryV1.deploy( address_provider.address, populated_base_pool_registry, sender=owner ) @@ -205,13 +198,8 @@ def test_remove_pool( assert ( crypto_registry.pool_count() == pool_count - 1 ) # one pool should be gone - assert ( - crypto_registry.get_zap(tricrypto2["pool"]) == ZERO_ADDRESS - ) - assert ( - crypto_registry.get_lp_token(tricrypto2["pool"]) - == ZERO_ADDRESS - ) + assert crypto_registry.get_zap(tricrypto2["pool"]) == ZERO_ADDRESS + assert crypto_registry.get_lp_token(tricrypto2["pool"]) == ZERO_ADDRESS assert ( crypto_registry.get_pool_from_lp_token(tricrypto2["lp_token"]) == ZERO_ADDRESS @@ -220,10 +208,7 @@ def test_remove_pool( assert crypto_registry.get_n_coins(tricrypto2["pool"]) == 0 assert crypto_registry.get_decimals(tricrypto2["pool"]) == [0] * max_coins - assert ( - crypto_registry.get_gauges(tricrypto2["pool"])[0][0] - == ZERO_ADDRESS - ) + assert crypto_registry.get_gauges(tricrypto2["pool"])[0][0] == ZERO_ADDRESS assert crypto_registry.get_gauges(tricrypto2["pool"])[1][0] == 0 assert ( @@ -233,7 +218,6 @@ def test_remove_pool( for coin_i in [tokens["usdt"], tokens["wbtc"], tokens["weth"]]: for coin_j in [tokens["usdt"], tokens["wbtc"], tokens["weth"]]: - assert crypto_registry.get_coin_indices( tricrypto2["pool"], coin_i, coin_j ) == ( diff --git a/tests/utils.py b/tests/utils.py index d445a28..4583640 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -26,11 +26,21 @@ def get_deployed_contract(contract_abi: str, address: str) -> VyperContract: :param contract_abi: The name of the contract to load. :param address: The address of the deployed contract. """ - file_name = path.join(BASE_DIR, f"contracts/mainnet/abi/{contract_abi}.json") + file_name = path.join( + BASE_DIR, f"contracts/mainnet/abi/{contract_abi}.json" + ) return boa.load_abi(file_name).at(address) -def deploy_contract(contract: str, *args, sender: Union[LocalAccount, str], directory: str = ".", **kwargs) -> VyperContract: - file_name = path.join(BASE_DIR, f"contracts/mainnet/{directory}/{contract}.vy") +def deploy_contract( + contract: str, + *args, + sender: Union[LocalAccount, str], + directory: str = ".", + **kwargs, +) -> VyperContract: + file_name = path.join( + BASE_DIR, f"contracts/mainnet/{directory}/{contract}.vy" + ) boa.env.eoa = sender if isinstance(sender, str) else sender.address return boa.load(file_name, *args, **kwargs)