2025-05-29 09:33:05 -07:00
# Waku Browser Tests
2025-10-07 10:54:19 -07:00
This package provides a containerized Waku light node simulation server for testing and development. The server runs a headless browser using Playwright and exposes a REST API similar to the nwaku REST API. A Dockerfile is provided to allow programmatic simulation and "deployment" of js-waku nodes in any Waku orchestration environment that uses Docker (e.g. [10ksim ](https://github.com/vacp2p/10ksim ) ).
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
## Quick Start
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Build and Run
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
```bash
# Build the application
npm run build
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
# Start the server (port 8080)
npm run start:server
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
# Build and run Docker container
npm run docker:build
docker run -p 8080:8080 waku-browser-tests:local
```
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
## Configuration
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
Configure the Waku node using environment variables:
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Network Configuration
- `WAKU_CLUSTER_ID` : Cluster ID (default: 1)
- `WAKU_SHARD` : Specific shard number - enables static sharding mode (optional)
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
**Sharding Behavior:**
- **Auto-sharding** (default): Uses `numShardsInCluster: 8` across cluster 1
- **Static sharding**: When `WAKU_SHARD` is set, uses only that specific shard
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Bootstrap Configuration
- `WAKU_ENR_BOOTSTRAP` : Enable ENR bootstrap mode with custom bootstrap peers (comma-separated)
- `WAKU_LIGHTPUSH_NODE` : Preferred lightpush node multiaddr (Docker only)
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### ENR Bootstrap Mode
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
When `WAKU_ENR_BOOTSTRAP` is set:
- Disables default bootstrap (`defaultBootstrap: false` )
- Enables DNS discovery using production ENR trees
- Enables peer exchange and peer cache
- Uses the specified ENR for additional bootstrap peers
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
# Example: ENR bootstrap mode
WAKU_ENR_BOOTSTRAP="enr:-QEnuEBEAyErHEfhiQxAVQoWowGTCuEF9fKZtXSd7H_PymHFhGJA3rGAYDVSHKCyJDGRLBGsloNbS8AZF33IVuefjOO6BIJpZIJ2NIJpcIQS39tkim11bHRpYWRkcnO4lgAvNihub2RlLTAxLmRvLWFtczMud2FrdXYyLnRlc3Quc3RhdHVzaW0ubmV0BgG73gMAODcxbm9kZS0wMS5hYy1jbi1ob25na29uZy1jLndha3V2Mi50ZXN0LnN0YXR1c2ltLm5ldAYBu94DACm9A62t7AQL4Ef5ZYZosRpQTzFVAB8jGjf1TER2wH-0zBOe1-MDBNLeA4lzZWNwMjU2azGhAzfsxbxyCkgCqq8WwYsVWH7YkpMLnU2Bw5xJSimxKav-g3VkcIIjKA" npm run start:server
2025-05-29 09:33:05 -07:00
```
## API Endpoints
2025-10-07 10:54:19 -07:00
The server exposes the following HTTP endpoints:
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Node Management
- `GET /` : Health check - returns server status
- `GET /waku/v1/peer-info` : Get node peer information
- `POST /waku/v1/wait-for-peers` : Wait for peers with specific protocols
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Messaging
- `POST /lightpush/v3/message` : Send message via lightpush
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Static Files
- `GET /app/index.html` : Web application entry point
- `GET /app/*` : Static web application files
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
### Examples
#### Send a Message (Auto-sharding)
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
curl -X POST http://localhost:8080/lightpush/v3/message \
2025-05-29 09:33:05 -07:00
-H "Content-Type: application/json" \
-d '{
2025-10-07 10:54:19 -07:00
"pubsubTopic": "",
2025-05-29 09:33:05 -07:00
"message": {
2025-10-07 10:54:19 -07:00
"contentTopic": "/test/1/example/proto",
"payload": "SGVsbG8gV2FrdQ==",
"version": 1
2025-05-29 09:33:05 -07:00
}
}'
```
2025-10-07 10:54:19 -07:00
#### Send a Message (Explicit pubsub topic)
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
curl -X POST http://localhost:8080/lightpush/v3/message \
2025-05-29 09:33:05 -07:00
-H "Content-Type: application/json" \
-d '{
2025-10-07 10:54:19 -07:00
"pubsubTopic": "/waku/2/rs/1/4",
"message": {
"contentTopic": "/test/1/example/proto",
"payload": "SGVsbG8gV2FrdQ==",
"version": 1
2025-05-29 09:33:05 -07:00
}
}'
```
2025-10-07 10:54:19 -07:00
#### Wait for Peers
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
curl -X POST http://localhost:8080/waku/v1/wait-for-peers \
2025-05-29 09:33:05 -07:00
-H "Content-Type: application/json" \
-d '{
2025-10-07 10:54:19 -07:00
"timeoutMs": 30000,
"protocols": ["lightpush", "filter"]
2025-05-29 09:33:05 -07:00
}'
```
2025-10-07 10:54:19 -07:00
#### Get Peer Info
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
curl -X GET http://localhost:8080/waku/v1/peer-info
2025-05-29 09:33:05 -07:00
```
2025-10-07 10:54:19 -07:00
## CLI Usage
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
Run with CLI arguments:
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
```bash
# Custom cluster and shard
node dist/src/server.js --cluster-id=2 --shard=0
2025-05-29 09:33:05 -07:00
```
2025-10-07 10:54:19 -07:00
## Testing
The package includes several test suites:
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
# Basic server functionality tests (default)
npm test
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
# Docker testing workflow
npm run docker:build
npm run test:integration
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
# All tests
npm run test:all
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
# Individual test suites:
npm run test:server # Server-only tests
npm run test:e2e # End-to-end tests
```
**Test Types:**
- `server.spec.ts` - Tests basic server functionality and static file serving
- `integration.spec.ts` - Tests Docker container integration with external services
- `e2e.spec.ts` - Full end-to-end tests using nwaku nodes
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
## Docker Usage
2025-05-29 09:33:05 -07:00
2025-10-07 10:54:19 -07:00
The package includes Docker support for containerized testing:
2025-05-29 09:33:05 -07:00
```bash
2025-10-07 10:54:19 -07:00
# Build image
docker build -t waku-browser-tests:local .
# Run with ENR bootstrap
docker run -p 8080:8080 \
-e WAKU_ENR_BOOTSTRAP="enr:-QEnuE..." \
-e WAKU_CLUSTER_ID="1" \
waku-browser-tests:local
# Run with specific configuration
docker run -p 8080:8080 \
-e WAKU_CLUSTER_ID="2" \
-e WAKU_SHARD="0" \
waku-browser-tests:local
2025-05-29 09:33:05 -07:00
```
2025-10-07 10:54:19 -07:00
## Development
The server automatically:
- Creates a Waku light node on startup
- Configures network settings from environment variables
- Enables appropriate protocols (lightpush, filter)
- Handles peer discovery and connection management
All endpoints are CORS-enabled for cross-origin requests.