Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 9s
Blockchain Synchronization Verification / sync-verification (push) Failing after 1s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Successful in 6s
Documentation Validation / validate-policies-strict (push) Successful in 2s
Integration Tests / test-service-integration (push) Successful in 40s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 1s
P2P Network Verification / p2p-verification (push) Successful in 2s
Production Tests / Production Integration Tests (push) Successful in 21s
Python Tests / test-python (push) Successful in 13s
Security Scanning / security-scan (push) Failing after 46s
Smart Contract Tests / test-solidity (map[name:aitbc-token path:packages/solidity/aitbc-token]) (push) Successful in 17s
Smart Contract Tests / lint-solidity (push) Successful in 10s
- Add sys import to 29 test files across agent-coordinator, blockchain-event-bridge, blockchain-node, and coordinator-api - Remove apps/blockchain-event-bridge/tests/test_integration.py (obsolete bridge integration tests) - Remove apps/coordinator-api/tests/test_integration.py (obsolete API integration tests) - Implement GPU registration in marketplace_gpu.py with GPURegistry model persistence
118 lines
3.9 KiB
Python
118 lines
3.9 KiB
Python
"""Tests for action handlers."""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock, AsyncMock, patch
|
|
import sys
|
|
|
|
from blockchain_event_bridge.action_handlers.coordinator_api import CoordinatorAPIHandler
|
|
from blockchain_event_bridge.action_handlers.agent_daemon import AgentDaemonHandler
|
|
from blockchain_event_bridge.action_handlers.marketplace import MarketplaceHandler
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_coordinator_api_handler_initialization():
|
|
"""Test coordinator API handler initialization."""
|
|
handler = CoordinatorAPIHandler("http://localhost:8011", "test-key")
|
|
|
|
assert handler.base_url == "http://localhost:8011"
|
|
assert handler.api_key == "test-key"
|
|
assert handler._client is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_coordinator_api_handler_handle_block():
|
|
"""Test coordinator API handler handling a block."""
|
|
handler = CoordinatorAPIHandler("http://localhost:8011")
|
|
|
|
block_data = {"height": 100, "hash": "0x123"}
|
|
transactions = [{"type": "ai_job", "hash": "0x456"}]
|
|
|
|
with patch.object(handler, "handle_transaction", new_callable=AsyncMock) as mock_handle_tx:
|
|
await handler.handle_block(block_data, transactions)
|
|
|
|
mock_handle_tx.assert_called_once_with(transactions[0])
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_coordinator_api_handler_close():
|
|
"""Test closing coordinator API handler."""
|
|
handler = CoordinatorAPIHandler("http://localhost:8011")
|
|
|
|
# Create a client first
|
|
await handler._get_client()
|
|
assert handler._client is not None
|
|
|
|
await handler.close()
|
|
assert handler._client is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handler_initialization():
|
|
"""Test agent daemon handler initialization."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
assert handler.blockchain_rpc_url == "http://localhost:8006"
|
|
assert handler._client is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handler_handle_transaction():
|
|
"""Test agent daemon handler handling a transaction."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
tx_data = {
|
|
"hash": "0x123",
|
|
"type": "agent_message",
|
|
"to": "agent_address",
|
|
"payload": {"trigger": "process"}
|
|
}
|
|
|
|
with patch.object(handler, "_notify_agent_daemon", new_callable=AsyncMock) as mock_notify:
|
|
await handler.handle_transaction(tx_data)
|
|
|
|
mock_notify.assert_called_once_with(tx_data)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handler_is_agent_transaction():
|
|
"""Test checking if transaction is an agent transaction."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
# Agent transaction
|
|
assert handler._is_agent_transaction({"payload": {"trigger": "test"}}) is True
|
|
assert handler._is_agent_transaction({"payload": {"agent": "test"}}) is True
|
|
|
|
# Not an agent transaction
|
|
assert handler._is_agent_transaction({"payload": {"other": "test"}}) is False
|
|
assert handler._is_agent_transaction({}) is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_marketplace_handler_initialization():
|
|
"""Test marketplace handler initialization."""
|
|
handler = MarketplaceHandler("http://localhost:8011", "test-key")
|
|
|
|
assert handler.base_url == "http://localhost:8011"
|
|
assert handler.api_key == "test-key"
|
|
assert handler._client is None
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_marketplace_handler_filter_marketplace_transactions():
|
|
"""Test filtering marketplace transactions."""
|
|
handler = MarketplaceHandler("http://localhost:8011")
|
|
|
|
transactions = [
|
|
{"type": "marketplace", "hash": "0x1"},
|
|
{"type": "transfer", "hash": "0x2"},
|
|
{"type": "listing", "hash": "0x3"},
|
|
{"type": "transfer", "payload": {"listing_id": "123"}, "hash": "0x4"},
|
|
]
|
|
|
|
filtered = handler._filter_marketplace_transactions(transactions)
|
|
|
|
assert len(filtered) == 3
|
|
assert filtered[0]["hash"] == "0x1"
|
|
assert filtered[1]["hash"] == "0x3"
|
|
assert filtered[2]["hash"] == "0x4"
|