diff --git a/.github/workflows/e2e-docker-tests.yaml b/.github/workflows/e2e-docker-tests.yaml new file mode 100644 index 0000000..cb7c231 --- /dev/null +++ b/.github/workflows/e2e-docker-tests.yaml @@ -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 diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml index 397bad9..b617687 100644 --- a/.github/workflows/e2e-tests.yaml +++ b/.github/workflows/e2e-tests.yaml @@ -9,10 +9,6 @@ on: - main workflow_dispatch: -permissions: - contents: read - packages: write - jobs: e2e-tests: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index ac96c43..cd4e6de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ **/node_modules/ **/.DS_Store **/yarn-error.log -lerna-debug.log \ No newline at end of file +lerna-debug.log + +**/.idea diff --git a/README.md b/README.md index b680102..29aa320 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: @@ -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__/`. --- @@ -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. diff --git a/package.json b/package.json index 3c7fe6d..3bec0cb 100644 --- a/package.json +++ b/package.json @@ -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" },