Skip to content

Commit

Permalink
Postgres migrations: remove balance view before children (#353)
Browse files Browse the repository at this point in the history
* remove balance view before childredn

* update readme

* CI with postgres

* install postgres in CI

* run postgres tests in CI?

* disable postgres tests for now
  • Loading branch information
callebtc authored Nov 1, 2023
1 parent aa36651 commit a4abbc2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,14 +42,15 @@ jobs:
cache: "poetry"
- name: Install dependencies
run: |
poetry install
poetry install --extras pgsql
shell: bash
- name: Run tests
env:
LIGHTNING: false
WALLET_NAME: test_wallet
MINT_HOST: localhost
MINT_PORT: 3337
MINT_DATABASE: ${{ inputs.db-url }}
TOR: false
run: |
make test
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cashu/mint/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 9 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit a4abbc2

Please sign in to comment.