Skip to content

Commit

Permalink
allow contract paths in kasmer.json and build from source
Browse files Browse the repository at this point in the history
  • Loading branch information
bbyalcinkaya committed Nov 22, 2024
1 parent 93e5f8f commit 7ac0b08
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 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
2 changes: 1 addition & 1 deletion src/tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_run(program: Path, tmp_path: Path) -> None:
def test_komet(contract_path: Path, tmp_path: Path, concrete_kasmer: Kasmer) -> None:
# Given
contract_wasm = concrete_kasmer.build_soroban_contract(contract_path, tmp_path)
child_wasms = _read_config_file(contract_path)
child_wasms = _read_config_file(concrete_kasmer, contract_path)

# Then
if contract_path.stem.endswith('_fail'):
Expand Down

0 comments on commit 7ac0b08

Please sign in to comment.