Files
aitbc/apps/blockchain-node/tests/test_models.py
aitbc e60cc3226c
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 test files and remove obsolete integration tests
- 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
2026-04-23 16:43:17 +02:00

86 lines
2.3 KiB
Python
Executable File

from __future__ import annotations
import pytest
from sqlmodel import Session
import sys
from aitbc_chain.models import Block, Receipt
from aitbc_chain.models import Transaction as ChainTransaction
def _insert_block(session: Session, height: int = 0) -> Block:
block = Block(
height=height,
hash=f"0x{'0'*63}{height}",
parent_hash="0x" + "0" * 64,
proposer="validator",
tx_count=0,
)
session.add(block)
session.commit()
session.refresh(block)
return block
def test_relationships(session: Session) -> None:
block = _insert_block(session, height=1)
tx = ChainTransaction(
tx_hash="0x" + "1" * 64,
block_height=block.height,
sender="alice",
recipient="bob",
payload={"foo": "bar"},
)
receipt = Receipt(
job_id="job-1",
receipt_id="0x" + "2" * 64,
block_height=block.height,
payload={},
miner_signature={},
coordinator_attestations=[],
)
session.add(tx)
session.add(receipt)
session.commit()
session.refresh(tx)
session.refresh(receipt)
assert tx.block is not None
assert tx.block.hash == block.hash
assert receipt.block is not None
assert receipt.block.hash == block.hash
def test_hash_validation_accepts_hex(session: Session) -> None:
block = Block(
height=10,
hash="0x" + "a" * 64,
parent_hash="0x" + "b" * 64,
proposer="validator",
)
session.add(block)
session.commit()
session.refresh(block)
assert block.hash.startswith("0x")
assert block.parent_hash.startswith("0x")
@pytest.mark.skip(reason="SQLModel table=True models bypass Pydantic validators - validation must be done at API layer")
def test_hash_validation_rejects_non_hex(session: Session) -> None:
"""
NOTE: This test is skipped because SQLModel with table=True does not run
Pydantic field validators. Validation should be performed at the API/service
layer before creating model instances.
See: https://github.com/tiangolo/sqlmodel/issues/52
"""
with pytest.raises(ValueError):
Block.model_validate({
"height": 20,
"hash": "not-hex",
"parent_hash": "0x" + "c" * 64,
"proposer": "validator",
})