From a83679f00eafe696355f6ced18bc4374e6e5c6b6 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Tue, 1 Jul 2025 14:27:57 -0400 Subject: [PATCH] Add real Nostr integration test --- .github/workflows/python-ci.yml | 3 +++ pytest.ini | 2 ++ src/tests/test_nostr_real.py | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/tests/test_nostr_real.py diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml index 2fd7825..80195a6 100644 --- a/.github/workflows/python-ci.yml +++ b/.github/workflows/python-ci.yml @@ -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: | diff --git a/pytest.ini b/pytest.ini index 981d40f..321b4ce 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,3 +2,5 @@ log_cli = true log_cli_level = INFO testpaths = src/tests +markers = + network: tests that require network connectivity diff --git a/src/tests/test_nostr_real.py b/src/tests/test_nostr_real.py new file mode 100644 index 0000000..18a82bf --- /dev/null +++ b/src/tests/test_nostr_real.py @@ -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