feat(indexer): complete deterministic projection pipeline and replay tests
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import pytest
|
||||
from src.core.events import NormalizedEvent
|
||||
from src.projections.store import ProjectionStore
|
||||
from src.decoding.evm import EVMDecoder
|
||||
|
||||
def test_normalized_event_idempotency():
|
||||
event = NormalizedEvent(
|
||||
chain_id=46630,
|
||||
block_number=1000,
|
||||
tx_hash="0xabcdef123456",
|
||||
log_index=2,
|
||||
event_type="MARKET_DEPLOYED",
|
||||
contract_address="0xc0E24E152771C588B21AEB654b30B1cBAf381c1a",
|
||||
payload={
|
||||
"market": "0x1111222233334444555566667777888899990000",
|
||||
"questionId": "0x9999",
|
||||
"tier": 1,
|
||||
"creator": "0x6cddF384792C77219fc25C454Cfe264757842830"
|
||||
},
|
||||
timestamp=1700000000
|
||||
)
|
||||
assert event.event_id == "46630:0xabcdef123456:2"
|
||||
|
||||
def test_projection_store_deploy_and_resolve():
|
||||
store = ProjectionStore()
|
||||
|
||||
deploy_event = NormalizedEvent(
|
||||
chain_id=46630,
|
||||
block_number=1000,
|
||||
tx_hash="0xabcdef123456",
|
||||
log_index=0,
|
||||
event_type="MARKET_DEPLOYED",
|
||||
contract_address="0xc0E24E152771C588B21AEB654b30B1cBAf381c1a",
|
||||
payload={
|
||||
"market": "0x1111222233334444555566667777888899990000",
|
||||
"questionId": "0x9999",
|
||||
"tier": 1,
|
||||
"creator": "0x6cddF384792C77219fc25C454Cfe264757842830"
|
||||
},
|
||||
timestamp=1700000000
|
||||
)
|
||||
store.apply_event(deploy_event)
|
||||
assert "0x1111222233334444555566667777888899990000" in store.markets
|
||||
assert store.markets["0x1111222233334444555566667777888899990000"]["status"] == "ACTIVE"
|
||||
|
||||
# Duplicate should be ignored
|
||||
store.apply_event(deploy_event)
|
||||
assert len(store.markets) == 1
|
||||
|
||||
# Resolve event
|
||||
resolve_event = NormalizedEvent(
|
||||
chain_id=46630,
|
||||
block_number=1050,
|
||||
tx_hash="0xabcdef789012",
|
||||
log_index=1,
|
||||
event_type="OUTCOME_RESOLVED",
|
||||
contract_address="0xc0E24E152771C588B21AEB654b30B1cBAf381c1a",
|
||||
payload={
|
||||
"questionId": "0x9999",
|
||||
"outcome": 1
|
||||
},
|
||||
timestamp=1700005000
|
||||
)
|
||||
store.apply_event(resolve_event)
|
||||
assert store.markets["0x1111222233334444555566667777888899990000"]["status"] == "RESOLVED"
|
||||
assert store.markets["0x1111222233334444555566667777888899990000"]["tentative_winning_outcome"] == 1
|
||||
|
||||
# Test Reset & Replay
|
||||
store.reset()
|
||||
assert len(store.markets) == 0
|
||||
assert len(store.processed_events) == 0
|
||||
|
||||
# Replay
|
||||
store.apply_event(deploy_event)
|
||||
store.apply_event(resolve_event)
|
||||
assert store.markets["0x1111222233334444555566667777888899990000"]["status"] == "RESOLVED"
|
||||
Reference in New Issue
Block a user