Add real Nostr integration test

This commit is contained in:
thePR0M3TH3AN
2025-07-01 14:27:57 -04:00
parent 8de6b65071
commit a83679f00e
3 changed files with 42 additions and 0 deletions

View File

@@ -63,6 +63,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r src/requirements.txt
- name: Enable Nostr network tests on main branch
if: github.ref == 'refs/heads/main'
run: echo "NOSTR_E2E=1" >> $GITHUB_ENV
- name: Run tests with coverage
shell: bash
run: |

View File

@@ -2,3 +2,5 @@
log_cli = true
log_cli_level = INFO
testpaths = src/tests
markers =
network: tests that require network connectivity

View File

@@ -0,0 +1,37 @@
import os
import sys
import time
from pathlib import Path
from tempfile import TemporaryDirectory
from unittest.mock import patch
import pytest
from cryptography.fernet import Fernet
sys.path.append(str(Path(__file__).resolve().parents[1]))
from password_manager.encryption import EncryptionManager
from nostr.client import NostrClient
@pytest.mark.network
@pytest.mark.skipif(not os.getenv("NOSTR_E2E"), reason="NOSTR_E2E not set")
def test_nostr_publish_and_retrieve():
seed = (
"abandon abandon abandon abandon abandon abandon abandon "
"abandon abandon abandon abandon about"
)
with TemporaryDirectory() as tmpdir:
enc_mgr = EncryptionManager(Fernet.generate_key(), Path(tmpdir))
with patch.object(enc_mgr, "decrypt_parent_seed", return_value=seed):
client = NostrClient(
enc_mgr,
"test_fp_real",
relays=["wss://relay.snort.social"],
)
payload = b"seedpass"
assert client.publish_json_to_nostr(payload) is True
time.sleep(2)
retrieved = client.retrieve_json_from_nostr_sync()
client.close_client_pool()
assert retrieved == payload