Some checks failed
Blockchain Synchronization Verification / sync-verification (push) Failing after 2s
Integration Tests / test-service-integration (push) Failing after 15s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 2s
P2P Network Verification / p2p-verification (push) Successful in 2s
Python Tests / test-python (push) Successful in 12s
Security Scanning / security-scan (push) Successful in 41s
Systemd Sync / sync-systemd (push) Successful in 7s
- Phase 1: Core bridge service with gossip broker subscription - Phase 2: Smart contract event integration via eth_getLogs RPC endpoint - Add contract event subscriber for AgentStaking, PerformanceVerifier, Marketplace, Bounty, CrossChainBridge - Add contract event handlers in agent_daemon.py and marketplace.py - Add systemd service file for blockchain-event-bridge - Update blockchain node router.py with eth_getLogs endpoint - Add configuration for contract addresses - Add tests for contract subscriber and handlers (27 tests passing)
78 lines
2.2 KiB
Python
78 lines
2.2 KiB
Python
"""Tests for contract event handlers."""
|
|
|
|
import pytest
|
|
from unittest.mock import Mock, AsyncMock
|
|
|
|
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_agent_daemon_handle_staking_event():
|
|
"""Test agent daemon handler for staking events."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
event_log = {
|
|
"topics": ["StakeCreated"],
|
|
"data": '{"stakeId": "123", "staker": "0xabc"}'
|
|
}
|
|
|
|
# Should not raise an error
|
|
await handler.handle_staking_event(event_log)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handle_performance_event():
|
|
"""Test agent daemon handler for performance events."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
event_log = {
|
|
"topics": ["PerformanceVerified"],
|
|
"data": '{"verificationId": "456", "withinSLA": true}'
|
|
}
|
|
|
|
# Should not raise an error
|
|
await handler.handle_performance_event(event_log)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handle_bounty_event():
|
|
"""Test agent daemon handler for bounty events."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
event_log = {
|
|
"topics": ["BountyCreated"],
|
|
"data": '{"bountyId": "789", "creator": "0xdef"}'
|
|
}
|
|
|
|
# Should not raise an error
|
|
await handler.handle_bounty_event(event_log)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_agent_daemon_handle_bridge_event():
|
|
"""Test agent daemon handler for bridge events."""
|
|
handler = AgentDaemonHandler("http://localhost:8006")
|
|
|
|
event_log = {
|
|
"topics": ["BridgeInitiated"],
|
|
"data": '{"requestId": "101", "sourceChain": "ethereum"}'
|
|
}
|
|
|
|
# Should not raise an error
|
|
await handler.handle_bridge_event(event_log)
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_marketplace_handle_contract_event():
|
|
"""Test marketplace handler for contract events."""
|
|
handler = MarketplaceHandler("http://localhost:8011")
|
|
|
|
event_log = {
|
|
"topics": ["ServiceListed"],
|
|
"data": '{"serviceId": "202", "provider": "0x123"}'
|
|
}
|
|
|
|
# Should not raise an error
|
|
await handler.handle_contract_event(event_log)
|