Tests: split wallet test from mint test pipeline (#748)

* split wallet test from mint test pipeline

* regtest mint and wallet

* fix

* fix

* move mint tests

* real invoice in regtest mpp
This commit is contained in:
callebtc
2025-05-11 14:14:49 +02:00
committed by GitHub
parent 619d06f0ab
commit 38bdb9ce76
35 changed files with 137 additions and 15 deletions

View File

@@ -57,8 +57,24 @@ jobs:
poetry-version: ${{ matrix.poetry-version }}
mint-database: ${{ matrix.mint-database }}
regtest:
uses: ./.github/workflows/regtest.yml
regtest-mint:
uses: ./.github/workflows/regtest-mint.yml
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]
poetry-version: ["1.8.5"]
backend-wallet-class:
["LndRPCWallet", "LndRestWallet", "CLNRestWallet", "CoreLightningRestWallet", "LNbitsWallet"]
mint-database: ["./test_data/test_mint", "postgres://cashu:cashu@localhost:5432/cashu"]
# mint-database: ["./test_data/test_mint"]
with:
python-version: ${{ matrix.python-version }}
backend-wallet-class: ${{ matrix.backend-wallet-class }}
mint-database: ${{ matrix.mint-database }}
regtest-wallet:
uses: ./.github/workflows/regtest-wallet.yml
strategy:
fail-fast: false
matrix:

View File

@@ -1,4 +1,4 @@
name: regtest
name: regtest-mint
on:
workflow_call:
@@ -20,7 +20,7 @@ on:
type: string
jobs:
regtest:
regtest-mint:
runs-on: ${{ inputs.os-version }}
timeout-minutes: 10
steps:
@@ -73,7 +73,7 @@ jobs:
MINT_CLNREST_CERT: ./regtest/data/clightning-2/regtest/ca.pem
run: |
sudo chmod -R 777 .
make test
make test-mint
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

79
.github/workflows/regtest-wallet.yml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: regtest-wallet
on:
workflow_call:
inputs:
python-version:
default: "3.10.4"
type: string
poetry-version:
default: "1.5.1"
type: string
os-version:
default: "ubuntu-latest"
type: string
mint-database:
default: ""
type: string
backend-wallet-class:
required: true
type: string
jobs:
regtest-wallet:
runs-on: ${{ inputs.os-version }}
timeout-minutes: 10
steps:
- name: Start PostgreSQL service
if: contains(inputs.mint-database, 'postgres')
run: |
docker run -d --name postgres -e POSTGRES_USER=cashu -e POSTGRES_PASSWORD=cashu -e POSTGRES_DB=cashu -p 5432:5432 postgres:latest
until docker exec postgres pg_isready; do sleep 1; done
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
with:
python-version: ${{ inputs.python-version }}
poetry-version: ${{ inputs.poetry-version }}
- name: Setup Regtest
run: |
git clone https://github.com/callebtc/cashu-regtest-enviroment.git regtest
cd regtest
chmod -R 777 .
bash ./start.sh
- name: Run Tests
env:
WALLET_NAME: test_wallet
MINT_HOST: localhost
MINT_PORT: 3337
MINT_TEST_DATABASE: ${{ inputs.mint-database }}
TOR: false
MINT_BACKEND_BOLT11_SAT: ${{ inputs.backend-wallet-class }}
# LNbits wallet
MINT_LNBITS_ENDPOINT: http://localhost:5001
MINT_LNBITS_KEY: d08a3313322a4514af75d488bcc27eee
# LndRestWallet
MINT_LND_REST_ENDPOINT: https://localhost:8081/
MINT_LND_REST_CERT: ./regtest/data/lnd-3/tls.cert
MINT_LND_REST_MACAROON: ./regtest/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon
# LndRPCWallet
MINT_LND_RPC_ENDPOINT: localhost:10009
MINT_LND_RPC_CERT: ./regtest/data/lnd-3/tls.cert
MINT_LND_RPC_MACAROON: ./regtest/data/lnd-3/data/chain/bitcoin/regtest/admin.macaroon
# CoreLightningRestWallet
MINT_CORELIGHTNING_REST_URL: https://localhost:3001
MINT_CORELIGHTNING_REST_MACAROON: ./regtest/data/clightning-2-rest/access.macaroon
MINT_CORELIGHTNING_REST_CERT: ./regtest/data/clightning-2-rest/certificate.pem
# CLNRestWallet
MINT_CLNREST_URL: https://localhost:3010
MINT_CLNREST_RUNE: ./regtest/data/clightning-2/rune
MINT_CLNREST_CERT: ./regtest/data/clightning-2/regtest/ca.pem
run: |
sudo chmod -R 777 .
make test-wallet
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3

View File

@@ -67,7 +67,7 @@ jobs:
MINT_AUTH_OICD_DISCOVERY_URL: http://localhost:8080/realms/nutshell/.well-known/openid-configuration
MINT_AUTH_OICD_CLIENT_ID: cashu-client
run: |
poetry run pytest tests/test_wallet_auth.py -v --cov=mint --cov-report=xml
poetry run pytest tests/wallet/test_wallet_auth.py -v --cov=mint --cov-report=xml
- name: Stop and clean up Docker Compose
run: |

View File

@@ -53,7 +53,7 @@ jobs:
MINT_REDIS_CACHE_ENABLED: true
MINT_REDIS_CACHE_URL: redis://localhost:6379
run: |
poetry run pytest tests/test_mint_api_cache.py -v --cov=mint --cov-report=xml
poetry run pytest tests/mint/test_mint_api_cache.py -v --cov=mint --cov-report=xml
- name: Stop and clean up Docker Compose
run: |

View File

@@ -27,6 +27,16 @@ test:
DEBUG=true \
poetry run pytest tests --cov-report xml --cov cashu
test-wallet:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest tests/wallet --cov-report xml --cov cashu
test-mint:
PYTHONUNBUFFERED=1 \
DEBUG=true \
poetry run pytest tests/mint --cov-report xml --cov cashu
test-lndrest:
PYTHONUNBUFFERED=1 \
DEBUG=true \

View File

@@ -3,7 +3,12 @@ import pytest
from cashu.core.base import MintKeyset, Unit
from cashu.core.settings import settings
from cashu.mint.ledger import Ledger
from tests.test_mint_init import DECRYPTON_KEY, DERIVATION_PATH, ENCRYPTED_SEED, SEED
from tests.mint.test_mint_init import (
DECRYPTON_KEY,
DERIVATION_PATH,
ENCRYPTED_SEED,
SEED,
)
async def assert_err(f, msg):
@@ -73,16 +78,27 @@ async def test_keyset_0_15_0_encrypted():
)
assert keyset.id == "009a1f293253e41e"
@pytest.mark.asyncio
async def test_keyset_rotation(ledger: Ledger):
keyset_sat = next(filter(lambda k: k.unit == Unit["sat"] and k.active, ledger.keysets.values()))
new_keyset_sat = await ledger.rotate_next_keyset(unit=Unit["sat"], max_order=20, input_fee_ppk=1)
keyset_sat = next(
filter(lambda k: k.unit == Unit["sat"] and k.active, ledger.keysets.values())
)
new_keyset_sat = await ledger.rotate_next_keyset(
unit=Unit["sat"], max_order=20, input_fee_ppk=1
)
keyset_sat_derivation = keyset_sat.derivation_path.split("/")
new_keyset_sat_derivation = keyset_sat.derivation_path.split("/")
assert keyset_sat_derivation[:-1] == new_keyset_sat_derivation[:-1], "keyset derivation does not match up to the counter branch"
assert int(new_keyset_sat_derivation[-1].replace("'", "")) - int(keyset_sat_derivation[-1].replace("'", "")) == 0, "counters should differ by exactly 1"
assert (
keyset_sat_derivation[:-1] == new_keyset_sat_derivation[:-1]
), "keyset derivation does not match up to the counter branch"
assert (
int(new_keyset_sat_derivation[-1].replace("'", ""))
- int(keyset_sat_derivation[-1].replace("'", ""))
== 0
), "counters should differ by exactly 1"
assert new_keyset_sat.input_fee_ppk == 1
assert len(new_keyset_sat.private_keys.values()) == 20

View File

@@ -17,6 +17,7 @@ from tests.helpers import (
assert_err,
cancel_invoice,
get_hold_invoice,
get_real_invoice,
is_fake,
partial_pay_real_invoice,
pay_if_regtest,
@@ -51,7 +52,7 @@ async def test_regtest_pay_mpp(wallet: Wallet, ledger: Ledger):
assert wallet.balance == 128
# this is the invoice we want to pay in two parts
preimage, invoice_dict = get_hold_invoice(64)
invoice_dict = get_real_invoice(64)
invoice_payment_request = str(invoice_dict["payment_request"])
async def _mint_pay_mpp(invoice: str, amount: int, proofs: List[Proof]):
@@ -116,7 +117,7 @@ async def test_regtest_pay_mpp_incomplete_payment(wallet: Wallet, ledger: Ledger
assert wallet.balance == 384
# this is the invoice we want to pay in two parts
preimage, invoice_dict = get_hold_invoice(64)
invoice_dict = get_real_invoice(64)
invoice_payment_request = str(invoice_dict["payment_request"])
async def pay_mpp(amount: int, proofs: List[Proof], delay: float = 0.0):