Skip to content
Merged

Dev #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions certified_builder/build_url_tech_floripa.py

This file was deleted.

9 changes: 3 additions & 6 deletions certified_builder/certified_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from certified_builder.utils.fetch_file_certificate import fetch_file_certificate
from certified_builder.certificates_on_solana import CertificatesOnSolana
from certified_builder.make_qrcode import MakeQRCode
from certified_builder.build_url_tech_floripa import build_url_tech_floripa
from certified_builder.solana_explorer_url import extract_solana_explorer_url

FONT_NAME = os.path.join(os.path.dirname(__file__), "fonts/PinyonScript/PinyonScript-Regular.ttf")
VALIDATION_CODE = os.path.join(os.path.dirname(__file__), "fonts/ChakraPetch/ChakraPetch-SemiBold.ttf")
Expand Down Expand Up @@ -58,11 +58,8 @@ def build_certificates(self, participants: List[Participant]):
}
)

participant.authenticity_verification_url = build_url_tech_floripa(
solana_response=solana_response,
validation_code=participant.formated_validation_code(),
order_id=participant.event.order_id
)
# alteração: agora usamos a função renomeada que apenas extrai o explorer_url
participant.authenticity_verification_url = extract_solana_explorer_url(solana_response=solana_response)

if not participant.authenticity_verification_url:
raise RuntimeError("Failed to get authenticity verification URL from Solana response")
Expand Down
6 changes: 6 additions & 0 deletions certified_builder/solana_explorer_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def extract_solana_explorer_url(solana_response: dict) -> str:
# alteração: extrai a URL do explorer do bloco "blockchain" conforme contrato oficial
explorer_url = solana_response.get("blockchain", {}).get("explorer_url", "")
return explorer_url


31 changes: 31 additions & 0 deletions tests/test_certified_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from models.certificate import Certificate
from models.event import Event
from datetime import datetime
from unittest.mock import patch

@pytest.fixture
def mock_certificate():
Expand Down Expand Up @@ -80,7 +81,37 @@ def test_create_validation_code_image(certified_builder, mock_participant, mock_
def test_build_certificates(certified_builder, mock_participant, mock_certificate_template, mock_logo):
participants = [mock_participant]

# comentário: mock do download de imagens e da resposta do serviço Solana para evitar chamada externa
with patch('certified_builder.utils.fetch_file_certificate.fetch_file_certificate', side_effect=[mock_certificate_template, mock_logo]), \
patch('certified_builder.certified_builder.CertificatesOnSolana.register_certificate_on_solana', return_value={
# comentário: mock alinhado ao contrato atual do serviço
"status": "sucesso",
"certificado": {
"event": "evento de teste",
"name": "user test",
"email": "user@test.com",
"uuid": "uuid-123",
"time": "2025-10-31 12:05:38",
"json_canonico": {"fake": "data"},
"hash_sha256": "deadbeef",
"txid_solana": "fake_txid_abc123",
"network": "devnet",
"timestamp": "2025-10-31 12:05:39",
"timestamp_unix": 1730366739
},
"blockchain": {
"rede": "Solana Devnet",
"explorer_url": "https://explorer.solana.com/tx/fake_txid_abc123?cluster=devnet",
"verificacao_url": "http://localhost:8000/certificados/verify/fake_txid_abc123",
"memo_program": "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
},
"validacao": {
"como_validar": "Recrie o JSON canonizado e compare o hash SHA-256",
"json_canonico_string": "{}",
"hash_esperado": "deadbeef",
"comando_validacao": "printf '{}' | shasum -a 256"
}
}), \
patch.object(certified_builder, 'save_certificate') as mock_save:

certified_builder.build_certificates(participants)
Expand Down