Skip to content

Commit

Permalink
Merge pull request nucypher#317 from derekpierre/ci-job-scripts
Browse files Browse the repository at this point in the history
CI job for testing deployment functionality, and validate registries
  • Loading branch information
derekpierre authored Aug 23, 2024
2 parents 96f24de + c24f375 commit 346f364
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 26 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ jobs:
with:
cache: "pip"
python-version: "3.11"
- run: pip install . -r requirements.txt
- run: pip install -e . -r requirements.txt

- name: Run Ape Tests
run: ape test

- name: Run Deployment Test
run: ape run ci deploy_child

- name: Run Registry Scripts to list contracts
run: |
ape run list_contracts --domain lynx
ape run list_contracts --domain tapir
ape run list_contracts --domain mainnet
- name: Build npm package
run: npm run build

Expand Down
33 changes: 33 additions & 0 deletions deployment/constructor_params/ci/child.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
deployment:
name: ci-child
chain_id: 1337

artifacts:
dir: ./deployment/artifacts/
filename: ci.json

constants:
ONE_HOUR_IN_SECONDS: 3600
FORTY_THOUSAND_TOKENS_IN_WEI_UNITS: 40000000000000000000000
TEN_MILLION_TOKENS_IN_WEI_UNITS: 10000000000000000000000000 # https://www.youtube.com/watch?v=EJR1H5tf5wE
MAX_DKG_SIZE: 4

contracts:
- MockPolygonChild
- TACoChildApplication:
proxy:
constructor:
_rootApplication: $MockPolygonChild
_minimumAuthorization: $FORTY_THOUSAND_TOKENS_IN_WEI_UNITS
- LynxRitualToken:
constructor:
_totalSupplyOfTokens: $TEN_MILLION_TOKENS_IN_WEI_UNITS
- Coordinator:
proxy:
constructor:
_data: $encode:initialize,$ONE_HOUR_IN_SECONDS,$MAX_DKG_SIZE,$deployer
constructor:
_application: $TACoChildApplication
- GlobalAllowList:
constructor:
_coordinator: $Coordinator
61 changes: 36 additions & 25 deletions deployment/params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import typing
from abc import ABC, abstractmethod
from collections import namedtuple, OrderedDict
from collections import OrderedDict, namedtuple
from pathlib import Path
from typing import Any, List

Expand Down Expand Up @@ -480,7 +480,11 @@ class Transactor:
Represents an ape account plus validated/annotated transaction execution.
"""

def __init__(self, account: typing.Optional[AccountAPI] = None):
def __init__(self, account: typing.Optional[AccountAPI] = None, non_interactive: bool = False):
if non_interactive and not account:
raise ValueError("'non_interactive' can only be used if an account is provided")

self._non_interactive = non_interactive
if account is None:
self._account = select_account()
else:
Expand All @@ -502,13 +506,17 @@ def transact(self, method: ContractTransactionHandler, *args) -> ReceiptAPI:
else:
message = f"{base_message} with no arguments"
print(message)
_continue()

result = method(*args, sender=self._account,
# FIXME: Manual gas fees - #199
# max_priority_fee="3 gwei",
# max_fee="120 gwei"
)
if not self._non_interactive:
_continue()

result = method(
*args,
sender=self._account,
# FIXME: Manual gas fees - #199
# max_priority_fee="3 gwei",
# max_fee="120 gwei"
)
return result


Expand All @@ -526,7 +534,10 @@ def __init__(
path: Path,
verify: bool,
account: typing.Optional[AccountAPI] = None,
non_interactive: bool = False,
):
super().__init__(account, non_interactive)

check_plugins()
self.path = path
self.config = config
Expand All @@ -539,10 +550,13 @@ def __init__(
_Constants = namedtuple("_Constants", list(constants))
self.constants = _Constants(**constants)

super().__init__(account)
self._set_account(self._account)
self.verify = verify
self._confirm_start()
self._print_deployment_info()

if not self._non_interactive:
# Confirms the start of the deployment.
_continue()

@classmethod
def from_yaml(cls, filepath: Path, *args, **kwargs) -> "Deployer":
Expand Down Expand Up @@ -583,16 +597,19 @@ def _deploy_contract(
self, container: ContractContainer, resolved_params: OrderedDict
) -> ContractInstance:
contract_name = container.contract_type.name
_confirm_resolution(resolved_params, contract_name)
if not self._non_interactive:
_confirm_resolution(resolved_params, contract_name)
deployment_params = [container, *resolved_params.values()]
kwargs = self._get_kwargs()

deployer_account = self.get_account()
return deployer_account.deploy(*deployment_params,
# FIXME: Manual gas fees - #199
# max_priority_fee="3 gwei",
# max_fee="120 gwei",
**kwargs)
return deployer_account.deploy(
*deployment_params,
# FIXME: Manual gas fees - #199
# max_priority_fee="3 gwei",
# max_fee="120 gwei",
**kwargs,
)

def _deploy_proxy(
self,
Expand All @@ -615,12 +632,8 @@ def _deploy_proxy(
)
return contract_type_container.at(proxy_contract.address)

def upgrade(self, container: ContractContainer, proxy_address, data=b'') -> ContractInstance:

admin_slot = chain.provider.get_storage_at(
address=proxy_address,
slot=EIP1967_ADMIN_SLOT
)
def upgrade(self, container: ContractContainer, proxy_address, data=b"") -> ContractInstance:
admin_slot = chain.provider.get_storage_at(address=proxy_address, slot=EIP1967_ADMIN_SLOT)

if admin_slot == EMPTY_BYTES32:
raise ValueError(
Expand Down Expand Up @@ -651,8 +664,7 @@ def finalize(self, deployments: List[ContractInstance]) -> None:
if self.verify:
verify_contracts(contracts=deployments)

def _confirm_start(self) -> None:
"""Confirms the start of the deployment."""
def _print_deployment_info(self):
print(
f"Account: {self.get_account().address}",
f"Config: {self.path}",
Expand All @@ -664,4 +676,3 @@ def _confirm_start(self) -> None:
f"Gas Price: {networks.provider.gas_price}",
sep="\n",
)
_continue()
45 changes: 45 additions & 0 deletions scripts/ci/deploy_child.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/python3
from ape import accounts, networks, project

from deployment.constants import CONSTRUCTOR_PARAMS_DIR
from deployment.params import Deployer

VERIFY = False
CONSTRUCTOR_PARAMS_FILEPATH = CONSTRUCTOR_PARAMS_DIR / "ci" / "child.yml"


def main():
with networks.ethereum.local.use_provider("test"):
test_account = accounts.test_accounts[0]

deployer = Deployer.from_yaml(
filepath=CONSTRUCTOR_PARAMS_FILEPATH,
verify=VERIFY,
account=test_account,
non_interactive=True,
)

mock_polygon_child = deployer.deploy(project.MockPolygonChild)

taco_child_application = deployer.deploy(project.TACoChildApplication)

deployer.transact(mock_polygon_child.setChildApplication, taco_child_application.address)

ritual_token = deployer.deploy(project.LynxRitualToken)

coordinator = deployer.deploy(project.Coordinator)

global_allow_list = deployer.deploy(project.GlobalAllowList)

deployments = [
mock_polygon_child,
taco_child_application,
ritual_token,
coordinator,
global_allow_list,
]

deployer.finalize(deployments=deployments)

# remove registry file now that task is complete
deployer.registry_filepath.unlink()

0 comments on commit 346f364

Please sign in to comment.