| Crates.io | pubky-testnet |
| lib.rs | pubky-testnet |
| version | 0.6.0 |
| created_at | 2025-02-13 18:01:57.986211+00 |
| updated_at | 2026-01-15 03:20:54.900875+00 |
| description | A local test network for Pubky Core development. |
| homepage | https://github.com/pubky/pubky-core |
| repository | https://github.com/pubky/pubky-core |
| max_upload_size | |
| id | 1554538 |
| size | 172,518 |
A local test network for developing Pubky Core or applications depending on it.
All resources are ephemeral, the database is an empheral Postgres, and all servers are cleaned up as the testnet dropped.
Requires a running Postgres.
# Example local Postgres with password auth
docker run --name postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=pubky_homeserver \
-p 127.0.0.1:5432:5432 \
-d postgres:18-alpine
TEST_PUBKY_CONNECTION_STRING='postgres://postgres:postgres@localhost:5432/postgres?pubky-test=true' cargo run -p pubky-testnet
For the homeserver and therefore this testnet to be used, a postgres server is required.
By default, testnet will use postgres://localhost:5432/postgres?pubky-test=true.
?pubky-test=true indicates that the homeserver should create an emphemeral database.
If you want to change the connection string you have 2 options.
TEST_PUBKY_CONNECTION_STRING environment variable.use pubky_testnet::{Testnet, pubky_homeserver::ConnectionString};
#[tokio::main]
async fn main () {
let connection_string = ConnectionString::new("postgres://localhost:5432/my_db").unwrap();
let testnet = Testnet::new_with_custom_postgres(connection_string).await.unwrap();
}
use pubky_testnet::EphemeralTestnet;
#[tokio::main]
#[pubky_testnet::test] // Macro makes sure that the ephemeral Postgres databases are cleaned up.
async fn main () {
// Run a new testnet. This creates a test DHT and homeserver.
// By default, uses minimal_test_config() (admin/metrics disabled, no HTTP relay).
let testnet = EphemeralTestnet::builder().build().await.unwrap();
// Create a Pubky Http Client from the testnet.
let client = testnet.client().unwrap();
// Use the homeserver
let homeserver = testnet.homeserver_app();
}
use pubky_testnet::{EphemeralTestnet, pubky_homeserver::ConfigToml, pubky::Keypair};
#[tokio::main]
async fn main () {
// Enable admin server for tests that need it
let testnet = EphemeralTestnet::builder()
.config(ConfigToml::default_test_config())
.build()
.await
.unwrap();
// Or use a custom keypair
let testnet = EphemeralTestnet::builder()
.keypair(Keypair::random())
.build()
.await
.unwrap();
// Enable HTTP relay for tests that need it
let testnet = EphemeralTestnet::builder()
.with_http_relay()
.build()
.await
.unwrap();
let http_relay = testnet.http_relay();
}
If you need to run the testnet in a separate process, for example to test Pubky Core in browsers, you need to run this binary, which will create these components with hardcoded configurations: