diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c99460b2..986e58e7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,11 +5,27 @@ on: [push, pull_request] jobs: poetry: runs-on: ${{ matrix.os }} + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: cashu + POSTGRES_PASSWORD: cashu + POSTGRES_DB: cashu + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 strategy: matrix: os: [ubuntu-latest] python-version: ["3.10.4"] poetry-version: ["1.5.1"] + # db-url: ["", "postgres://cashu:cashu@localhost:5432/test"] # TODO: Postgres test not working + db-url: [""] steps: - name: Checkout repository and submodules uses: actions/checkout@v2 @@ -26,7 +42,7 @@ jobs: cache: "poetry" - name: Install dependencies run: | - poetry install + poetry install --extras pgsql shell: bash - name: Run tests env: @@ -34,6 +50,7 @@ jobs: WALLET_NAME: test_wallet MINT_HOST: localhost MINT_PORT: 3337 + MINT_DATABASE: ${{ inputs.db-url }} TOR: false run: | make test diff --git a/README.md b/README.md index c359a570..190c25b0 100644 --- a/README.md +++ b/README.md @@ -76,18 +76,20 @@ source ~/.bashrc #### Poetry: Install Cashu ```bash # install cashu -git clone https://github.com/callebtc/cashu.git +git clone https://github.com/cashubtc/nutshell.git cashu cd cashu pyenv local 3.10.4 poetry install ``` +If you would like to use PostgreSQL as the mint database, use the command `poetry install --extras pgsql`. + #### Poetry: Update Cashu To update Cashu to the newest version enter ```bash git pull && poetry install ``` -#### Poetry: Using Cashu +#### Poetry: Using the Nutshell wallet Cashu should be now installed. To execute the following commands, activate your virtual Poetry environment via @@ -183,11 +185,13 @@ You can find the API docs at [http://localhost:4448/docs](http://localhost:4448/ # Running a mint This command runs the mint on your local computer. Skip this step if you want to use the [public test mint](#test-instance) instead. + +Before you can run your own mint, make sure to enable a Lightning backend in `MINT_LIGHTNING_BACKEND` and set `MINT_PRIVATE_KEY` in your `.env` file. ```bash -python -m cashu.mint +poetry run mint ``` -You can turn off Lightning support and mint as many tokens as you like by setting `LIGHTNING=FALSE` in the `.env` file. +For testing, you can use Nutshell without a Lightning backend by setting `MINT_LIGHTNING_BACKEND=FakeWallet` in the `.env` file. # Running tests diff --git a/cashu/mint/migrations.py b/cashu/mint/migrations.py index c2c7a937..5b9270ba 100644 --- a/cashu/mint/migrations.py +++ b/cashu/mint/migrations.py @@ -183,9 +183,9 @@ async def m009_add_out_to_invoices(db: Database): # column in invoices for marking whether the invoice is incoming (out=False) or outgoing (out=True) async with db.connect() as conn: # we have to drop the balance views first and recreate them later + await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance')}") await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_issued')}") await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance_redeemed')}") - await conn.execute(f"DROP VIEW {table_with_schema(db, 'balance')}") # rename column pr to bolt11 await conn.execute( diff --git a/tests/conftest.py b/tests/conftest.py index 02751323..39914079 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -57,11 +57,16 @@ async def start_mint_init(ledger: Ledger): await ledger.load_used_proofs() await ledger.init_keysets() - db_file = "test_data/mint/test.sqlite3" - if os.path.exists(db_file): - os.remove(db_file) + database_name = "test" + + if not settings.mint_database.startswith("postgres"): + # clear sqlite database + db_file = os.path.join(settings.mint_database, database_name + ".sqlite3") + if os.path.exists(db_file): + os.remove(db_file) + ledger = Ledger( - db=Database("test", "test_data/mint"), + db=Database(database_name, settings.mint_database), seed=settings.mint_private_key, derivation_path=settings.mint_derivation_path, lightning=FakeWallet(),