Files
aitbc/tests/verification/test_model_validation.py
aitbc 0081b9ee4d
Some checks failed
Python Tests / test-python (push) Failing after 10s
P2P Network Verification / p2p-verification (push) Successful in 7s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 7s
feat: migrate tests to use centralized aitbc package utilities
- Migrate HTTP client usage from httpx/requests to aitbc.AITBCHTTPClient
- Update test_payment_integration.py to use AITBCHTTPClient and get_logger
- Fix typo in test_cross_node_blockchain.py (NetworkErroration -> NetworkError)
- Add aitbc validators to test_model_validation.py (validate_address, validate_hash)
- conftest.py already uses aitbc path utilities (get_data_path, get_log_path)
- Other test files already migrated (test_tx_import, test_simple_import, test_minimal, test_block_import_complete, verify_transactions_fixed)
2026-04-24 21:50:35 +02:00

67 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""
Test the BlockImportRequest model
"""
from pydantic import BaseModel, Field
from typing import Dict, Any, List, Optional
from aitbc import validate_address, validate_hash
class TransactionData(BaseModel):
tx_hash: str
sender: str
recipient: str
payload: Dict[str, Any] = Field(default_factory=dict)
class BlockImportRequest(BaseModel):
height: int = Field(gt=0)
hash: str
parent_hash: str
proposer: str
timestamp: str
tx_count: int = Field(ge=0)
state_root: Optional[str] = None
transactions: List[TransactionData] = Field(default_factory=list)
# Test creating the request
test_data = {
"height": 1,
"hash": "0xtest",
"parent_hash": "0x00",
"proposer": "test",
"timestamp": "2026-01-29T10:20:00",
"tx_count": 1,
"transactions": [{
"tx_hash": "0xtx123",
"sender": "0xsender",
"recipient": "0xrecipient",
"payload": {"test": "data"}
}]
}
print("Test data:")
print(test_data)
# Validate address and hash using aitbc validators
try:
validate_address(test_data["proposer"])
validate_hash(test_data["hash"])
print("✅ Address and hash validation passed")
except Exception as e:
print(f"⚠️ Validation warning: {e}")
try:
request = BlockImportRequest(**test_data)
print("\n✅ Request validated successfully!")
print(f"Transactions count: {len(request.transactions)}")
if request.transactions:
tx = request.transactions[0]
print(f"First transaction:")
print(f" tx_hash: {tx.tx_hash}")
print(f" sender: {tx.sender}")
print(f" recipient: {tx.recipient}")
except Exception as e:
print(f"\n❌ Validation failed: {e}")
import traceback
traceback.print_exc()