55import asyncio
66import sys
77
8- from dstack_sdk import DstackClient , AsyncDstackClient , TappdClient , AsyncTappdClient , get_compose_hash , verify_env_encrypt_public_key
8+ from dstack_sdk import (
9+ DstackClient ,
10+ AsyncDstackClient ,
11+ TappdClient ,
12+ AsyncTappdClient ,
13+ get_compose_hash ,
14+ verify_env_encrypt_public_key ,
15+ )
916
1017
1118async def main ():
1219 print ("=== Python SDK Output Test ===" )
13-
20+
1421 try :
1522 # Test client get_key
1623 client = DstackClient ()
1724 print ("\n 1. Testing DstackClient.get_key()" )
18-
25+
1926 test_paths = [
2027 {"path" : "test/wallet" , "purpose" : "ethereum" },
2128 {"path" : "test/signing" , "purpose" : "solana" },
22- {"path" : "user/alice" , "purpose" : "mainnet" }
29+ {"path" : "user/alice" , "purpose" : "mainnet" },
2330 ]
24-
31+
2532 for test_case in test_paths :
2633 path , purpose = test_case ["path" ], test_case ["purpose" ]
2734 key_result = client .get_key (path , purpose )
2835 print (f"get_key('{ path } ', '{ purpose } '):" )
2936 print (f" key: { key_result .decode_key ().hex ()} " )
3037 print (f" signature_chain length: { len (key_result .signature_chain )} " )
31- print (f" signature_chain[0]: { key_result .decode_signature_chain ()[0 ].hex ()} " )
38+ print (
39+ f" signature_chain[0]: { key_result .decode_signature_chain ()[0 ].hex ()} "
40+ )
3241
3342 # Test viem integration (if available)
3443 print ("\n 2. Testing Viem Integration" )
3544 eth_key = client .get_key ("eth/test" , "wallet" )
36-
45+
3746 print ("\n 2.1 to_account (legacy):" )
3847 try :
3948 from dstack_sdk .ethereum import to_account
49+
4050 account = to_account (eth_key )
4151 print (f" address: { account .address } " )
4252 print (f" type: ethereum account" )
4353 except ImportError :
44- print (" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')" )
54+ print (
55+ " error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"
56+ )
4557 except Exception as error :
4658 print (f" error: { error } " )
47-
59+
4860 print ("\n 2.2 to_account_secure:" )
4961 try :
5062 from dstack_sdk .ethereum import to_account_secure
63+
5164 account_secure = to_account_secure (eth_key )
5265 print (f" address: { account_secure .address } " )
5366 print (f" type: ethereum account" )
5467 except ImportError :
55- print (" error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')" )
68+ print (
69+ " error: Ethereum integration not available (install with pip install 'dstack-sdk[eth]')"
70+ )
5671 except Exception as error :
5772 print (f" error: { error } " )
5873
5974 # Test solana integration (if available)
6075 print ("\n 3. Testing Solana Integration" )
6176 sol_key = client .get_key ("sol/test" , "wallet" )
62-
77+
6378 print ("\n 3.1 to_keypair (legacy):" )
6479 try :
6580 from dstack_sdk .solana import to_keypair
81+
6682 keypair = to_keypair (sol_key )
6783 print (f" publicKey: { keypair .pubkey ()} " )
6884 print (f" secretKey length: { len (bytes (keypair ))} " )
6985 print (f" secretKey (first 32 bytes): { bytes (keypair )[:32 ].hex ()} " )
7086 except ImportError :
71- print (" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')" )
87+ print (
88+ " error: Solana integration not available (install with pip install 'dstack-sdk[sol]')"
89+ )
7290 except Exception as error :
7391 print (f" error: { error } " )
74-
92+
7593 print ("\n 3.2 to_keypair_secure:" )
7694 try :
7795 from dstack_sdk .solana import to_keypair_secure
96+
7897 keypair_secure = to_keypair_secure (sol_key )
7998 print (f" publicKey: { keypair_secure .pubkey ()} " )
8099 print (f" secretKey length: { len (bytes (keypair_secure ))} " )
81100 print (f" secretKey (first 32 bytes): { bytes (keypair_secure )[:32 ].hex ()} " )
82101 except ImportError :
83- print (" error: Solana integration not available (install with pip install 'dstack-sdk[sol]')" )
102+ print (
103+ " error: Solana integration not available (install with pip install 'dstack-sdk[sol]')"
104+ )
84105 except Exception as error :
85106 print (f" error: { error } " )
86107
@@ -106,7 +127,9 @@ async def main():
106127 try :
107128 async_tappd_client = AsyncTappdClient ()
108129 print ("\n 4.3.1 AsyncTappdClient.get_key():" )
109- async_tappd_key = await async_tappd_client .get_key ("test/wallet" , "ethereum" )
130+ async_tappd_key = await async_tappd_client .get_key (
131+ "test/wallet" , "ethereum"
132+ )
110133 print (f" key: { async_tappd_key .decode_key ().hex ()} " )
111134 print (f" signature_chain length: { len (async_tappd_key .signature_chain )} " )
112135
@@ -140,16 +163,16 @@ async def main():
140163 "manifest_version" : 1 ,
141164 "name" : "test-app" ,
142165 "runner" : "docker-compose" ,
143- "docker_compose_file" : "services:\\ n app:\\ n image: test\\ n ports:\\ n - 8080:8080"
166+ "docker_compose_file" : "services:\\ n app:\\ n image: test\\ n ports:\\ n - 8080:8080" ,
144167 },
145168 {
146169 "manifest_version" : 1 ,
147- "name" : "another-app" ,
170+ "name" : "another-app" ,
148171 "runner" : "docker-compose" ,
149- "docker_compose_file" : "services:\\ n web:\\ n build: .\\ n environment:\\ n - NODE_ENV=production"
150- }
172+ "docker_compose_file" : "services:\\ n web:\\ n build: .\\ n environment:\\ n - NODE_ENV=production" ,
173+ },
151174 ]
152-
175+
153176 for index , compose in enumerate (test_composes ):
154177 hash_value = get_compose_hash (compose )
155178 print (f"compose { index + 1 } : { hash_value } " )
@@ -160,23 +183,29 @@ async def main():
160183 print ("\n 7. Testing verify_env_encrypt_public_key" )
161184 test_cases = [
162185 {
163- "public_key" : bytes .fromhex ('e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a' ),
164- "signature" : bytes .fromhex ('8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00' ),
165- "app_id" : '0000000000000000000000000000000000000000'
186+ "public_key" : bytes .fromhex (
187+ "e33a1832c6562067ff8f844a61e51ad051f1180b66ec2551fb0251735f3ee90a"
188+ ),
189+ "signature" : bytes .fromhex (
190+ "8542c49081fbf4e03f62034f13fbf70630bdf256a53032e38465a27c36fd6bed7a5e7111652004aef37f7fd92fbfc1285212c4ae6a6154203a48f5e16cad2cef00"
191+ ),
192+ "app_id" : "0000000000000000000000000000000000000000" ,
166193 },
167194 {
168- "public_key" : bytes .fromhex ('deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef' ),
169- "signature" : bytes .fromhex ('0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' ),
170- "app_id" : 'invalid-app-id'
171- }
195+ "public_key" : bytes .fromhex (
196+ "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
197+ ),
198+ "signature" : bytes .fromhex (
199+ "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
200+ ),
201+ "app_id" : "invalid-app-id" ,
202+ },
172203 ]
173204
174205 for index , test_case in enumerate (test_cases ):
175206 try :
176207 result = verify_env_encrypt_public_key (
177- test_case ["public_key" ],
178- test_case ["signature" ],
179- test_case ["app_id" ]
208+ test_case ["public_key" ], test_case ["signature" ], test_case ["app_id" ]
180209 )
181210 print (f"test case { index + 1 } : { result .hex () if result else 'null' } " )
182211 except Exception as error :
@@ -186,5 +215,6 @@ async def main():
186215 print (f"Error: { error } " )
187216 sys .exit (1 )
188217
218+
189219if __name__ == "__main__" :
190- asyncio .run (main ())
220+ asyncio .run (main ())
0 commit comments