hiero-ledger / hiero-ledger/hiero-sdk-python

feat(tck): implement updateFile JSON-RPC method

Open
#2,491 8 comments 0 reactions 1 assignee Claimed by @anchit-goel View on GitHub
approved lang: python scope: TCK skill: beginner
Dominant language
Python
Stars
63
Forks
298
Avg merge
3d 18h
Merged PRs (30d)
38

Description

**Problem**

The TCK server does not implement `updateFile`, so the TCK driver's `FileUpdateTransaction` suite cannot run against the Python SDK. The SDK transaction (`src/hiero_sdk_python/file/file_update_transaction.py`) already exists with all needed setters: `set_file_id`, `set_keys`, `set_expiration_time`, `set_contents`, `set_file_memo`.

**Blocked by #2488** (`createFile`) — this handler goes in the file-service TCK modules #2488 creates, and the driver needs a created file to update. Use #2489 (`getFileContents`) / #2490 (`getFileInfo`) to verify update results end-to-end.

**Solution**

Add an `updateFile` handler wrapping `FileUpdateTransaction`. Structurally identical to the `createFile` handler from #2488, plus `fileId`, returning status only.

*Method contract (from the spec):* all inputs optional.

| Input | Type | Notes |
|---|---|---|
| `fileId` | string | File to update |
| `keys` | string[] | DER-encoded hex; **threshold keys not allowed** for update (unlike create) |
| `contents` | string | New contents; **empty string means "leave unchanged"** |
| `expirationTime` | string | Seconds since epoch; must be strictly later than current |
| `memo` | string | UTF-8, max 100 bytes |
| `commonTransactionParams` | object | |

Output: `status` — reuse `StatusOnlyResponse` from `tck/response/base.py`; no new response class needed.

*Implementation steps:*

1. Add `UpdateFileParams(BaseTransactionParams)` to `tck/param/file.py` — mirror `CreateFileParams` plus `fileId`.
2. Add the handler to `tck/handlers/file.py`: parse `fileId` via `FileId.from_string()`, map the rest as in `createFile`, execute, return `StatusOnlyResponse(ResponseCode(receipt.status).name)`.
3. Add a unit test under `tests/tck/`.

*Details that matter:*

- **`contents=""` must NOT clear the file.** Per the spec, empty string means content unchanged — so parse with `non_empty_string_or_none()` (`tck/util/param_utils.py`) so `""` becomes `None` and `set_contents` is never called with it. Add a comment explaining this, since it looks like a bug otherwise.
- **`expirationTime` validation is server-side** — the network rejects non-increasing values; don't validate client-side, let the error propagate.
- **Threshold keys** are disallowed by the spec for update but `get_key_from_string()` won't reject them — the network will. Acceptable; note it in the PR.
- Only call setters for non-`None` params: the spec distinguishes omitted fields (unchanged) from set fields.

**Acceptance criteria**

- [ ] `updateFile` registered and dispatchable
- [ ] `contents=""` leaves file content unchanged (verified via `getFileContents`)
- [ ] All inputs mapped; omitted params leave fields untouched
- [ ] Invalid `fileId` format → SDK internal error; non-existent ID → network `INVALID_FILE_ID`
- [ ] Unit test added; `uv run pytest tests/tck -q` passes

Spec: https://github.com/hiero-ledger/hiero-sdk-tck/blob/main/docs/test-specifications/file-service/FileUpdateTransaction.md

JS reference: https://github.com/hiero-ledger/hiero-sdk-js/blob/main/tck/methods/file.ts (`updateFile`)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.