Fix tests review

This commit is contained in:
koalasat
2025-04-26 18:49:37 +02:00
parent 5e57223e4a
commit 2ee48f3108
3 changed files with 6 additions and 17 deletions

View File

@ -4,7 +4,7 @@ import uuid
from secp256k1 import PrivateKey
from asgiref.sync import sync_to_async
from nostr_sdk import Keys, Client, EventBuilder, NostrSigner, Kind, Tag, PublicKey
from nostr_sdk import Keys, Client, EventBuilder, NostrSigner, Kind, Tag
from api.models import Order
from decouple import config
@ -115,13 +115,6 @@ class Nostr:
return ["lightning"]
return False
def is_valid_public_key(public_key_hex):
try:
PublicKey.from_hex(public_key_hex)
return True
except Exception:
return False
def sign_message(text: str) -> str:
try:
keys = Keys.parse(config("NOSTR_NSEC", cast=str))

View File

@ -1066,15 +1066,9 @@ class ReviewView(APIView):
status.HTTP_400_BAD_REQUEST,
)
if not request.user.robot.nostr_pubkey:
verified = Nostr.is_valid_public_key(pubkey)
if verified:
request.user.robot.nostr_pubkey = pubkey
request.user.robot.save(update_fields=["nostr_pubkey"])
else:
return Response(
{"bad_request": "Invalid hex pubkey"},
status.HTTP_400_BAD_REQUEST,
)
request.user.robot.nostr_pubkey = pubkey
request.user.robot.save(update_fields=["nostr_pubkey"])
if request.user.robot.nostr_pubkey != pubkey:
return Response(
{"bad_request": "Wrong hex pubkey"},

View File

@ -992,6 +992,8 @@ class TradeTest(BaseAPITestCase):
trade.process_payouts(mine_a_block=True)
trade.get_review(trade.maker_index)
data = trade.response.json()
print(data)
self.assertEqual(trade.response.status_code, 200)
nostr_pubkey = read_file(f"tests/robots/{trade.maker_index}/nostr_pubkey")
data = trade.response.json()