mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 15:28:44 +00:00
Merge pull request #103 from PR0M3TH3AN/codex/introduce-mutmut-in-requirements.txt-and-ci-workflow
Add mutation testing and Nostr contract test
This commit is contained in:
4
.github/workflows/python-ci.yml
vendored
4
.github/workflows/python-ci.yml
vendored
@@ -72,8 +72,8 @@ jobs:
|
|||||||
if [ "${{ github.event_name }}" = "schedule" ]; then
|
if [ "${{ github.event_name }}" = "schedule" ]; then
|
||||||
echo "STRESS_ARGS=--stress" >> $GITHUB_ENV
|
echo "STRESS_ARGS=--stress" >> $GITHUB_ENV
|
||||||
fi
|
fi
|
||||||
- name: Enable Nostr network tests on main branch
|
- name: Enable Nostr network tests on main branch or nightly
|
||||||
if: github.ref == 'refs/heads/main'
|
if: github.ref == 'refs/heads/main' || github.event_name == 'schedule'
|
||||||
run: echo "NOSTR_E2E=1" >> $GITHUB_ENV
|
run: echo "NOSTR_E2E=1" >> $GITHUB_ENV
|
||||||
- name: Run tests with coverage
|
- name: Run tests with coverage
|
||||||
shell: bash
|
shell: bash
|
||||||
|
10
README.md
10
README.md
@@ -195,6 +195,16 @@ pip install -r src/requirements.txt
|
|||||||
pytest -vv
|
pytest -vv
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To run mutation tests locally, generate coverage data first and then execute `mutmut`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pytest --cov=src src/tests
|
||||||
|
python -m mutmut run --paths-to-mutate src --tests-dir src/tests --runner "python -m pytest -q" --use-coverage --no-progress
|
||||||
|
python -m mutmut results
|
||||||
|
```
|
||||||
|
|
||||||
|
Mutation testing is disabled in the GitHub workflow due to reliability issues and should be run on a desktop environment instead.
|
||||||
|
|
||||||
## Security Considerations
|
## Security Considerations
|
||||||
|
|
||||||
**Important:** The password you use to encrypt your parent seed is also required to decrypt the seed index data retrieved from Nostr. **It is imperative to remember this password** and be sure to use it with the same seed, as losing it means you won't be able to access your stored index. Secure your 12-word seed **and** your master password.
|
**Important:** The password you use to encrypt your parent seed is also required to decrypt the seed index data retrieved from Nostr. **It is imperative to remember this password** and be sure to use it with the same seed, as losing it means you won't be able to access your stored index. Secure your 12-word seed **and** your master password.
|
||||||
|
@@ -18,3 +18,4 @@ websocket-client==1.7.0
|
|||||||
websockets>=15.0.0
|
websockets>=15.0.0
|
||||||
tomli
|
tomli
|
||||||
hypothesis
|
hypothesis
|
||||||
|
mutmut==2.4.4
|
||||||
|
76
src/tests/test_nostr_contract.py
Normal file
76
src/tests/test_nostr_contract.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest.mock import patch
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
class MockNostrServer:
|
||||||
|
def __init__(self):
|
||||||
|
self.events = []
|
||||||
|
|
||||||
|
|
||||||
|
class MockClient:
|
||||||
|
def __init__(self, server):
|
||||||
|
self.server = server
|
||||||
|
|
||||||
|
async def add_relays(self, relays):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def add_relay(self, relay):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def connect(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def disconnect(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def send_event(self, event):
|
||||||
|
self.server.events.append(event)
|
||||||
|
|
||||||
|
class FakeId:
|
||||||
|
def to_hex(self_inner):
|
||||||
|
return "abcd"
|
||||||
|
|
||||||
|
class FakeOutput:
|
||||||
|
def __init__(self):
|
||||||
|
self.id = FakeId()
|
||||||
|
|
||||||
|
return FakeOutput()
|
||||||
|
|
||||||
|
async def fetch_events(self, filter_obj, timeout):
|
||||||
|
class FakeEvents:
|
||||||
|
def __init__(self, events):
|
||||||
|
self._events = events
|
||||||
|
|
||||||
|
def to_vec(self):
|
||||||
|
return self._events
|
||||||
|
|
||||||
|
return FakeEvents(self.server.events[-1:])
|
||||||
|
|
||||||
|
|
||||||
|
def setup_client(tmp_path, server):
|
||||||
|
key = Fernet.generate_key()
|
||||||
|
enc_mgr = EncryptionManager(key, tmp_path)
|
||||||
|
|
||||||
|
with patch("nostr.client.Client", lambda signer: MockClient(server)), patch(
|
||||||
|
"nostr.client.KeyManager"
|
||||||
|
) as MockKM, patch.object(enc_mgr, "decrypt_parent_seed", return_value="seed"):
|
||||||
|
km_inst = MockKM.return_value
|
||||||
|
km_inst.keys.private_key_hex.return_value = "1" * 64
|
||||||
|
km_inst.keys.public_key_hex.return_value = "2" * 64
|
||||||
|
client = NostrClient(enc_mgr, "fp", relays=["ws://mock"])
|
||||||
|
return client
|
||||||
|
|
||||||
|
|
||||||
|
def test_publish_and_retrieve(tmp_path):
|
||||||
|
server = MockNostrServer()
|
||||||
|
client = setup_client(tmp_path, server)
|
||||||
|
payload = b"contract-test"
|
||||||
|
assert client.publish_json_to_nostr(payload) is True
|
||||||
|
assert client.retrieve_json_from_nostr_sync() == payload
|
Reference in New Issue
Block a user