mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 19:34:18 +01:00
[FEAT] Improve tests (#296)
* test cli arent async tests * unused SERVER_ENDPOINT var * async test werent marked async * make test didnt use correct ports * enable more verbose test logging * refactor conftest variable * not needed anymore are set in conftest * using test_data now for conftest * formatting * comment out invalid hex * remove test dir before creating it to be sure * keep data from altest testrun and ad test_data to ignore * ignore error for CI * add duplicate env var * fix confest * Update pyproject.toml * fix up tests * short p2pk locktimes for faster tests --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
@@ -16,42 +16,36 @@ from cashu.lightning.fake import FakeWallet
|
||||
from cashu.mint import migrations as migrations_mint
|
||||
from cashu.mint.ledger import Ledger
|
||||
|
||||
SERVER_ENDPOINT = "http://localhost:3337"
|
||||
SERVER_PORT = 3337
|
||||
SERVER_ENDPOINT = f"http://localhost:{SERVER_PORT}"
|
||||
|
||||
settings.cashu_dir = "./test_data/"
|
||||
settings.mint_host = "localhost"
|
||||
settings.mint_port = SERVER_PORT
|
||||
settings.mint_host = "0.0.0.0"
|
||||
settings.mint_listen_port = SERVER_PORT
|
||||
settings.mint_url = SERVER_ENDPOINT
|
||||
settings.lightning = False
|
||||
settings.tor = False
|
||||
settings.mint_lightning_backend = "FakeWallet"
|
||||
settings.mint_database = "./test_data/test_mint"
|
||||
settings.mint_derivation_path = "0/0/0/0"
|
||||
settings.mint_private_key = "TEST_PRIVATE_KEY"
|
||||
|
||||
shutil.rmtree(settings.cashu_dir, ignore_errors=True)
|
||||
Path(settings.cashu_dir).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
class UvicornServer(multiprocessing.Process):
|
||||
def __init__(self, config: Config, private_key: str = "TEST_PRIVATE_KEY"):
|
||||
def __init__(self, config: Config):
|
||||
super().__init__()
|
||||
self.server = Server(config=config)
|
||||
self.config = config
|
||||
self.private_key = private_key
|
||||
|
||||
def stop(self):
|
||||
self.terminate()
|
||||
|
||||
def run(self, *args, **kwargs):
|
||||
settings.lightning = False
|
||||
settings.mint_lightning_backend = "FakeWallet"
|
||||
settings.mint_database = "data/test_mint"
|
||||
settings.mint_private_key = self.private_key
|
||||
settings.mint_derivation_path = "0/0/0/0"
|
||||
|
||||
dirpath = Path(settings.mint_database)
|
||||
if dirpath.exists() and dirpath.is_dir():
|
||||
shutil.rmtree(dirpath)
|
||||
|
||||
dirpath = Path("data/wallet1")
|
||||
if dirpath.exists() and dirpath.is_dir():
|
||||
shutil.rmtree(dirpath)
|
||||
|
||||
dirpath = Path("data/wallet2")
|
||||
if dirpath.exists() and dirpath.is_dir():
|
||||
shutil.rmtree(dirpath)
|
||||
|
||||
dirpath = Path("data/wallet3")
|
||||
if dirpath.exists() and dirpath.is_dir():
|
||||
shutil.rmtree(dirpath)
|
||||
|
||||
self.server.run()
|
||||
|
||||
|
||||
@@ -62,13 +56,13 @@ async def ledger():
|
||||
await ledger.load_used_proofs()
|
||||
await ledger.init_keysets()
|
||||
|
||||
db_file = "data/mint/test.sqlite3"
|
||||
db_file = "test_data/mint/test.sqlite3"
|
||||
if os.path.exists(db_file):
|
||||
os.remove(db_file)
|
||||
ledger = Ledger(
|
||||
db=Database("test", "data/mint"),
|
||||
seed="TEST_PRIVATE_KEY",
|
||||
derivation_path="0/0/0/0",
|
||||
db=Database("test", "test_data/mint"),
|
||||
seed=settings.mint_private_key,
|
||||
derivation_path=settings.mint_derivation_path,
|
||||
lightning=FakeWallet(),
|
||||
)
|
||||
await start_mint_init(ledger)
|
||||
@@ -77,12 +71,10 @@ async def ledger():
|
||||
|
||||
@pytest.fixture(autouse=True, scope="session")
|
||||
def mint():
|
||||
settings.mint_listen_port = 3337
|
||||
settings.mint_url = "http://localhost:3337"
|
||||
config = uvicorn.Config(
|
||||
"cashu.mint.app:app",
|
||||
port=settings.mint_listen_port,
|
||||
host="127.0.0.1",
|
||||
host=settings.mint_listen_host,
|
||||
)
|
||||
|
||||
server = UvicornServer(config=config)
|
||||
|
||||
Reference in New Issue
Block a user