Skip to content

Commit 16593c8

Browse files
committed
feat: adding get_operation_key
1 parent 1d62d09 commit 16593c8

File tree

8 files changed

+71
-18
lines changed

8 files changed

+71
-18
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
DELTADEFI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
1+
DELTADEFI_API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
2+
BASE_URL="http://localhost:8080"

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ submit_order_response = api.order.submit_place_order_transaction(signed_tx="<sig
7474
print(submit_order_response)
7575
```
7676

77+
## Development
78+
79+
### Tests
80+
81+
Testing sdk:
82+
83+
```sh
84+
DELTADEFI_API_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx make test
85+
```
86+
7787
## License
7888

7989
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at <http://www.apache.org/licenses/LICENSE-2.0>

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "deltadefi"
3-
version = "0.0.6"
3+
version = "0.0.7"
44
classifiers = [
55
"Intended Audience :: Developers",
66
"License :: OSI Approved :: Apache Software License",

src/deltadefi/clients/accounts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SubmitDepositTransactionResponse,
1717
SubmitWithdrawalTransactionResponse,
1818
)
19+
from deltadefi.responses.accounts import GetOperationKeyResponse
1920

2021

2122
class Accounts(API):
@@ -28,6 +29,17 @@ class Accounts(API):
2829
def __init__(self, api_key=None, base_url=None, **kwargs):
2930
super().__init__(api_key=api_key, base_url=base_url, **kwargs)
3031

32+
def get_operation_key(self, **kwargs) -> GetOperationKeyResponse:
33+
"""
34+
Get the encrypted operation key.
35+
36+
Returns:
37+
A GetOperationKeyResponse object containing the encrypted operation key and its hash.
38+
"""
39+
40+
url_path = "/operation-key"
41+
return self.send_request("GET", self.group_url_path + url_path, kwargs)
42+
3143
def create_new_api_key(self, **kwargs) -> CreateNewAPIKeyResponse:
3244
"""
3345
Create a new API key.

src/deltadefi/clients/clients.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ def __init__(
3030
"""
3131
if network == "mainnet":
3232
self.network_id = 1
33-
base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
33+
self.base_url = "https://api-dev.deltadefi.io" # TODO: input production link once available
3434
else:
3535
self.network_id = 0
36-
base_url = "https://api-dev.deltadefi.io"
36+
self.base_url = "https://api-dev.deltadefi.io"
37+
38+
if base_url:
39+
self.base_url = base_url
3740

3841
self.api_key = api_key
3942
self.wallet = wallet
40-
self.base_url = base_url
4143

4244
self.accounts = Accounts(base_url=base_url, api_key=api_key)
4345
self.app = App(base_url=base_url, api_key=api_key)

src/deltadefi/responses/accounts.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ class CreateNewAPIKeyResponse:
1414
api_key: str
1515

1616

17+
@dataclass
18+
class GetOperationKeyResponse:
19+
encrypted_operation_key: str
20+
operation_key_hash: str
21+
22+
1723
@dataclass
1824
class BuildDepositTransactionResponse:
1925
tx_hex: str

tests/clients/test_accounts.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
11
# flake8: noqa
2-
# get api_key from env
32
import os
43
import unittest
54

65
from deltadefi.clients import ApiClient
76
from deltadefi.responses import GetAccountBalanceResponse
8-
9-
api_key = os.getenv("DELTADEFI_API_KEY")
7+
from deltadefi.responses.accounts import GetOperationKeyResponse
108

119

1210
class TestAccounts(unittest.TestCase):
1311

14-
def test_get_account_balance(self):
12+
def setUp(self):
13+
api_key = os.getenv("DELTADEFI_API_KEY")
14+
base_url = os.getenv("BASE_URL", "http://localhost:8080")
15+
print(api_key)
1516
if not api_key:
1617
self.skipTest("DELTADEFI_API_KEY not set in environment variables")
18+
self.api = ApiClient(api_key=api_key, base_url=base_url)
1719

18-
# Arrange
19-
api = ApiClient(api_key=api_key)
20+
def test_get_operation_key(self):
21+
response: GetOperationKeyResponse = self.api.accounts.get_operation_key()
2022

21-
# Act
22-
response: GetAccountBalanceResponse = api.accounts.get_account_balance()
23+
# Assert
24+
print(f"response: {response}")
25+
self.assertIn("encrypted_operation_key", response)
26+
self.assertIn("operation_key_hash", response)
27+
28+
def test_get_account_balance(self):
29+
response: GetAccountBalanceResponse = self.api.accounts.get_account_balance()
2330
print(f"response: {response}")
2431

25-
# # Assert
26-
# print(f"response: {response}")
27-
# self.assertIn("token", response)
28-
# self.assertIn("is_first_time", response)
32+
# # Assert
33+
# print(f"response: {response}")
34+
# self.assertIn("token", response)
35+
# self.assertIn("is_first_time", response)
2936

3037

3138
if __name__ == "__main__":

0 commit comments

Comments
 (0)