Skip to content

Commit

Permalink
allow contract source paths in kasmer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Nov 22, 2024
1 parent f947b13 commit 1397020
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/komet/komet.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def _exec_test(*, wasm: Path | None) -> None:
# We build the contract here, specifying where it's saved so we know where to find it.
# Knowing where the compiled contract is saved by default when building it would eliminate
# the need for this step, but at the moment I don't know how to retrieve that information.
child_wasms = _read_config_file(kasmer)
wasm = kasmer.build_soroban_contract(Path.cwd())
child_wasms = _read_config_file()

kasmer.deploy_and_run(wasm, child_wasms)

Expand All @@ -109,22 +109,30 @@ def _exec_prove_run(
child_wasms: tuple[Path, ...] = ()

if wasm is None:
child_wasms = _read_config_file(kasmer)
wasm = kasmer.build_soroban_contract(Path.cwd())
child_wasms = _read_config_file()

kasmer.deploy_and_prove(wasm, child_wasms, id, proof_dir, bug_report)

sys.exit(0)


def _read_config_file(dir_path: Path | None = None) -> tuple[Path, ...]:
def _read_config_file(kasmer: Kasmer, dir_path: Path | None = None) -> tuple[Path, ...]:
dir_path = Path.cwd() if dir_path is None else dir_path
config_path = dir_path / 'kasmer.json'

def get_wasm_path(c: Path) -> Path:
c = abs_or_rel_to(c, dir_path)
if c.is_file() and c.suffix == '.wasm':
return c
if c.is_dir():
return kasmer.build_soroban_contract(c)
raise ValueError(f'Invalid child contract path: {c}')

if config_path.is_file():
with open(config_path) as f:
config = json.load(f)
return tuple(abs_or_rel_to(Path(c), dir_path) for c in config['contracts'])
return tuple(get_wasm_path(Path(c)) for c in config['contracts'])

return ()

Expand Down

0 comments on commit 1397020

Please sign in to comment.