@@ -40,6 +40,17 @@ def setup_method(self):
4040 self.mock_client.get_account_info = AsyncMock()
4141 self.mock_client.build_and_send_transaction = AsyncMock()
4242 self.mock_client.get_program_accounts = AsyncMock()
43+ self.mock_client.send_transaction = AsyncMock()
44+
45+ # Mock instruction building methods
46+ self.mock_client.build_register_agent_instruction = Mock()
47+ self.mock_client.build_update_agent_instruction = Mock()
48+ self.mock_client.build_deregister_agent_instruction = Mock()
49+
50+ # Create a proper mock transaction
51+ self.mock_transaction = Mock(spec=Transaction)
52+ self.mock_transaction.sign = Mock()
53+ self.mock_transaction.serialize = Mock(return_value=b"mock_serialized_tx")
4354
4455 # Sample agent data
4556 self.sample_agent_data = {
@@ -69,32 +80,54 @@ def test_agent_registry_has_required_methods(self):
6980
7081 # Registration Tests
7182 @pytest.mark.asyncio
72- async def test_register_agent_success (self ):
83+ @patch('solana_ai_registries.agent.Transaction')
84+ async def test_register_agent_success(self, mock_transaction):
7385 """Test successful agent registration."""
86+ # Setup mocks - mock instruction building at the client level
87+ mock_instruction = Mock()
88+ self.mock_client.build_register_agent_instruction.return_value = mock_instruction
89+
90+ # Mock transaction creation
91+ mock_transaction_instance = Mock()
92+ mock_transaction.new_with_payer.return_value = mock_transaction_instance
93+
7494 # Mock successful registration (account doesn't exist)
7595 self.mock_client.get_account_info.return_value = None
76- self .mock_client .build_and_send_transaction .return_value = "mock_tx_signature"
96+ self.mock_client.send_transaction .return_value = "mock_tx_signature"
7797
78- result = await self .agent_registry .register_agent (
79- agent_id = "test_agent" ,
80- name = "Test AI Agent" ,
81- description = "A test AI agent" ,
82- owner = self .owner_keypair
83- )
98+ # Mock get_agent to return None (agent doesn't exist)
99+ with patch.object(self.agent_registry, 'get_agent', return_value=None):
100+ result = await self.agent_registry.register_agent(
101+ agent_id="test_agent",
102+ name="Test AI Agent",
103+ description="A test AI agent",
104+ owner=self.owner_keypair
105+ )
84106
85107 assert result == "mock_tx_signature"
108+ # Verify instruction was built correctly
109+ self.mock_client.build_register_agent_instruction.assert_called_once()
86110
87111 @pytest.mark.asyncio
88- async def test_register_agent_with_service_endpoint (self ):
112+ @patch('solana_ai_registries.agent.Transaction')
113+ async def test_register_agent_with_service_endpoint(self, mock_transaction):
89114 """Test agent registration with service endpoint."""
115+ # Setup mocks
116+ mock_instruction = Mock()
117+ self.mock_client.build_register_agent_instruction.return_value = mock_instruction
118+
119+ # Mock transaction creation
120+ mock_transaction_instance = Mock()
121+ mock_transaction.new_with_payer.return_value = mock_transaction_instance
122+
90123 service_endpoint = ServiceEndpoint(
91124 url="https://api.example.com/agent",
92125 auth_type="bearer_token",
93126 auth_config={"token": "secret_token"}
94127 )
95128
96129 self.mock_client.get_account_info.return_value = None
97- self .mock_client .build_and_send_transaction .return_value = "mock_tx_signature"
130+ self.mock_client.send_transaction .return_value = "mock_tx_signature"
98131
99132 result = await self.agent_registry.register_agent(
100133 agent_id="test_agent",
@@ -109,21 +142,27 @@ async def test_register_agent_with_service_endpoint(self):
109142 @pytest.mark.asyncio
110143 async def test_register_agent_with_skills(self):
111144 """Test agent registration with skills."""
145+ # Setup mocks
146+ mock_instruction = Mock()
147+ self.mock_client.build_register_agent_instruction.return_value = mock_instruction
148+
112149 skills = [
113150 AgentSkill(
151+ skill_id="skill_1",
114152 name="text_generation",
115153 description="Generate human-like text",
116154 category="nlp"
117155 ),
118156 AgentSkill(
157+ skill_id="skill_2",
119158 name="sentiment_analysis",
120159 description="Analyze sentiment in text",
121160 category="nlp"
122161 )
123162 ]
124163
125164 self.mock_client.get_account_info.return_value = None
126- self .mock_client .build_and_send_transaction .return_value = "mock_tx_signature"
165+ self.mock_client.send_transaction .return_value = "mock_tx_signature"
127166
128167 result = await self.agent_registry.register_agent(
129168 agent_id="test_agent",
@@ -200,10 +239,14 @@ async def test_register_agent_already_exists(self):
200239 @pytest.mark.asyncio
201240 async def test_register_agent_transaction_failure(self):
202241 """Test agent registration when transaction fails."""
242+ # Setup mocks
243+ mock_instruction = Mock()
244+ self.mock_client.build_register_agent_instruction.return_value = mock_instruction
245+
203246 # Mock account doesn't exist (new registration)
204247 self.mock_client.get_account_info.return_value = None
205248 # Mock transaction failure
206- self .mock_client .build_and_send_transaction .side_effect = Exception ("Transaction failed" )
249+ self.mock_client.send_transaction .side_effect = Exception("Transaction failed")
207250
208251 with pytest.raises(RegistrationError, match="Failed to register agent"):
209252 await self.agent_registry.register_agent(
0 commit comments