Skip to content

Commit

Permalink
feat: add sanity check (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa authored Jul 9, 2024
1 parent fba71dd commit ceaa9a9
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 88 deletions.
8 changes: 0 additions & 8 deletions .github/tests/blockscout.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,3 @@ optimism_package:
network_id: '3151910'
additional_services:
- blockscout
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- blockscout
18 changes: 2 additions & 16 deletions .github/tests/multiple_l2s.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
optimism_package:
- participants:
- el_type: op-geth
network_params:
- network_params:
name: op-rollup-one
network_id: '3151909'
additional_services: []
- participants:
- el_type: op-geth
network_params:
- network_params:
name: op-rollup-two
network_id: '3151910'
additional_services: []
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/op-erigon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@ optimism_package:
participants:
- el_type: op-erigon
cl_type: op-node
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/op-geth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@ optimism_package:
participants:
- el_type: op-geth
cl_type: op-node
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/op-nethermind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@ optimism_package:
- el_type: op-geth
- el_type: op-nethermind
cl_type: op-node
ethereum_package:
participants:
- el_type: geth
- el_type: nethermind
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/op-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,3 @@ optimism_package:
cl_type: op-node
- el_type: op-nethermind
cl_type: op-node
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/op-reth.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,3 @@ optimism_package:
participants:
- el_type: op-reth
cl_type: op-node
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
8 changes: 0 additions & 8 deletions .github/tests/single_l2.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
optimism_package:
participants:
- count: 2
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
15 changes: 9 additions & 6 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ def run(plan, args):
A full deployment of Optimism L2(s)
"""
plan.print("Parsing the L1 input args")
ethereum_args = args["ethereum_package"]

# If no args are provided, use the default values with minimal preset
ethereum_args = args.get(
"ethereum_package", {"network_params": {"preset": "minimal"}}
)
optimism_args = args.get("optimism_package", {})
# Deploy the L1
plan.print("Deploying a local L1")
l1 = ethereum_package.run(plan, ethereum_args)
Expand All @@ -41,20 +44,20 @@ def run(plan, args):

# Deploy L2s
plan.print("Deploying a local L2")
if type(args["optimism_package"]) == "dict":
if type(optimism_args) == "dict":
l2_services_suffix = "" # no suffix if one l2
l2_launcher.launch_l2(
plan,
l2_services_suffix,
args["optimism_package"],
optimism_args,
l1_config_env_vars,
l1_priv_key,
all_l1_participants[0].el_context,
)
elif type(args["optimism_package"]) == "list":
elif type(optimism_args) == "list":
seen_names = {}
seen_network_ids = {}
for l2_num, l2_args in enumerate(args["optimism_package"]):
for l2_num, l2_args in enumerate(optimism_args):
name = l2_args["network_params"]["name"]
network_id = l2_args["network_params"]["network_id"]
if name in seen_names:
Expand Down
9 changes: 0 additions & 9 deletions network_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,4 @@ optimism_package:
- el_type: op-erigon
- el_type: op-nethermind
additional_services:
- blockscout
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
- blockscout
2 changes: 1 addition & 1 deletion src/contracts/contract_deployer.star
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def deploy_l2_contracts(
):
chainspec_files_artifact = plan.upload_files(
src=CHAINSPEC_JQ_FILEPATH,
name="chainspec-config",
name="op-chainspec-config{0}".format(l2_services_suffix),
)

op_genesis = plan.run_sh(
Expand Down
3 changes: 3 additions & 0 deletions src/package_io/input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ ethereum_package_input_parser = import_module(
"github.com/ethpandaops/ethereum-package/src/package_io/input_parser.star"
)

sanity_check = import_module("./sanity_check.star")

DEFAULT_EL_IMAGES = {
"op-geth": "us-docker.pkg.dev/oplabs-tools-artifacts/images/op-geth:latest",
"op-reth": "parithoshj/op-reth:latest",
Expand Down Expand Up @@ -31,6 +33,7 @@ DEFAULT_ADDITIONAL_SERVICES = []


def input_parser(plan, input_args):
sanity_check.sanity_check(plan, input_args)
result = parse_network_params(plan, input_args)

return struct(
Expand Down
82 changes: 82 additions & 0 deletions src/package_io/sanity_check.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
PARTICIPANT_CATEGORIES = {
"participants": [
"el_type",
"el_image",
"cl_type",
"cl_image",
"count",
],
}

SUBCATEGORY_PARAMS = {
"network_params": [
"network",
"network_id",
"seconds_per_slot",
"name",
],
}

ADDITIONAL_SERVICES_PARAMS = [
"blockscout",
]


def deep_validate_params(plan, input_args, category, allowed_params):
if category in input_args:
for item in input_args[category]:
for param in item.keys():
if param not in allowed_params:
fail(
"Invalid parameter {0} for {1}. Allowed fields: {2}".format(
param, category, allowed_params
)
)


def validate_params(plan, input_args, category, allowed_params):
if category in input_args:
for param in input_args[category].keys():
if param not in allowed_params:
fail(
"Invalid parameter {0} for {1}. Allowed fields: {2}".format(
param, category, allowed_params
)
)


def sanity_check(plan, input_args):
# Checks participants
deep_validate_params(
plan, input_args, "participants", PARTICIPANT_CATEGORIES["participants"]
)

# Checks additional_services
if "additional_services" in input_args:
for additional_services in input_args["additional_services"]:
if additional_services not in ADDITIONAL_SERVICES_PARAMS:
fail(
"Invalid additional_services {0}, allowed fields: {1}".format(
additional_services, ADDITIONAL_SERVICES_PARAMS
)
)

# Checks subcategories
for subcategories in SUBCATEGORY_PARAMS.keys():
validate_params(
plan, input_args, subcategories, SUBCATEGORY_PARAMS[subcategories]
)
# Checks everything else
for param in input_args.keys():
combined_root_params = PARTICIPANT_CATEGORIES.keys() + SUBCATEGORY_PARAMS.keys()
combined_root_params.append("additional_services")

if param not in combined_root_params:
fail(
"Invalid parameter {0}, allowed fields {1}".format(
param, combined_root_params
)
)

# If everything passes, print a message
plan.print("Sanity check for OP package passed")

0 comments on commit ceaa9a9

Please sign in to comment.