Skip to content

Commit

Permalink
Undo commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed May 18, 2022
1 parent 47ce269 commit 55db210
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 33 deletions.
32 changes: 0 additions & 32 deletions erdpy/projects/project_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def build(self, options: Union[Dict[str, Any], None] = None) -> List[Path]:
self._ensure_dependencies_installed()
self.perform_build()
contract_paths = self._do_after_build_custom()
contract_paths = rename_wasm_files(contract_paths, self.options.get("wasm_name"))
self._do_after_build_core()
return contract_paths

Expand Down Expand Up @@ -155,39 +154,8 @@ def glob_files(folder: Path, pattern: str) -> List[Path]:
def exclude_files(files: List[Path], to_exclude: List[Path]) -> List[Path]:
return list(set(files).difference(to_exclude))

def rename_wasm_files(paths: List[Path], name: Union[str, None]) -> List[Path]:
if name is None:
return paths
new_paths = [adjust_wasm_filename(path, name) for path in paths]
for old_path, new_path in zip(paths, new_paths):
old_path.rename(new_path)
return new_paths

def get_contract_suffix(name: str) -> str:
for suffix in ["-view.wasm", ".wasm"]:
if name.endswith(suffix):
return suffix
return ""

def remove_suffix(name: str, suffix: str) -> str:
if not name.endswith(suffix) or len(suffix) == 0:
return name
return name[:-len(suffix)]

def adjust_wasm_filename(path: Path, name_hint: str) -> Path:
"""
Adjusts the wasm's filename by using a name hint
>>> adjust_wasm_filename(Path("test/my-contract.wasm"), "hello.wasm")
PosixPath('test/hello.wasm')
>>> adjust_wasm_filename(Path("test/my-contract-view.wasm"), "hello.wasm")
PosixPath('test/hello-view.wasm')
>>> adjust_wasm_filename(Path("test/my-contract-view.wasm"), "hello")
PosixPath('test/hello-view.wasm')
>>> adjust_wasm_filename(Path("test/my-contract.wasm"), "world-view.wasm")
PosixPath('test/world-view.wasm')
>>> adjust_wasm_filename(Path("test/my-contract-view.wasm"), "world-view.wasm")
PosixPath('test/world-view-view.wasm')
"""
new_name = remove_suffix(name_hint, ".wasm") + get_contract_suffix(path.name)
return path.with_name(new_name)
2 changes: 1 addition & 1 deletion erdpy/tests/test_cli_contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ testWasmName() {

${ERDPY} contract clean ${SANDBOX}/myadder-rs
assertFileDoesNotExist ${SANDBOX}/myadder-rs/output/myadder-2-rs.wasm || return 1
${ERDPY} contract build ${SANDBOX}/myadder-rs --cargo-target-dir=${TARGET_DIR} --wasm-name myadder-2-rs || return 1
${ERDPY} contract build ${SANDBOX}/myadder-rs --cargo-target-dir=${TARGET_DIR} --wasm-name myadder-2-rs.wasm || return 1
assertFileExists ${SANDBOX}/myadder-rs/output/myadder-2-rs.wasm || return 1
assertFileExists ${SANDBOX}/myadder-rs/output/myadder-rs.abi.json || return 1
}
Expand Down

0 comments on commit 55db210

Please sign in to comment.