junction
junction copied to clipboard
What to test exactly
This thing needs tests:
- Watch-only wallet creation and address generation
- PSBT lifecycle
- ...
In the current state the application is not very testable. I tried to create tests but creating the app-for testing purposes is quite difficult, mainly because of: https://github.com/justinmoon/junction/blob/master/ui.py#L11
Although Unittests of Classes and helper-utils might even be possible, in practice most python-files use dependencies from flask which results in "outside app-context issues" when testing. Also, if you you don't have any tests, it's usually better to start end2end-testing rather then unit-testing.
Therefore i'd like to get this project in a testable shape rather early on. I'm not sure whether you're biased to anything or have strong opinions on how to test that stuff. Here is a rough idea on what worked for me on a midsize flask-project with 90+ tests and roughly 80% test-coverage:
- pytest with tests outside application-directory like here: https://docs.pytest.org/en/latest/goodpractices.html#tests-outside-application-code
- using pytest-fixtures heavily
- Creating the application in a function similiar to this description: https://flask.palletsprojects.com/en/1.0.x/tutorial/factory/
- The tests, though, are importing their dependencies inside their functions. I never was very happy with this approach but couldn't find an alternative. Here is an example how such a test look like:
def test_dashboard(client, fresh_user_with_purchases):
#pylint: disable=unused-argument
''' tests the dashboard '''
from someapp.models import db
db.session.add(fresh_user_with_purchases)
result = login(client, fresh_user_with_purchases.email, 'bla')
assert b'Logged in successfully.' in result.data
print_messages(result.data)
result = client.get('/dashboard')
assert b'some other text' in result.data
Would such an approach work for you? I'm happy to work on that but it will include some heavy changes in filestructures and the way the app is started/tested.
I want to start by testing junction.py. I'm mostly concerned with:
- Wallet file IO
- Watch-only wallet creation / export
- Address index logic
- Add / remove signer logic
I've got a testing
branch where I'm starting to do this
The UI is currently being rewritten (typescript
branch) so it's probably premature to test it ...