Skip to content
Open
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
5 changes: 4 additions & 1 deletion node/utxo_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ def utxo_transfer():
}), 400

# Verify pubkey → address
expected_addr = _addr_from_pk_fn(public_key)
try:
expected_addr = _addr_from_pk_fn(public_key)
except ValueError:
return jsonify({'error': 'Invalid public_key'}), 400
if from_address != expected_addr:
return jsonify({
'error': 'Public key does not match from_address',
Expand Down
16 changes: 16 additions & 0 deletions tests/test_utxo_transfer_json_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ def test_utxo_transfer_rejects_structured_string_fields(client, field, value):
assert response.get_json() == {"error": f"{field} must be a string"}


def test_utxo_transfer_rejects_malformed_public_key_material(client, monkeypatch):
monkeypatch.setattr(
utxo_endpoints,
"_addr_from_pk_fn",
lambda public_key: (_ for _ in ()).throw(ValueError("bad hex")),
)

response = client.post(
"/utxo/transfer",
json=_transfer_payload(public_key="not-hex"),
)

assert response.status_code == 400
assert response.get_json() == {"error": "Invalid public_key"}


def test_utxo_transfer_still_reports_missing_trimmed_string_fields(client):
response = client.post(
"/utxo/transfer",
Expand Down