Add PostgreSQL support for mint and wallet (#878)

* Add PostgreSQL support for mint and wallet

* Fixed bug to avoid empty calls `get_proofs_states`

* Fixed SQL bug

* Avoid redudant clone()

* Add more tests for the storage layer

* Minor enhacements

* Add a generic function to execute db operations

This function would log slow operations and log errors

* Provision a postgres db for tests

* Update deps for msrv

* Add postgres to pipeline

* feat: add psgl to example and docker

* feat: db url fmt

---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
This commit is contained in:
C
2025-08-18 13:45:11 -03:00
committed by GitHub
parent 2e424e629f
commit 28a01398fd
34 changed files with 1282 additions and 40 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Script to run fake mint tests with proper handling of race conditions
# This script ensures the .env file is properly created and available
# This script ensures the .env file is properly created and available
# before running tests
# Function to perform cleanup
@@ -28,6 +28,10 @@ cleanup() {
echo "Temp directory removed: $CDK_ITESTS_DIR"
fi
if [ -n "$CONTAINER_NAME" ]; then
docker rm "${CONTAINER_NAME}" -f
fi
# Unset all environment variables
unset CDK_ITESTS_DIR
unset CDK_TEST_MINT_URL
@@ -56,6 +60,31 @@ cargo build -p cdk-integration-tests
# Start the fake mint binary with the new Rust-based approach
echo "Starting fake mint using Rust binary..."
if [ "${CDK_MINTD_DATABASE}" = "POSTGRES" ]; then
export CONTAINER_NAME="rust-fake-test-pg"
DB_USER="test"
DB_PASS="test"
DB_NAME="testdb"
DB_PORT="15433"
docker run -d --rm \
--name "${CONTAINER_NAME}" \
-e POSTGRES_USER="${DB_USER}" \
-e POSTGRES_PASSWORD="${DB_PASS}" \
-e POSTGRES_DB="${DB_NAME}" \
-p ${DB_PORT}:5432 \
postgres:16
export CDK_MINTD_DATABASE_URL="postgresql://${DB_USER}:${DB_PASS}@localhost:${DB_PORT}/${DB_NAME}"
echo "Waiting for PostgreSQL to be ready and database '${DB_NAME}' to exist..."
until docker exec -e PGPASSWORD="${DB_PASS}" "${CONTAINER_NAME}" \
psql -U "${DB_USER}" -d "${DB_NAME}" -c "SELECT 1;" >/dev/null 2>&1; do
sleep 0.5
done
echo "PostgreSQL container is ready"
fi
if [ "$2" = "external_signatory" ]; then
echo "Starting with external signatory support"
@@ -64,7 +93,7 @@ if [ "$2" = "external_signatory" ]; then
cargo run --bin signatory -- -w $CDK_ITESTS_DIR -u "sat" -u "usd" &
export CDK_SIGNATORY_PID=$!
sleep 5
cargo run --bin start_fake_mint -- --enable-logging --external-signatory "$CDK_MINTD_DATABASE" "$CDK_ITESTS_DIR" &
else
cargo run --bin start_fake_mint -- --enable-logging "$CDK_MINTD_DATABASE" "$CDK_ITESTS_DIR" &