Skip to content

Commit 31bccf6

Browse files
authored
fix: Contract name underscoring
2 parents dc4020e + 034749c commit 31bccf6

File tree

9 files changed

+38
-21
lines changed

9 files changed

+38
-21
lines changed

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jsonschema = "^4.15.0"
2424
graphlib-backport = "^1.0.3"
2525
jwskate = ">=0.4.1,<0.6.0"
2626
makefun = "^1.15.0"
27+
urllib3 = "==1.26.16"
2728

2829
[tool.poetry.dev-dependencies]
2930
coverage = "^7.0.3"

src/jenesis/cmd/add/deployment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def run(args: argparse.Namespace):
2626

2727
selected_contract = parse_contract(project_root , args.contract)
2828

29-
3029
for (profile_name, profile) in cfg.profiles.items():
3130
network_name = profile.network.name
3231
for deployment in args.deployments:

src/jenesis/cmd/compile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from jenesis.contracts.schema import generate_schemas, load_contract_schema
1313
from jenesis.tasks.image import image_exists, pull_image
1414

15+
1516
def _compute_init_checksum(path, contract_name):
1617
schema_path = os.path.join(path, "contracts", contract_name)
1718
schema = load_contract_schema(schema_path)
@@ -44,7 +45,7 @@ def run(args: argparse.Namespace):
4445
print(term.red("Unable to detect any contracts"))
4546
return 1
4647

47-
init_checksums = {contract.name: _compute_init_checksum(project_path, contract.name) for contract in contracts}
48+
init_checksums = {contract.name: _compute_init_checksum(project_path, contract.variable_name) for contract in contracts}
4849

4950
if is_workspace(project_path):
5051
if not image_exists(WORKSPACE_BUILD_IMAGE):
@@ -65,7 +66,7 @@ def run(args: argparse.Namespace):
6566

6667
cfg = Config.load(os.getcwd())
6768
for contract in contracts:
68-
if _compute_init_checksum(project_path, contract.name) != init_checksums[contract.name]:
69+
if _compute_init_checksum(project_path, contract.variable_name) != init_checksums[contract.name]:
6970
# update project file
7071
for (profile_name, profile) in cfg.profiles.items():
7172
network_name = profile.network.name

src/jenesis/cmd/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def load_shell_globals(cfg: Config, selected_profile: Profile) -> dict:
3838
shell_globals = {}
3939
contract_instances = {}
4040

41-
contracts = {contract.name: contract for contract in detect_contracts(PROJECT_PATH)}
41+
contracts = {contract.variable_name: contract for contract in detect_contracts(PROJECT_PATH)}
4242

4343
deployments = selected_profile.deployments
4444

src/jenesis/config/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
@dataclass
2929
class Deployment:
30-
name: str # internal: the name for the deployment
30+
name: str # internal: the name for the deployment
3131
contract: str # internal: the name of the contract to deploy
3232
network: str # internal: the name of the network to deploy to
3333
deployer_key: str # config: the name of the key to use for deployment
@@ -402,7 +402,7 @@ def add_profile(profile: str, network_name: str):
402402
toml.dump(data, toml_file)
403403

404404
@staticmethod
405-
def add_contract(project_root: str, template: str, name: str, branch: str) -> Contract:
405+
def add_contract(project_root: str, template: str, name: str, branch: Optional[str]) -> Optional[Contract]:
406406

407407
contract_path = os.path.join(project_root, 'contracts', name)
408408

@@ -425,9 +425,11 @@ def add_contract(project_root: str, template: str, name: str, branch: str) -> Co
425425
contract_template_path = os.path.join(temp_clone_path, "contracts", template)
426426
if not os.path.isdir(contract_template_path):
427427
print(f"Unknown template {template}: expecting one of {set(available_templates)}")
428-
return
428+
return None
429429
print("Downloading template...complete")
430430

431+
name_underscored = name.replace("-", "_")
432+
431433
# process all the files as part of the template
432434
print("Rendering template...")
433435
for root, _, files in os.walk(contract_template_path):
@@ -440,12 +442,11 @@ def add_contract(project_root: str, template: str, name: str, branch: str) -> Co
440442
with open(file_path, "r", encoding="utf8") as input_file:
441443
with open(output_filepath, "w", encoding="utf8") as output_file:
442444
contents = input_file.read()
443-
444445
# replace the templating parameters here
445446
if file_path.endswith(".toml"):
446447
contents = contents.replace("<<NAME>>", name)
447448
else:
448-
contents = contents.replace("<<NAME>>", name.replace("-", "_"))
449+
contents = contents.replace("<<NAME>>", name_underscored)
449450

450451
output_file.write(contents)
451452
print("Rendering template...complete")

src/jenesis/contracts/__init__.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
import os.path
2-
from dataclasses import dataclass
3-
from typing import Optional
2+
from dataclasses import dataclass, field
3+
from typing import Optional, Dict, Any
44

55
from cosmpy.aerial.contract import _compute_digest
66

77

8+
SchemaType = Dict[str, Any]
9+
10+
811
@dataclass
912
class Contract:
1013
name: str
14+
variable_name: str = field(init=False)
1115
source_path: str
1216
binary_path: str
1317
cargo_root: str
14-
schema: dict
18+
schema: SchemaType
19+
instantiate_schema: Optional[SchemaType] = field(default=None, init=False)
20+
query_schema: Optional[SchemaType] = field(default=None, init=False)
21+
execute_schema: Optional[SchemaType] = field(default=None, init=False)
1522

1623
def __post_init__(self):
24+
self.variable_name = self.to_variable_name(self.name)
1725
self.instantiate_schema = {}
1826
self.query_schema = {}
1927
self.execute_schema = {}
20-
2128
self.update_schema()
2229

23-
2430
def update_schema(self):
2531
# check for workspace-style schemas
2632
if self.name in self.schema:
@@ -54,6 +60,10 @@ def init_args(self) -> dict:
5460
def __repr__(self):
5561
return self.name
5662

63+
@classmethod
64+
def to_variable_name(cls, contract_name: str) -> str:
65+
return contract_name.replace("-", "_")
66+
5767

5868
def _extract_msgs(schema: dict) -> dict:
5969
msgs = {}
@@ -69,6 +79,7 @@ def _extract_msgs(schema: dict) -> dict:
6979
msgs[msg] = args
7080
return msgs
7181

82+
7283
def _get_msg_args(msg_schema):
7384
msg_args = {}
7485
args = msg_schema.get('properties', {}).keys()

src/jenesis/contracts/build.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def __init__(self, contract: Contract, optimize: bool, rebuild: bool, log: bool)
3737
def name(self) -> str:
3838
return self.contract.name
3939

40+
@property
41+
def variable_name(self) -> str:
42+
return self.contract.variable_name
43+
4044
def _is_out_of_date(self) -> bool:
4145
# pylint: disable=duplicate-code
4246
if self._rebuild:
@@ -56,7 +60,7 @@ def _is_out_of_date(self) -> bool:
5660

5761
def _schedule_container(self) -> Container:
5862
mounts = [
59-
Mount('/code/target', f'contract_{self.contract.name}_cache'),
63+
Mount('/code/target', f'contract_{self.contract.variable_name}_cache'),
6064
Mount('/usr/local/cargo/registry', 'registry_cache'),
6165
Mount('/code', os.path.abspath(self.contract.cargo_root), type='bind'),
6266
]

src/jenesis/contracts/detect.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def parse_contract(path: str, name: str) -> Contract:
3030
cargo_contents = toml.load(cargo_file)
3131

3232
# extract the contract name and replace hyphens with underscores
33-
contract_name = cargo_contents['package']['name'].replace("-", "_")
33+
contract_name = cargo_contents['package']['name']
3434

3535
source_path = os.path.abspath(os.path.join(contracts_folder, name))
3636
if is_workspace(path):
3737
cargo_root = path
3838
else:
3939
cargo_root = os.path.join(contracts_folder, name)
4040
artifacts_path = os.path.join(cargo_root, 'artifacts')
41-
binary_path = os.path.abspath(os.path.join(artifacts_path, f'{contract_name}.wasm'))
41+
binary_path = os.path.abspath(os.path.join(artifacts_path, f'{Contract.to_variable_name(contract_name)}.wasm'))
4242

4343
schema = load_contract_schema(source_path)
4444

0 commit comments

Comments
 (0)