agent0-sdk 0.3rc1__py3-none-any.whl → 0.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tests/test_transfer.py DELETED
@@ -1,255 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Test agent transfer functionality.
4
-
5
- This script demonstrates:
6
- 1. Creating and registering an agent with owner A
7
- 2. Transferring agent from owner A to owner B
8
- 3. Verifying ownership changed on-chain
9
- 4. Attempting to transfer from non-owner (should fail)
10
- 5. Verifying agent metadata remains unchanged after transfer
11
- """
12
-
13
- import logging
14
- import time
15
- import sys
16
-
17
- # Configure logging: root logger at WARNING to suppress noisy dependencies
18
- logging.basicConfig(
19
- level=logging.WARNING,
20
- format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
21
- datefmt='%Y-%m-%d %H:%M:%S',
22
- handlers=[logging.StreamHandler(sys.stdout)]
23
- )
24
-
25
- # Set debug level ONLY for agent0_sdk
26
- logging.getLogger('agent0_sdk').setLevel(logging.DEBUG)
27
- logging.getLogger('agent0_sdk.core').setLevel(logging.DEBUG)
28
-
29
- from config import (
30
- CHAIN_ID, RPC_URL, AGENT_PRIVATE_KEY, PINATA_JWT, SUBGRAPH_URL,
31
- print_config
32
- )
33
- from agent0_sdk import SDK, EndpointType, TrustModel
34
-
35
- def main():
36
- print("=" * 60)
37
- print("🔄 AGENT TRANSFER TEST")
38
- print("=" * 60)
39
-
40
- print_config()
41
-
42
- # Configuration for SDK
43
- sdkConfig_pinata = {
44
- "chainId": CHAIN_ID,
45
- "rpcUrl": RPC_URL,
46
- "signer": AGENT_PRIVATE_KEY,
47
- "ipfs": "pinata",
48
- "pinataJwt": PINATA_JWT
49
- # Subgraph URL auto-defaults from DEFAULT_SUBGRAPH_URLS
50
- }
51
-
52
- # Initialize SDK with Pinata
53
- print("\n📡 Initializing SDK with Pinata...")
54
- agentSdk = SDK(**sdkConfig_pinata)
55
-
56
- # Create a second private key for testing transfer
57
- # In a real scenario, this would be a different wallet
58
- # For testing, we'll use a different address derived from the same key
59
- print("\n🔑 Setting up test accounts...")
60
- ownerA_address = agentSdk.web3_client.account.address
61
- print(f"Owner A address: {ownerA_address}")
62
-
63
- # For testing purposes, we'll use a different address
64
- # In practice, this would be a completely different private key
65
- ownerB_address = "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6" # Example address
66
- print(f"Owner B address: {ownerB_address}")
67
-
68
- print("\n" + "=" * 60)
69
- print("STEP 1: CREATE AND REGISTER AGENT WITH OWNER A")
70
- print("=" * 60)
71
-
72
- # Create agent
73
- agent = agentSdk.createAgent(
74
- name="Transfer Test Agent",
75
- description="An agent for testing transfer functionality",
76
- image="https://example.com/transfer-test-agent.png"
77
- )
78
-
79
- # Configure agent details
80
- agent.setAgentWallet(ownerA_address, CHAIN_ID)
81
- agent.setENS("transfer-test-agent.eth")
82
- agent.setMetadata({
83
- "version": "1.0",
84
- "category": "test",
85
- "transfer_test": True
86
- })
87
-
88
- # Add endpoints
89
- agent.setMCP("https://mcp.example.com/transfer-test", auto_fetch=False)
90
- agent.setA2A("https://a2a.example.com/transfer-test-agent.json", auto_fetch=False)
91
-
92
- print(f"✅ Agent created with ID: {agent.agentId}")
93
- print(f"📄 Registration file prepared")
94
-
95
- # Register agent on-chain
96
- print("\n📝 Registering agent on-chain...")
97
- registration_result = agent.registerIPFS()
98
-
99
- print(f"✅ Agent registered successfully!")
100
- print(f" Agent ID: {registration_result.agentId}")
101
- print(f" IPFS URI: {registration_result.agentURI}")
102
-
103
- # Verify initial ownership using utility function
104
- print("\n🔍 Verifying initial ownership...")
105
- current_owner = agentSdk.getAgentOwner(registration_result.agentId)
106
- print(f"✅ Current owner: {current_owner}")
107
- print(f"✅ Matches Owner A: {current_owner.lower() == ownerA_address.lower()}")
108
-
109
- print("\n" + "=" * 60)
110
- print("STEP 2: TRANSFER AGENT TO OWNER B")
111
- print("=" * 60)
112
-
113
- # Transfer agent using Agent.transfer() method
114
- print(f"🔄 Transferring agent {registration_result.agentId} to {ownerB_address}...")
115
-
116
- try:
117
- transfer_result = agent.transfer(ownerB_address)
118
- print(f"✅ Transfer successful!")
119
- print(f" Transaction: {transfer_result['txHash']}")
120
- print(f" From: {transfer_result['from']}")
121
- print(f" To: {transfer_result['to']}")
122
- print(f" Agent ID: {transfer_result['agentId']}")
123
- except Exception as e:
124
- print(f"❌ Transfer failed: {e}")
125
- return
126
-
127
- print("\n" + "=" * 60)
128
- print("STEP 3: VERIFY OWNERSHIP CHANGE")
129
- print("=" * 60)
130
-
131
- # Verify ownership changed using utility function
132
- print("🔍 Verifying ownership change...")
133
- new_owner = agentSdk.getAgentOwner(registration_result.agentId)
134
- print(f"✅ New owner: {new_owner}")
135
- print(f"✅ Matches Owner B: {new_owner.lower() == ownerB_address.lower()}")
136
-
137
- # Verify agent metadata remains unchanged
138
- print("\n🔍 Verifying agent metadata remains unchanged...")
139
- # Parse agentId to extract tokenId for contract call
140
- agent_id_str = str(registration_result.agentId)
141
- if ":" in agent_id_str:
142
- token_id = int(agent_id_str.split(":")[-1])
143
- else:
144
- token_id = int(agent_id_str)
145
-
146
- agent_uri = agentSdk.web3_client.call_contract(
147
- agentSdk.identity_registry,
148
- "tokenURI",
149
- token_id
150
- )
151
- print(f"✅ Agent URI unchanged: {agent_uri}")
152
- # Note: registration_result.agentURI may be None if not set in RegistrationFile
153
- if registration_result.agentURI:
154
- print(f"✅ Matches original: {agent_uri == registration_result.agentURI}")
155
- else:
156
- print(f"✅ Agent URI retrieved from blockchain: {agent_uri}")
157
-
158
- print("\n" + "=" * 60)
159
- print("STEP 4: TEST SDK.transferAgent() METHOD")
160
- print("=" * 60)
161
-
162
- # Test SDK-level transfer method (this will fail since we're not Owner B)
163
- print("🔄 Testing SDK.transferAgent() method...")
164
- print(" (This should fail since we're not the current owner)")
165
-
166
- try:
167
- # Try to transfer back to Owner A (should fail)
168
- sdk_transfer_result = agentSdk.transferAgent(
169
- registration_result.agentId,
170
- ownerA_address
171
- )
172
- print(f"❌ Unexpected success: {sdk_transfer_result}")
173
- except Exception as e:
174
- print(f"✅ Expected failure: {e}")
175
-
176
- print("\n" + "=" * 60)
177
- print("STEP 5: TEST INVALID TRANSFER ATTEMPTS")
178
- print("=" * 60)
179
-
180
- # Test invalid transfer attempts
181
- print("🔄 Testing invalid transfer attempts...")
182
-
183
- # Test zero address
184
- try:
185
- agent.transfer("0x0000000000000000000000000000000000000000")
186
- print("❌ Zero address transfer should have failed")
187
- except ValueError as e:
188
- print(f"✅ Zero address correctly rejected: {e}")
189
-
190
- # Test self-transfer
191
- try:
192
- agent.transfer(ownerB_address) # Try to transfer to same address
193
- print("❌ Self-transfer should have failed")
194
- except ValueError as e:
195
- print(f"✅ Self-transfer correctly rejected: {e}")
196
-
197
- # Test invalid address format
198
- try:
199
- agent.transfer("invalid_address")
200
- print("❌ Invalid address should have failed")
201
- except ValueError as e:
202
- print(f"✅ Invalid address correctly rejected: {e}")
203
-
204
- print("\n" + "=" * 60)
205
- print("STEP 6: VERIFY AGENT DATA INTEGRITY")
206
- print("=" * 60)
207
-
208
- # Load agent and verify all data is intact
209
- print("🔍 Loading agent and verifying data integrity...")
210
-
211
- try:
212
- loaded_agent = agentSdk.loadAgent(registration_result.agentId)
213
- print(f"✅ Agent loaded successfully")
214
- print(f" Name: {loaded_agent.name}")
215
- print(f" Description: {loaded_agent.description}")
216
- print(f" Image: {loaded_agent.image}")
217
- print(f" Wallet Address: {loaded_agent.walletAddress}")
218
- print(f" ENS: {loaded_agent.ensEndpoint}")
219
- print(f" Metadata: {loaded_agent.metadata}")
220
- print(f" MCP Endpoint: {loaded_agent.mcpEndpoint}")
221
- print(f" A2A Endpoint: {loaded_agent.a2aEndpoint}")
222
- print(f" Active: {loaded_agent.active}")
223
-
224
- # Verify ownership is correctly reflected
225
- print(f"\n🔍 Ownership verification:")
226
- print(f" Current owner (on-chain): {new_owner}")
227
- print(f" Expected owner: {ownerB_address}")
228
- print(f" Match: {new_owner.lower() == ownerB_address.lower()}")
229
-
230
- except Exception as e:
231
- print(f"❌ Failed to load agent: {e}")
232
- import traceback
233
- traceback.print_exc()
234
-
235
- print("\n" + "=" * 60)
236
- print("🎉 TRANSFER TEST COMPLETED SUCCESSFULLY!")
237
- print("=" * 60)
238
-
239
- print("\n📋 Summary:")
240
- print(f" ✅ Agent created and registered with Owner A")
241
- print(f" ✅ Agent successfully transferred to Owner B")
242
- print(f" ✅ Ownership change verified on-chain")
243
- print(f" ✅ Invalid transfer attempts properly rejected")
244
- print(f" ✅ Agent data integrity maintained")
245
- print(f" ✅ Both Agent.transfer() and SDK.transferAgent() methods tested")
246
-
247
- print(f"\n🔗 Agent Details:")
248
- print(f" Agent ID: {registration_result.agentId}")
249
- print(f" Current Owner: {new_owner}")
250
- print(f" Agent URI: {agent_uri}")
251
- if transfer_result and 'txHash' in transfer_result:
252
- print(f" Transfer Transaction: {transfer_result['txHash']}")
253
-
254
- if __name__ == "__main__":
255
- main()