Pubky Testnet
A local test network for developing Pubky Core or applications depending on it.
All resources are ephemeral, including the database, and all servers are cleaned up when the testnet is dropped.
Quickstart
Option 1: Docker PostgreSQL (No External DB Required)
For testing without a separate Postgres installation, enable the docker-postgres feature:
[]
= { = "0.9", = ["docker-postgres"] }
#
#
#
use EphemeralTestnet;
#
async
This uses testcontainers to run PostgreSQL in a Docker container. Docker must be running on the host. The container is automatically cleaned up on drop and on Ctrl+C/SIGTERM.
Important: If you have multiple tests, see Sharing Docker Postgres Across Tests below.
Option 2: External PostgreSQL
If you prefer to use an external Postgres instance:
# Example local Postgres with password auth
Then run the testnet binary:
TEST_PUBKY_CONNECTION_STRING='postgres://postgres:postgres@localhost:5432/postgres?pubky-test=true'
Usage
Writing Tests
use EphemeralTestnet;
// Macro ensures ephemeral Postgres databases are cleaned up
async
Custom Postgres Connection
By default (without docker-postgres), testnet will use postgres://localhost:5432/postgres?pubky-test=true.
The ?pubky-test=true parameter indicates that the homeserver should create an ephemeral database.
To use a custom connection string:
Option A: Set the TEST_PUBKY_CONNECTION_STRING environment variable.
Option B: Pass the connection string programmatically:
use ;
async
Custom Configuration
use ;
async
Sharing Docker Postgres Across Tests
When using docker-postgres, each call to .with_docker_postgres() starts a separate PostgreSQL container.
Use DockerPostgres::shared() to start one container and share its connection string across all tests.
Docker handles cleanup automatically when the process exits.
use EphemeralTestnet;
use DockerPostgres;
async
async
Each testnet still gets its own ephemeral database within the shared PostgreSQL instance, so tests remain isolated.
Troubleshooting
Docker not running
The docker-postgres feature requires Docker. If you see "Is Docker running?" errors, ensure the Docker daemon is started and your user has permission to access it (e.g., is in the docker group).
Docker Hub rate limits
The Postgres image is pulled from Docker Hub. Anonymous pulls are limited to 100 per 6 hours. If you hit this, either docker login or pre-pull the image:
Once cached locally, subsequent test runs won't pull again.
Binary (Static Testnet)
If you need to run the testnet in a separate process (e.g., to test Pubky Core in browsers), run the binary which creates these components with hardcoded configurations: