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

feature: docker all in one #23

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions .github/workflows/e2e-docker-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run E2E Docker Tests

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
e2e-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository 📝
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
cache: "yarn"

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Build contracts
run: yarn build

- name: Run docker infra
run: |
yarn run docker
sleep 5

- name: Run E2E Tests
run: yarn test
4 changes: 0 additions & 4 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ on:
- main
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
e2e-tests:
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**/node_modules/
**/.DS_Store
**/yarn-error.log
lerna-debug.log
lerna-debug.log

**/.idea
69 changes: 52 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ Welcome to **Hyperweb**, the blockchain for JavaScript smart contracts. Hyperweb
## Table of Contents

- [Quickstart](#quickstart)
- [Contract Layout](#contract-layout)
- [Building and Bundling](#building-and-bundling)
- [Creating JSD Client](#creating-jsd-client)
- [Deploying and Interacting with the Contract](#deploying-and-interacting-with-the-contract)
- [Bundle Contracts](#bundle-contracts)
- [Infrastructure Setup](#infrastructure-setup)
- [Option 1: Using Starship](#option-1-using-starship)
- [Enable Kubernetes in Docker Desktop](#enable-kubernetes-in-docker-desktop)
- [Install `kubectl` and `helm`](#install-kubectl-and-helm)
- [Start Starship](#start-starship)
- [Interact with the Chain](#interact-with-the-chain)
- [Option 2: Using Docker](#option-2-using-docker)
- [Run Hyperweb with Docker](#run-hyperweb-with-docker)
- [Interact with Chain](#interact-with-chain)
- [Run Tests](#run-tests)
- [Usage](#usage)
- [Instantiating a Contract](#instantiating-a-contract)
- [Interacting with the Contract](#interacting-with-the-contract)
- [Evaluating Functions on the Contract](#evaluating-functions-on-the-contract)
- [Reading Contract State](#reading-contract-state)
- [Creating JSD Client](#creating-jsd-client)
- [Deploying and Interacting with the Contract](#deploying-and-interacting-with-the-contract)
- [Instantiating a Contract](#instantiating-a-contract)
- [Interacting with the Contract](#interacting-with-the-contract)
- [Evaluating Functions on the Contract](#evaluating-functions-on-the-contract)
- [Reading Contract State](#reading-contract-state)
- [Development](#development)

## Installation
Expand Down Expand Up @@ -56,7 +65,11 @@ yarn build

This bundles the contracts from src/** into dist/contracts/.

### Spin Up Starship
## Infrastructure Setup

### Option 1: Using Starship
[Starship](https://github.com/cosmology-tech/starship) is a Kubernetes-based blockchain orchestrator. It sets up a local blockchain environment with full cross-chain compatibility.

#### Enable Kubernetes in Docker Desktop
Docker Desktop includes a standalone Kubernetes server and client, as well as Docker CLI integration that runs on your machine.
To enable Kubernetes in Docker Desktop:
Expand All @@ -80,18 +93,40 @@ Wait for Starship to initialize.

For more details, refer to the [Starship Docs](https://docs.cosmology.zone/starship/).

#### Interact with Chain
Once the starship nodes are running, then you can interact with the chain using following endpoints:
- REST: http://localhost:1317
- RPC: http://localhost:26657
- Faucet: http://localhost:8000
### Option 2: Using Docker
Alternatively, Hyperweb can be run using Docker, which simplifies setup and enables you to interact with the blockchain without requiring Kubernetes.

#### Run Hyperweb with Docker
To spin up the chain using Docker, the following scripts are available in the package.json:

* Run Docker container:
```bash
yarn docker
```

* Stop and remove the container:
```bash
yarn docker:stop
```

### Interact with chain

This will set up the same chain environment that Starship provides, allowing you to interact with the chain using the same endpoints:
* REST: http://localhost:1317
* RPC: http://localhost:26657
* Faucet: http://localhost:8000
* Exposer: http://localhost:8081
* Registry: http://localhost:8001

Once the chain is running, you can follow the same steps to interact with the chain and run tests as detailed below.

### Run Tests
## Run Tests
Once the setup it complete, you can run tests to validate the contract functionality.
Run tests:
```bash
yarn test
```
The test suite deploys the contracts, interacts with them, and validates state transitions. The tests are located in tests/.
The test suite deploys the contracts, interacts with them, and validates state transitions. The tests are located in `__tests__/`.

---

Expand Down Expand Up @@ -212,4 +247,4 @@ console.log('Contract state:', state);

## Development

For local development, you can run the tests provided in the `tests/` folder to validate contract functionality using `starshipjs` to simulate chain interactions.
For local development, you can run the tests provided in the `__tests__/` folder to validate contract functionality using `starshipjs` to simulate chain interactions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"build": "ts-node scripts/build.ts",
"test": "jest --verbose --bail",
"test:debug": "jest --runInBand --verbose --bail",
"docker": "npm run docker:stop && npm run docker:run",
"docker:run": "docker run -d --name jsd-plus -p 26657:26657 -p 1317:1317 -p 8000:8000 -p 8001:8001 -p 8081:8081 ghcr.io/cosmology-tech/jsd-plus:0.1.1",
"docker:exec": "docker exec -it jsd-plus /bin/bash",
"docker:stop": "docker stop jsd-plus || true && docker rm jsd-plus || true",
"starship": "starship --config configs/local.yaml",
"starship:ci": "starship --config configs/ci.yaml"
},
Expand Down
Loading