Skip to content

Commit 4f4a541

Browse files
fix(rofl-client): default encrypt to true in Python client
1 parent 4826700 commit 4f4a541

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

rofl-client/py/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ Fetches or generates a cryptographic key from ROFL.
7575
- **Returns:** The private key as a hex string
7676
- **Raises:** `httpx.HTTPStatusError` if the request fails
7777

78-
##### `async sign_submit(tx: TxParams, encrypt: bool = False) -> dict[str, Any]`
78+
##### `async sign_submit(tx: TxParams, encrypt: bool = True) -> dict[str, Any]`
7979

8080
Sign the given Ethereum transaction with an endorsed ephemeral key and submit it to Sapphire.
8181

8282
Note: Transaction nonce and gas price are ignored.
8383

8484
- **Parameters:**
8585
- `tx`: Transaction parameters
86-
- `encrypt`: End-to-end encrypt the transaction before submitting (default: False)
86+
- `encrypt`: End-to-end encrypt the transaction before submitting (default: True)
8787
- **Returns:** Deserialized response data object
8888
- **Raises:** `httpx.HTTPStatusError` if the request fails
8989
- **Raises:** `cbor2.CBORDecodeValueError` If the response data is invalid
@@ -125,4 +125,4 @@ Publishing to PyPI is fully automated via GitHub Actions.
125125

126126
## License
127127

128-
Licensed under the Apache License, Version 2.0. See `LICENSE` for details or visit http://www.apache.org/licenses/LICENSE-2.0.
128+
Licensed under the Apache License, Version 2.0. See `LICENSE` for details or visit http://www.apache.org/licenses/LICENSE-2.0.

rofl-client/py/src/oasis_rofl_client/rofl_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ async def generate_key(
130130
async def sign_submit(
131131
self,
132132
tx: TxParams,
133-
encrypt: bool = False,
133+
encrypt: bool = True,
134134
) -> dict[str, Any]:
135135
"""Sign the given Ethereum transaction with an endorsed ephemeral key and submit it to Sapphire.
136136
137137
Note: Transaction nonce and gas price are ignored.
138138
139139
:param tx: Transaction parameters
140-
:param encrypt: End-to-end encrypt the transaction before submitting (default: False)
140+
:param encrypt: End-to-end encrypt the transaction before submitting (default: True)
141141
:returns: Deserialized response data object.
142142
:raises httpx.HTTPStatusError: If the request fails
143143
:raises cbor2.CBORDecodeValueError: If the response data is invalid

rofl-client/py/tests/test_client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,33 @@ async def test_sign_submit(self, mock_client_class):
299299
timeout=60.0,
300300
)
301301

302+
@patch("oasis_rofl_client.rofl_client.httpx.AsyncClient")
303+
async def test_sign_submit_default_encrypt_true(self, mock_client_class):
304+
"""sign_submit should default encrypt to True when omitted."""
305+
mock_response = MagicMock()
306+
mock_response.json.return_value = {"data": ""}
307+
mock_response.raise_for_status = MagicMock()
308+
309+
mock_client = AsyncMock()
310+
mock_client.post.return_value = mock_response
311+
mock_client_class.return_value.__aenter__.return_value = mock_client
312+
313+
client = RoflClient()
314+
tx: TxParams = {
315+
"from": "0x1234567890123456789012345678901234567890",
316+
"data": "0x",
317+
"gas": 21000,
318+
"gasPrice": 0,
319+
"value": 0,
320+
"nonce": 0,
321+
}
322+
323+
await client.sign_submit(tx) # no encrypt argument
324+
325+
mock_client.post.assert_called_once()
326+
_, kwargs = mock_client.post.call_args
327+
assert kwargs["json"]["encrypt"] is True
328+
302329
@patch("oasis_rofl_client.rofl_client.httpx.AsyncClient")
303330
async def test_get_metadata(self, mock_client_class):
304331
"""Test get_metadata method."""

rofl-client/ts/test/client.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,24 @@ describe('RoflClient', () => {
247247
expect(payload.tx.data.data).toBe('deadbeef'); // 0x stripped
248248
});
249249

250+
it('sign-submit defaults encrypt to true when opts are omitted', async () => {
251+
const calls: TransportRequest[] = [];
252+
const client = makeClient(calls);
253+
254+
await client.signAndSubmit({
255+
kind: 'eth',
256+
gas_limit: 1,
257+
to: '',
258+
value: 0,
259+
data: '0x',
260+
});
261+
262+
const call = calls.find((c) => c.path === '/rofl/v1/tx/sign-submit')!;
263+
expect(call).toBeTruthy();
264+
const payload = call.payload as any;
265+
expect(payload.encrypt).toBe(true);
266+
});
267+
250268
it('normalizes EthTx.value inputs precisely', async () => {
251269
const calls: TransportRequest[] = [];
252270
const client = makeClient(calls);

0 commit comments

Comments
 (0)