Skip to content

Commit

Permalink
Install pre-commit via docker
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Nov 22, 2023
1 parent eeacdb7 commit 4cc75a1
Show file tree
Hide file tree
Showing 48 changed files with 290 additions and 255 deletions.
78 changes: 78 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ __pycache__/
.DS_Store
venv/
bvenv/
.env
.env
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ repos:
args: ["--profile", "black", --line-length=79]

default_language_version:
python: python3.10
python: python3.11
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
FROM python:3.11-slim
FROM python:3.11-slim as base

WORKDIR /usr/app
RUN pip cache purge
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
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/AddressProvider.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,4 @@
"type": "function",
"gas": 12168
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/CryptoFactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,4 @@
}
]
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/CryptoRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,4 @@
],
"gas": 3366
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/GaugeController.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,4 +819,4 @@
"type": "function",
"gas": 2490
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/ProxyAdmin.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,4 @@
}
]
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/StableFactory.json
Original file line number Diff line number Diff line change
Expand Up @@ -1060,4 +1060,4 @@
],
"gas": 3708
}
]
]
2 changes: 1 addition & 1 deletion contracts/mainnet/abi/StableRegistry.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,4 @@
],
"gas": 2288
}
]
]
13 changes: 12 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 14 additions & 8 deletions scripts/boa_scripts/set_up_registries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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())

Expand Down
1 change: 0 additions & 1 deletion scripts/change_registry_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def cli():
@network_option()
@account_option()
def main(network, account):

# deploy basepool registry:
base_pool_registry = account.deploy(project.BasePoolRegistry)

Expand Down
1 change: 0 additions & 1 deletion scripts/deploy_crypto_registry_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
41 changes: 26 additions & 15 deletions scripts/setup_metaregistry.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4cc75a1

Please sign in to comment.