Skip to content

Commit

Permalink
Playground follow up (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Harry Solovay <[email protected]>
  • Loading branch information
piotr-iohk and harrysolovay authored Sep 27, 2024
1 parent 8190607 commit d514feb
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
7 changes: 6 additions & 1 deletion Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ wait-for-pg:
./scripts/wait_for_pg.sh

test:
SNAP_CHECK=1 cargo test
SNAP_CHECK=1 cargo test

setup-archive-db:
just get-mainnet-archive-db
just pg
just wait-for-pg
67 changes: 57 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,71 @@ The binary will be available at:
target/debug/mina_mesh
```

## Testing
## Running

Mina Mesh requires access to a PostgreSQL Archive database and a Mina GraphQL endpoint. By default,
the configuration points to the mainnet, making it easy to get started. You can override the
configuration by either passing arguments or setting environment variables via a `.env` file (an
example is provided as `.env.example`).

### Quick Start with Mainnet

1. **Set up the PostgreSQL Archive Database**

Use the predefined `just` commands to set up and start the PostgreSQL database:

```bash
just setup-archive-db
```

> Note: This process sets up the PostgreSQL docker using the latest mainnet archive database.
2. **Run the Mina Mesh Server**

To start the server with default settings (mainnet configuration):

```bash
target/debug/mina_mesh serve
```

The server will listen on `0.0.0.0:3000` by default.

### Playground Mode

You can enable a playground mode, which provides a simplified testing interface, by adding the
`--playground` flag:

```bash
cargo run -- serve --playground
```

When enabled, you can access the playground at the root URL (`/`).

### Setup PostgreSQL with Latest Mainnet Archive DB
### Configuration

To set up the testing environment with a working PostgreSQL database, use the predefined `just`
steps:
Mina Mesh can be configured through command-line options or by using environment variables. For
convenience, you can use a `.env` file. To get started, copy the provided `.env.example`:

```bash
just get-mainnet-archive-db
just pg
just wait-for-pg
cp .env.example .env
```

> Note: This process sets up the environment using the latest mainnet archive database.
Then modify the `.env` file to suit your environment. The available configurations include:

### Run Tests
- **Mina GraphQL Endpoint**: `MINA_PROXY_URL` (default:
`https://mainnet.minaprotocol.network/graphql`)
- **PostgreSQL Archive Database URL**: `MINA_ARCHIVE_DATABASE_URL` (default:
`postgres://mina:whatever@localhost:5432/archive`)
- **Genesis Block Identifier**: `MINA_GENESIS_BLOCK_IDENTIFIER_HEIGHT`,
`MINA_GENESIS_BLOCK_IDENTIFIER_STATE_HASH`

> You can also pass these options as arguments to `mina_mesh serve` to override the defaults.
## Testing

Once the setup is complete, run the tests with:
Running the tests requires having Archive database available [see:
[Quick Start with Mainnet](#quick-start-with-mainnet)]. Once the setup is complete you can run tests
using:

```bash
just test
Expand Down
2 changes: 1 addition & 1 deletion src/bin/mina_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum Command {

#[tokio::main]
async fn main() -> Result<()> {
dotenv::dotenv()?;
dotenv::dotenv().ok();
match Command::parse() {
Command::Serve(cmd) => cmd.run().await,
Command::FetchGenesisBlockIdentifier(cmd) => cmd.run().await,
Expand Down
7 changes: 3 additions & 4 deletions src/commands/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ pub struct ServeCommand {
host: String,
#[arg(default_value = "3000")]
port: u16,
#[arg(env, long)]
/// Whether to enable the playground.
#[arg(env = "PLAYGROUND", long)]
playground: bool,
#[arg(env = "RUST_ENV", long)]
rust_env: String,
}

impl ServeCommand {
Expand All @@ -52,7 +51,7 @@ impl ServeCommand {
.route("/network/options", post(handle_network_options))
.route("/network/status", post(handle_network_status))
.with_state(Arc::new(mina_mesh));
if self.rust_env == "development" || self.playground {
if self.playground {
router = router.route("/", get(handle_playground));
}
let listener = TcpListener::bind(format!("{}:{}", self.host, self.port)).await?;
Expand Down

0 comments on commit d514feb

Please sign in to comment.