Skip to content

Commit

Permalink
Fix TxID lookup in e2e logging test (#6650)
Browse files Browse the repository at this point in the history
  • Loading branch information
achamayou authored Nov 14, 2024
1 parent b979233 commit 060b561
Showing 1 changed file with 34 additions and 45 deletions.
79 changes: 34 additions & 45 deletions tests/e2e_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -1028,62 +1028,51 @@ def test_cose_receipt_schema(network, args):
with primary.client() as client:
client.wait_for_commit(r)

txid = r.headers[infra.clients.CCF_TX_ID_HEADER]

service_cert_path = os.path.join(network.common_dir, "service_cert.pem")
service_cert = load_pem_x509_certificate(
open(service_cert_path, "rb").read(), default_backend()
)
service_key = service_cert.public_key()

with primary.client("user0") as client:
r = client.get("/commit")
assert r.status_code == http.HTTPStatus.OK
last_txid = TxID.from_str(r.body.json()["transaction_id"])
LOG.debug(f"Trying to get COSE receipt for txid {txid}")
max_retries = 10
for _ in range(max_retries):
r = client.get(
"/log/public/cose_receipt",
headers={infra.clients.CCF_TX_ID_HEADER: txid},
log_capture=[], # Do not emit raw binary to stdout
)

for seqno in range(last_txid.seqno, last_txid.seqno - 10, -1):
txid = f"{last_txid.view}.{seqno}"
LOG.debug(f"Trying to get COSE receipt for txid {txid}")
max_retries = 10
found_proof = False
for _ in range(max_retries):
r = client.get(
"/log/public/cose_receipt",
headers={infra.clients.CCF_TX_ID_HEADER: txid},
log_capture=[], # Do not emit raw binary to stdout
if r.status_code == http.HTTPStatus.OK:
cbor_proof = r.body.data()
receipt_phdr = ccf.cose.verify_receipt(
cbor_proof, service_key, b"\0" * 32
)

if r.status_code == http.HTTPStatus.OK:
cbor_proof = r.body.data()
receipt_phdr = ccf.cose.verify_receipt(
cbor_proof, service_key, b"\0" * 32
)
assert receipt_phdr[15][1] == "service.example.com"
assert receipt_phdr[15][2] == "ledger.signature"
cbor_proof_filename = os.path.join(
network.common_dir, f"receipt_{txid}.cose"
)
with open(cbor_proof_filename, "wb") as f:
f.write(cbor_proof)
subprocess.run(
["cddl", "../cddl/ccf-receipt.cddl", "v", cbor_proof_filename],
check=True,
)
found_proof = True
LOG.debug(f"Checked COSE receipt for txid {txid}")
break
elif r.status_code == http.HTTPStatus.ACCEPTED:
LOG.debug(f"Transaction {txid} accepted, retrying")
time.sleep(0.1)
elif r.status_code == http.HTTPStatus.NOT_FOUND:
LOG.debug(f"Transaction {txid} is a signature")
break
else:
assert (
False
), f"Failed to get receipt for txid {txid} after {max_retries} retries"
if found_proof:
assert receipt_phdr[15][1] == "service.example.com"
assert receipt_phdr[15][2] == "ledger.signature"
cbor_proof_filename = os.path.join(
network.common_dir, f"receipt_{txid}.cose"
)
with open(cbor_proof_filename, "wb") as f:
f.write(cbor_proof)
subprocess.run(
["cddl", "../cddl/ccf-receipt.cddl", "v", cbor_proof_filename],
check=True,
)
LOG.debug(f"Checked COSE receipt for txid {txid}")
break
elif r.status_code == http.HTTPStatus.ACCEPTED:
LOG.debug(f"Transaction {txid} accepted, retrying")
time.sleep(0.1)
else:
assert False, r
else:
assert False, "Failed to find a non-signature in the last 10 transactions"
assert (
False
), f"Failed to get receipt for txid {txid} after {max_retries} retries"

return network

Expand Down

0 comments on commit 060b561

Please sign in to comment.