Adds initial test framework; adds PrivateKey.from_nsec() (#13)

* Adds initial test framework; adds PrivateKey.from_nsec()

* Update setup.py
This commit is contained in:
kdmukai
2022-12-27 14:40:50 -06:00
committed by GitHub
parent b5e99fc708
commit 2c93c1df20
7 changed files with 93 additions and 2 deletions

31
test/README.md Normal file
View File

@@ -0,0 +1,31 @@
# Testing python-nostr
## Set up the test environment
Install the test-runner dependencies:
```
pip3 install -r test/requirements.txt
```
Then make the `nostr` python module visible/importable to the tests by installing the local dev dir as an editable module:
```
# from the repo root
pip3 install -e .
```
## Running the test suite
Run the whole test suite:
```
# from the repo root
pytest
```
Run a specific test file:
```
pytest test/test_this_file.py
```
Run a specific test:
```
pytest test/test_this_file.py::test_this_specific_test
```

1
test/requirements.txt Normal file
View File

@@ -0,0 +1 @@
pytest>=7.2.0

23
test/test_key.py Normal file
View File

@@ -0,0 +1,23 @@
from nostr.key import PrivateKey
def test_eq_true():
""" __eq__ should return True when PrivateKeys are equal """
pk1 = PrivateKey()
pk2 = PrivateKey(pk1.raw_secret)
assert pk1 == pk2
def test_eq_false():
""" __eq__ should return False when PrivateKeys are not equal """
pk1 = PrivateKey()
pk2 = PrivateKey()
assert pk1.raw_secret != pk2.raw_secret
assert pk1 != pk2
def test_from_nsec():
""" PrivateKey.from_nsec should yield the source's raw_secret """
pk1 = PrivateKey()
pk2 = PrivateKey.from_nsec(pk1.bech32())
assert pk1.raw_secret == pk2.raw_secret