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)
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
"""Tests for event subscribers."""
|
|
|
|
import pytest
|
|
import asyncio
|
|
from unittest.mock import Mock, AsyncMock
|
|
|
|
from blockchain_event_bridge.event_subscribers.blocks import BlockEventSubscriber
|
|
from blockchain_event_bridge.event_subscribers.transactions import TransactionEventSubscriber
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_block_subscriber_initialization():
|
|
"""Test block subscriber initialization."""
|
|
from blockchain_event_bridge.config import Settings
|
|
|
|
settings = Settings()
|
|
subscriber = BlockEventSubscriber(settings)
|
|
|
|
assert subscriber.settings == settings
|
|
assert subscriber._running is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_block_subscriber_set_bridge():
|
|
"""Test setting bridge on block subscriber."""
|
|
from blockchain_event_bridge.config import Settings
|
|
from blockchain_event_bridge.bridge import BlockchainEventBridge
|
|
|
|
settings = Settings()
|
|
subscriber = BlockEventSubscriber(settings)
|
|
bridge = Mock(spec=BlockchainEventBridge)
|
|
|
|
subscriber.set_bridge(bridge)
|
|
assert subscriber._bridge == bridge
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_block_subscriber_stop():
|
|
"""Test stopping block subscriber."""
|
|
from blockchain_event_bridge.config import Settings
|
|
|
|
settings = Settings()
|
|
subscriber = BlockEventSubscriber(settings)
|
|
|
|
# Start and immediately stop
|
|
task = asyncio.create_task(subscriber.run())
|
|
await asyncio.sleep(0.1) # Let it start
|
|
await subscriber.stop()
|
|
|
|
# Cancel the task
|
|
task.cancel()
|
|
try:
|
|
await task
|
|
except asyncio.CancelledError:
|
|
pass
|
|
|
|
assert subscriber._running is False
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_transaction_subscriber_initialization():
|
|
"""Test transaction subscriber initialization."""
|
|
from blockchain_event_bridge.config import Settings
|
|
|
|
settings = Settings()
|
|
subscriber = TransactionEventSubscriber(settings)
|
|
|
|
assert subscriber.settings == settings
|
|
assert subscriber._running is False
|