Skip to content

Commit f79633e

Browse files
Copilot0xrinegade
andcommitted
Add targeted coverage tests, improve coverage from 57% to 72%
Co-authored-by: 0xrinegade <[email protected]>
1 parent 641b6d0 commit f79633e

File tree

3 files changed

+944
-121
lines changed

3 files changed

+944
-121
lines changed

python/tests/unit/test_core_coverage.py

Lines changed: 51 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,12 @@ def test_pda_derivation_methods(self):
7979
owner = PublicKey.from_string("11111111111111111111111111111112")
8080

8181
# Test agent PDA derivation
82-
pda, bump = client.derive_agent_pda("test-agent", owner)
82+
pda = client.derive_agent_pda("test-agent", owner)
8383
assert isinstance(pda, PublicKey)
84-
assert isinstance(bump, int)
8584

8685
# Test MCP server PDA derivation
87-
pda, bump = client.derive_mcp_server_pda("test-server", owner)
86+
pda = client.derive_mcp_server_pda("test-server", owner)
8887
assert isinstance(pda, PublicKey)
89-
assert isinstance(bump, int)
90-
91-
# Test payment escrow PDA derivation
92-
pda, bump = client.derive_payment_escrow_pda("test-agent", owner)
93-
assert isinstance(pda, PublicKey)
94-
assert isinstance(bump, int)
9588

9689
def test_instruction_building_methods(self):
9790
"""Test instruction building methods exist."""
@@ -131,50 +124,32 @@ def test_instruction_building_methods(self):
131124
)
132125
assert instruction is not None
133126

134-
instruction = client.build_update_mcp_server_instruction(
135-
server_id="test-server",
136-
owner=owner,
137-
name="Updated Server"
138-
)
139-
assert instruction is not None
140-
141127
instruction = client.build_deregister_mcp_server_instruction(
142128
server_id="test-server",
143129
owner=owner
144130
)
145131
assert instruction is not None
146132

147133
def test_serialization_methods(self):
148-
"""Test data serialization methods."""
134+
"""Test data serialization methods exist."""
149135
client = SolanaAIRegistriesClient()
150136

151-
# Test agent data serialization
152-
data = client._serialize_agent_data(
137+
# Test agent data encoding methods
138+
data = client._encode_register_agent_data(
153139
agent_id="test-agent",
154140
name="Test Agent",
155141
description="Test description"
156142
)
157143
assert isinstance(data, bytes)
158144

159-
# Test MCP server data serialization
160-
data = client._serialize_mcp_server_data(
145+
# Test MCP server data encoding
146+
data = client._encode_register_mcp_server_data(
161147
server_id="test-server",
162148
name="Test Server",
163149
description="Test description",
164150
endpoint_url="https://api.example.com"
165151
)
166152
assert isinstance(data, bytes)
167-
168-
# Test string serialization
169-
data = client._serialize_string("test")
170-
assert isinstance(data, bytes)
171-
172-
# Test optional string serialization
173-
data = client._serialize_optional_string("test")
174-
assert isinstance(data, bytes)
175-
176-
data = client._serialize_optional_string(None)
177-
assert isinstance(data, bytes)
178153

179154

180155
class TestMcpRegistryBasics:
@@ -195,14 +170,22 @@ def test_init_devnet(self):
195170
mock_client = Mock()
196171
manager = PaymentManager(mock_client)
197172
assert manager.client == mock_client
198-
assert manager.use_mainnet is False
173+
# Token mint should be devnet
174+
from solders.pubkey import Pubkey as PublicKey
175+
from solana_ai_registries.constants import A2AMPL_TOKEN_MINT_DEVNET
176+
expected = PublicKey.from_string(A2AMPL_TOKEN_MINT_DEVNET)
177+
assert manager.token_mint == expected
199178

200179
def test_init_mainnet(self):
201180
"""Test PaymentManager initialization for mainnet."""
202181
mock_client = Mock()
203182
manager = PaymentManager(mock_client, use_mainnet=True)
204183
assert manager.client == mock_client
205-
assert manager.use_mainnet is True
184+
# Token mint should be mainnet
185+
from solders.pubkey import Pubkey as PublicKey
186+
from solana_ai_registries.constants import A2AMPL_TOKEN_MINT_MAINNET
187+
expected = PublicKey.from_string(A2AMPL_TOKEN_MINT_MAINNET)
188+
assert manager.token_mint == expected
206189

207190
def test_token_mint_property(self):
208191
"""Test token mint property."""
@@ -222,66 +205,51 @@ def test_token_mint_property(self):
222205

223206
def test_utility_methods(self):
224207
"""Test payment utility methods."""
225-
from decimal import Decimal
226208
mock_client = Mock()
227209
manager = PaymentManager(mock_client)
228210

229-
# Test payment amount calculation
230-
amount = manager._calculate_payment_amount(Decimal("2.0"), 30)
231-
assert amount == Decimal("60.0")
232-
233211
# Test payment amount validation
234-
manager._validate_payment_amount(Decimal("10.0")) # Should not raise
212+
manager._validate_payment_amount(10.0) # Should not raise
235213

236214
with pytest.raises(Exception): # Should raise for invalid amounts
237-
manager._validate_payment_amount(Decimal("0"))
215+
manager._validate_payment_amount(0.0)
238216

239217
with pytest.raises(Exception):
240-
manager._validate_payment_amount(Decimal("-5"))
218+
manager._validate_payment_amount(-5.0)
241219

242-
# Test payment type methods
243-
payment_type = manager._get_payment_type_for_transaction("escrow")
244-
assert payment_type is not None
220+
# Test stream cost calculation
221+
cost = manager._calculate_stream_cost(2.0, 30)
222+
assert cost == 60.0
245223

246-
payment_type = manager._get_payment_type_for_transaction("direct")
247-
assert payment_type is not None
248-
249-
payment_type = manager._get_payment_type_for_transaction("streaming")
250-
assert payment_type is not None
224+
# Test payment ID generation
225+
from solders.pubkey import Pubkey as PublicKey
226+
pubkey = PublicKey.from_string("11111111111111111111111111111112")
227+
payment_id = manager._generate_payment_id(pubkey, pubkey, "test-service")
228+
assert isinstance(payment_id, str)
229+
assert len(payment_id) > 0
251230

252231
def test_instruction_building_methods(self):
253232
"""Test payment instruction building methods."""
254233
from solders.pubkey import Pubkey as PublicKey
255234
mock_client = Mock()
235+
# Mock the agent_program_id property
236+
mock_client.agent_program_id = PublicKey.from_string("11111111111111111111111111111112")
256237
manager = PaymentManager(mock_client)
257238

258239
pubkey = PublicKey.from_string("11111111111111111111111111111112")
259240

260-
# Test transfer instruction building
261-
instruction = manager._build_transfer_instruction(
262-
from_pubkey=pubkey,
263-
to_pubkey=pubkey,
264-
amount=1000000000,
265-
token_mint=manager.token_mint
266-
)
267-
assert instruction is not None
268-
269-
# Test escrow instruction building
270-
instruction = manager._build_create_escrow_instruction(
271-
user=pubkey,
272-
agent_id="test-agent",
241+
# Test SPL transfer instruction building
242+
instruction = manager._create_spl_transfer_instruction(
243+
source=pubkey,
244+
destination=pubkey,
245+
owner=pubkey,
273246
amount=1000000000
274247
)
275248
assert instruction is not None
276249

277-
# Test streaming instruction building
278-
instruction = manager._build_streaming_instruction(
279-
user=pubkey,
280-
agent_owner=pubkey,
281-
rate_per_second=1000000,
282-
duration=60
283-
)
284-
assert instruction is not None
250+
# Test escrow PDA derivation
251+
pda = manager._derive_escrow_pda(pubkey, pubkey)
252+
assert isinstance(pda, PublicKey)
285253

286254

287255
class TestIdlLoaderBasics:
@@ -343,46 +311,23 @@ def test_data_classes(self):
343311
assert parsed_idl.name == "test_program"
344312
assert len(parsed_idl.instructions) == 1
345313

346-
def test_type_conversion_methods(self):
347-
"""Test type conversion methods."""
314+
def test_type_mapping_methods(self):
315+
"""Test type mapping methods."""
348316
loader = IDLLoader()
349317

350-
# Test basic type conversions
351-
assert loader._convert_type("string") == str
352-
assert loader._convert_type("u64") == int
353-
assert loader._convert_type("bool") == bool
354-
assert loader._convert_type("publicKey") == str
355-
assert loader._convert_type("bytes") == bytes
356-
357-
# Test unknown type
358-
unknown_result = loader._convert_type("unknown_type")
359-
assert unknown_result is not None
360-
361-
def test_name_formatting(self):
362-
"""Test name formatting methods."""
363-
loader = IDLLoader()
318+
# Test basic type mappings
319+
result = loader._map_idl_type_to_python("string")
320+
assert result == str
364321

365-
assert loader._format_name("test_name") == "TestName"
366-
assert loader._format_name("another_test") == "AnotherTest"
367-
assert loader._format_name("simple") == "Simple"
368-
369-
def test_type_generation_methods(self):
370-
"""Test type generation methods exist."""
371-
loader = IDLLoader()
322+
result = loader._map_idl_type_to_python("u64")
323+
assert result == int
372324

373-
# Test struct type generation
374-
struct_type = loader._generate_struct_type(
375-
"TestStruct",
376-
[{"name": "field1", "type": "string"}]
377-
)
378-
assert struct_type is not None
325+
result = loader._map_idl_type_to_python("bool")
326+
assert result == bool
379327

380-
# Test enum type generation
381-
enum_type = loader._generate_enum_type(
382-
"TestEnum",
383-
[{"name": "Variant1"}, {"name": "Variant2"}]
384-
)
385-
assert enum_type is not None
328+
# Test complex type mapping
329+
result = loader._map_idl_type_to_python({"vec": "string"})
330+
assert result is not None
386331

387332

388333
class TestModuleImports:

0 commit comments

Comments
 (0)