Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: making testnet script write a docker compose file #10333

Merged
merged 17 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions spartan/releases/rough-rhino/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore

# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Caches

.cache

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

*.tgz

# Yarn Integrity file

.yarn-integrity

# dotenv environment variable files

.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# parcel-bundler cache (https://parceljs.org/)

.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
docker-compose.yml
33 changes: 33 additions & 0 deletions spartan/releases/rough-rhino/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Aztec Spartan

This tool helps easing the entry barrier to boot an Aztec Sequencer and Prover (S&P) Testnet.

![Aztec Sparta Meme](./assets/banner.jpeg)

For once, there's no rocket science here. This script does the following:

- Checks for the presence of Docker in your machine
- Prompts you for some environment variables
- Outputs a templated docker-compose file with your variables
- Runs the docker compose file

## Prerequisites

This script should work in most UNIX-based machines. You should [have Node installed](https://github.com/nvm-sh/nvm/blob/master/README.md#install--update-script).

## Installation

To configure a new node, create a new directory and run the install script:

```bash
cd val1
npx aztec-spartan install
```

If you don't have Docker installed, the script will do it for you. It will then prompt for any required environment variables and output a `docker-compose.yml` file and a `.env` file.

You can run the command with `-h` to see all available options, and pass them as flags, i.e. `npx aztec-spartan install -p 8080 -p2p 40400 -n nameme`.

## Running

To spare you a few keystrokes, you can use `npx aztec-spartan [start/stop/logs/update]` to start, stop, output logs or pull the latest docker images.
Binary file added spartan/releases/rough-rhino/assets/banner.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added spartan/releases/rough-rhino/bun.lockb
Binary file not shown.
101 changes: 101 additions & 0 deletions spartan/releases/rough-rhino/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import {
describe,
expect,
test,
beforeAll,
afterAll,
beforeEach,
mock,
} from "bun:test";
import { execSync, spawnSync } from "child_process";
import { existsSync, unlinkSync, readFileSync } from "fs";
import { join } from "path";
import axios from "axios";

const CLI_PATH = join(__dirname, "index.ts");
const DOCKER_COMPOSE_PATH = join(__dirname, "docker-compose.yml");
const ENV_PATH = join(__dirname, ".env");

// Mock axios for getPublicIP
const mockedAxios = mock(axios);

beforeAll(() => {
// Clean up any existing files before each test
[DOCKER_COMPOSE_PATH, ENV_PATH].forEach((file) => {
if (existsSync(file)) {
unlinkSync(file);
}
});
});

afterAll(() => {
// Clean up after all tests
[DOCKER_COMPOSE_PATH, ENV_PATH].forEach((file) => {
if (existsSync(file)) {
unlinkSync(file);
}
});
});

describe("Test Suite", () => {
describe("CLI commands", () => {
beforeAll(() => {
// Mock axios response for IP
mockedAxios.mockResolvedValue({ data: { ip: "1.2.3.4" } });
});

test("shows version", () => {
const output = execSync(`bun ${CLI_PATH} --version`).toString();
expect(output).toContain("1.0.0");
});

test("shows help", () => {
const output = execSync(`bun ${CLI_PATH} --help`).toString();
expect(output).toContain("Aztec Testnet Node CLI");
expect(output).toContain("Commands:");
});

test("start command fails without configuration", () => {
try {
execSync(`bun ${CLI_PATH} start`, {
encoding: "utf8",
});
} catch (error: any) {
expect(error.message).toContain(
'Configuration not found. Please run "aztec-node init" first.'
);
}
});
});

describe("Install and Run", () => {
beforeAll(() => {
execSync(
`bun ${CLI_PATH} install -p 8080 -p2p 40400 -ip 7.7.7.7 -k 0x00 -n nameme`,
{
encoding: "utf8",
}
);
});

test("install command creates necessary files", async () => {
// Check if files were created
expect(existsSync(ENV_PATH)).toBe(true);
expect(existsSync(DOCKER_COMPOSE_PATH)).toBe(true);

// Verify .env content
const envContent = readFileSync(ENV_PATH, "utf8");
expect(envContent).toContain("p2pPort=40400");
expect(envContent).toContain("port=8080");
expect(envContent).toContain("key=0x00");
expect(envContent).toContain("ip=7.7.7.7");
expect(envContent).toContain("name=nameme");

// Verify docker-compose.yml content
const composeContent = readFileSync(DOCKER_COMPOSE_PATH, "utf8");
expect(composeContent).toContain("name: nameme");
expect(composeContent).toContain(`P2P_UDP_ANNOUNCE_ADDR=7.7.7.7:40400`);
expect(composeContent).toContain("AZTEC_PORT=8080");
});
});
});
Loading
Loading