33from pathlib import Path
44import time
55from datetime import datetime
6+ from game_sdk .game .custom_types import Function , Argument , FunctionResultStatus
7+ from dotenv import load_dotenv
8+ load_dotenv ()
69
7- # Add the parent directory to Python path
8- parent_dir = str (Path (__file__ ).parent .parent )
9- sys .path .append (parent_dir )
1010
11- from dpsn_plugin_gamesdk .dpsn_plugin import plugin
11+
12+ from dpsn_plugin_gamesdk .dpsn_plugin import DpsnPlugin
13+
14+ dpsn_plugin = DpsnPlugin (
15+ dpsn_url = os .getenv ("DPSN_URL" ),
16+ pvt_key = os .getenv ("PVT_KEY" )
17+ )
1218
1319def test_dpsn_connection ():
1420 """Test DPSN connection and basic functionality"""
1521 print ("\n 🔄 Testing DPSN Connection..." )
1622
17- # Initialize DPSN client (without options since the method doesn't accept them)
18- result = plugin .initialize ()
19- if not result ["success" ]:
20- print (f"❌ Failed to initialize DPSN: { result .get ('error' )} " )
21- return False
22-
23+
2324 # Wait for connection to stabilize
2425 time .sleep (1 )
2526 print ("✅ DPSN initialized successfully" )
@@ -36,13 +37,13 @@ def handle_message(message_data):
3637 print (f"Received message on { topic } : { payload } " )
3738
3839 # Set the callback
39- plugin .set_message_callback (handle_message )
40+ dpsn_plugin .set_message_callback (handle_message )
4041
4142 # Test topic
4243 topic = "0xe14768a6d8798e4390ec4cb8a4c991202c2115a5cd7a6c0a7ababcaf93b4d2d4/SOLUSDT/ohlc"
4344
4445 print (f"Subscribing to topic: { topic } " )
45- result = plugin .subscribe (topic )
46+ result = dpsn_plugin .subscribe (topic )
4647 if not result ["success" ]:
4748 print (f"❌ Failed to subscribe to topic: { result .get ('error' )} " )
4849 return False
@@ -52,26 +53,24 @@ def handle_message(message_data):
5253
5354 try :
5455 while True :
55- if not plugin .client .dpsn_broker .is_connected ():
56+ if not dpsn_plugin .client .dpsn_broker .is_connected ():
5657 print ("Connection lost, attempting to reconnect..." )
57- plugin .initialize ()
58+ dpsn_plugin .initialize ()
5859 time .sleep (1 )
59- plugin .subscribe (topic )
60+ dpsn_plugin .subscribe (topic )
6061 time .sleep (1 )
6162
6263 except KeyboardInterrupt :
6364 print ("\n ⚠️ Test interrupted by user" )
6465 return True
6566
66- return True
67-
6867def test_shutdown ():
6968 """Test graceful shutdown"""
7069 print ("\n 🔄 Testing Shutdown..." )
7170
72- result = plugin .shutdown ()
73- if not result [ "success" ] :
74- print (f"❌ Failed to shutdown: { result . get ( 'error' ) } " )
71+ status , message , extra = dpsn_plugin .shutdown ()
72+ if status is not FunctionResultStatus . DONE :
73+ print (f"❌ Failed to shutdown" )
7574 return False
7675
7776 print ("✅ Shutdown successful" )
@@ -86,7 +85,6 @@ def main():
8685 if not test_dpsn_connection ():
8786 return
8887
89- # Test subscription and message reception
9088 if not test_subscribe_and_receive ():
9189 return
9290
0 commit comments