Skip to content

Commit

Permalink
Starship integration (#56)
Browse files Browse the repository at this point in the history
* Semi working integration of Starship with mesh-security with custom code

* Semi working full mesh security lifecycle

* Update devnet setup for starship multi-node setup

* rename denoms to uosmo and ujuno to get seperation of chains

* Cleanup the tests: update the structure

* Fix setup command and update cmd main file

* Update devnet information for latest contracts and endpoints

* update endpoints

* 2 way inital devnet

* update new devnet

* updated devnet, 2 chain mesh setup working

* add e2e tests of 2 way contract to run in the CI

* run a particular function for test

* working model of 2 way contract

* Revert adhoc changes made to mesh-security-sdk for hackathon

* revert makefile for demo app

* move testdata outside for using it with e2e tests and startship tests

* update starship yaml files to run with mesh-security-sdk

* working version of starship with meshd

* fix main_test.go and go mod

* fix ci starship config

* run starship ci on push to test branch

* fix typo errors

* fix typos and type errors

* add step to perform go mod before setting up the infra

* commit to trigger CI

* add retry of running tests incase of transient errors

* temp disable workflows in the CI

* Add readme, update make commands, add todo to change docker image in the configs

* remove ci-debuging for the PR

* update docker image to use ghcr.io meshd image
  • Loading branch information
Anmol1696 authored Sep 21, 2023
1 parent 115eec1 commit ce6a286
Show file tree
Hide file tree
Showing 32 changed files with 4,235 additions and 1 deletion.
66 changes: 66 additions & 0 deletions .github/workflows/starship-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Starship E2E tests

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

jobs:
e2e-test:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.20
id: go

- name: Deps
run: |
cd tests/starship/
go mod tidy
# Starship Infra setup
# - Connects to k8s cluster with kubeconfig (digital ocean)
# - Creates a new namespace based on the name (deleted in next step)
# - Spins up the infra with the given config file
# - Waits till all nodes are running (timeout 30m)
# - Port forward all ports to localhost for next steps to connect
- name: Setup Test infra
id: starship-action
uses: cosmology-tech/starship-action@0.2.15
with:
values: tests/starship/configs/ci.yaml
port-forward: true
version: 0.1.46-rc1

- name: Run Tests
id: run-tests
run: |
cd tests/starship/
make test
- name: Run Tests (retry on failure)
if: steps.run-tests.outcome == 'failure'
run: |
cd tests/starship/
make test
# Starship resource cleanup on cluster
- name: Cleanup cluster
if: always()
run: |
helm delete $DEVNET_NAME --debug --namespace $DEVNET_NAMESPACE --wait || true
kubectl delete namespace $DEVNET_NAMESPACE --wait=true || true
env:
DEVNET_NAME: ${{ steps.starship-action.outputs.name }}
DEVNET_NAMESPACE: ${{ steps.starship-action.outputs.namespace }}
2 changes: 1 addition & 1 deletion tests/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestMain(m *testing.M) {
flag.StringVar(&wasmContractPath, "contracts-path", "testdata", "Set path to dir with gzipped wasm contracts")
flag.StringVar(&wasmContractPath, "contracts-path", "../testdata", "Set path to dir with gzipped wasm contracts")
flag.BoolVar(&wasmContractGZipped, "gzipped", true, "Use `.gz` file ending when set")
flag.Parse()

Expand Down
72 changes: 72 additions & 0 deletions tests/starship/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/make -f

BUILD_DIR = ./build

all: test

test:
go test -count=1 -mod=readonly -v -race -run Test2WayContract ./...

build-setup:
cd setup && go build cmd/... -o build/ ./setup

run-setup:
cd setup && go run ./...

build:
CGO_ENABLED=1 go test -c -mod=readonly -o $(BUILD_DIR)/mesh-security.e2e.test

build-linux:
CGO_ENABLED=1 GOOS=linux go test -c -mod=readonly -o $(BUILD_DIR)/mesh-security.e2e.test

.PHONY: all build build-linux test

###############################################################################
### Starship Helm Charts ###
###############################################################################
NAME = mesh-security
FILE = configs/local.yaml

HELM_REPO = starship
HELM_CHART = devnet
HELM_VERSION = v0.1.46-rc1

.PHONY: check
setup-deps:
bash $(CURDIR)/scripts/dev-setup.sh

install:
bash $(CURDIR)/scripts/install.sh --config $(FILE) --version $(HELM_VERSION) --name $(NAME)

debug:
bash $(CURDIR)/scripts/install.sh --config $(FILE) --version $(HELM_VERSION) --name $(NAME) --dry-run

delete:
-helm delete $(NAME)

stop: stop-forward delete

###############################################################################
### Port forward ###
###############################################################################

.PHONY: port-forward
port-forward:
bash $(CURDIR)/scripts/port-forward.sh --config=$(FILE)

.PHONY: stop-forward
stop-forward:
-pkill -f "port-forward"

###############################################################################
### Local Kind Setup ###
###############################################################################
KIND_CLUSTER=starship

.PHONY: setup-kind
setup-kind:
kind create cluster --name $(KIND_CLUSTER)

.PHONY: clean-kind
clean-kind:
kind delete cluster --name $(KIND_CLUSTER)
90 changes: 90 additions & 0 deletions tests/starship/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Starship Tests
Multi-chain e2e tests that run against any chain, using chain binaries, relayers
and deploying Mesh-Security contracts.

Starship runs by separating out the infra from the tests that are run against the infra.

## Getting Started
### Setup script
In the `tests/starship` dir, run

```bash
make setup-deps ## Installs dependencies for Starship
```

### Manul install (alternate)
Alternatively to the setup script one can just install the deps directly:
* docker: https://docs.docker.com/get-docker/
* kubectl: https://kubernetes.io/docs/tasks/tools/
* kind: https://kind.sigs.k8s.io/docs/user/quick-start/#installation
* helm: https://helm.sh/docs/intro/install/
* yq: https://github.com/mikefarah/yq/#install

## Connect to a kubernetes cluster
### Spinup local cluster
On Linux:
```bash
make setup-kind
```

On Mac:
Use Docker Desktop to setup kubernetes cluster: https://docs.docker.com/desktop/kubernetes/#turn-on-kubernetes

### Connect to a remote cluster (alternate)
If one has access to a k8s cluster via a `kubeconfig` file one can run Starship directly on the remote cluster.

## Check connection with cluster
Run
```bash
kubectl get nodes
```

## Run Tests
Once the initial connection and setup is done, then one can spin up starship infra with

```bash
make install
# OR if you want to run specific config file
make install FILE=configs/devnet.yaml
```

Once the helm chart is installed, you will have to wait for pods to be in a `Running` state. Usually takes 3-5 mins depending on the resources available.
Can check with
```bash
kubectl get pods
```

When all pods are in `Running` state, run port-forwarding to access the nodes on localhost
```bash
make port-forward
# All exposed endpoints would be printed by this command
```

Now you can run the tests with:
```bash
make test
```

Once done, cleanup with:
```bash
make stop
```


## Configs
Starship configs is the definition of the infra we want to spin up.
Present in `test/starship/configs`, are multiple versions of the similar infra, tweaked to be able to run in different environments
* `configs/local.yaml`: Config file to be able to run locally
* `configs/devnet.yaml`: Supposed to be run on a larger k8s cluster, with more resources and number of validators
* `configs/ci.yaml`: Limited resources on the GH-Action runner, can be adapted for with reducing cpu,memory allocated

All the config files are similar topology, but different resources allocated.
Topology:
* 2 chains: `mesh-1` and `mesh-2` (both running `mesh-security-sdk` demo app)
* 1 hermes relayer: running between the chains, in pull mode (1.6.0)
* Registry service: analogous to cosmos chain-registry, but for only our infra
* Optionally explorer: ping-pub explorer for the mini cosmos

Details of each of arguments in the config file can be found [here](https://starship.cosmology.tech/config/chains)


93 changes: 93 additions & 0 deletions tests/starship/configs/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
chains:
- name: mesh-1
type: custom
numValidators: 1
image: ghcr.io/osmosis-labs/meshd:latest
home: /root/.meshd
binary: meshd
prefix: mesh
denom: stake
coins: 100000000000000stake
hdPath: m/44'/118'/0'/0/0
coinType: 118
repo: https://github.com/osmosis/mesh-security-sdk
genesis:
app_state:
meshsecurity:
params:
epoch_length: 10
staking:
params:
unbonding_time: 200s
ports:
rest: 1313
rpc: 26653
faucet: 8003
resources:
cpu: "0.2"
memory: "200M"
faucet:
concurreny: 2
resources:
cpu: "0.1"
memory: "100M"
- name: mesh-2
type: custom
numValidators: 1
image: ghcr.io/osmosis-labs/meshd:latest
home: /root/.meshd
binary: meshd
prefix: mesh
denom: stake
coins: 100000000000000stake
hdPath: m/44'/118'/0'/0/0
coinType: 118
repo: https://github.com/osmosis/mesh-security-sdk
genesis:
app_state:
meshsecurity:
params:
epoch_length: 10
staking:
params:
unbonding_time: 200s
ports:
rest: 1317
rpc: 26657
faucet: 8007
resources:
cpu: "0.2"
memory: "200M"
faucet:
concurreny: 2
resources:
cpu: "0.1"
memory: "100M"

relayers:
- name: mesh-1-mesh-2
type: hermes
replicas: 1
image: ghcr.io/cosmology-tech/starship/hermes:1.6.0
chains:
- mesh-1
- mesh-2
config:
event_source:
mode: pull
resources:
cpu: "0.1"
memory: "100M"

registry:
enabled: true
ports:
rest: 8081
resources:
cpu: "0.1"
memory: "100M"

exposer:
resources:
cpu: "0.1"
memory: "100M"
Loading

0 comments on commit ce6a286

Please sign in to comment.