cashubtc / nutshell

Chaumian ecash wallet and mint for Bitcoin
https://docs.cashu.space
MIT License
379 stars 95 forks source link

[Mint] Write test pipeline with `LIGHTNING=True` #128

Open callebtc opened 1 year ago

callebtc commented 1 year ago

All tests right now use LIGHTNING=False (a lot easier to test things) but it would be great if some also test Lightning functions. We would have to set up an LNbits instance in the tests (with FakeWallet, i.e. not using the real Lightning network).

AngusP commented 1 year ago

I've used this testing library VCR a lot before, it's great for testing things that need to make requests where it's a pain to set up all the things you need to make requests to, or where responses can change over time making tests non-deterministic (e.g. secrets are ephemeral, tokens are invalid once spent, etc.).

It stores fixtures for responses and intercepts/monkey-patches the requesting library (works with requests, aiohttp, httpx, etc.) mocking the fixture in.

Also useful for catching regressions and unintended behaviour changes too

callebtc commented 1 year ago

Maybe @xphade would be interested in this issue. Emulating Lightning with FakeWallet should work well by now!

xphade commented 1 year ago

Yes! I was pretty low on time the last couple of weeks but I would definitely like to work on the tests a bit next. So this would be something I can look into.

dyKiU commented 1 year ago

Here's a branch with cashu using python 3.10 and a cashu friendly version of lnbits as dependency.

https://github.com/dyKiU/cashu/tree/fake-lnbits-test

This is to avoid to a circular dependency of cashu -> lnbits -> old cashu The script tests/lnbits_env.sh sets up env for lnbits, runs poetry install and launches lnbits in the background Tests have been changed to use lightning and lnbits FakeWallet (!!! very broken still !!!)

dyKiU commented 1 year ago

So close to cashu tests with lighting via lnbits, until the main branch hit us with deps update. Now trying to get lnbits to use pydandic v2. This is challenging! Brain needs help https://github.com/dyKiU/cashu/tree/topic/tests_with_ln_brrr

dni commented 1 year ago

i want lnbits with pydantic v2 aswell :) first needs lnurl lib to use it though, and i am struggling to make it happen here. https://github.com/lnbits/lnurl/pull/21

dyKiU commented 1 year ago

Thanks @dni, your repos made me think about a way around lnbits as a dependency using docker compose, but we actually need some of the lnbits python in the tests. The maintanance and package updates for cashu will be quite challenging with lnbits in tow.

dni commented 1 year ago

i would rather use the lib directly https://github.com/cashubtc/cashu/pull/297 like here with the bolt11 lib