Skip to content

Commit

Permalink
feat: add sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasbusa committed Jul 5, 2024
1 parent fba71dd commit 015908a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 10 deletions.
10 changes: 5 additions & 5 deletions main.star
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run(plan, args):
"""
plan.print("Parsing the L1 input args")
ethereum_args = args["ethereum_package"]

optimism_args = args["optimism_package"]
# Deploy the L1
plan.print("Deploying a local L1")
l1 = ethereum_package.run(plan, ethereum_args)
Expand All @@ -41,20 +41,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
6 changes: 1 addition & 5 deletions network_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ optimism_package:
- el_type: op-erigon
- el_type: op-nethermind
additional_services:
- blockscout
- blockscout
ethereum_package:
participants:
- el_type: geth
- el_type: reth
network_params:
preset: minimal
additional_services:
- dora
- blockscout
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 015908a

Please sign in to comment.