devX: Docker compose for neutron + quartz cli (#248)

Co-authored-by: Juan Enrique Alcaraz <juanenrisley@gmail.com>
This commit is contained in:
dusterbloom 2024-10-10 14:41:16 +02:00 committed by GitHub
parent 382866be24
commit 864da77405
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 179 additions and 152 deletions

View file

@ -1,3 +1,12 @@
*
!crates
!examples
!Cargo.lock
!Cargo.toml
**/.cache
**/frontend
**/target **/target
docker **/.gitignore
docs **/Makefile
**/*.md
!**/README.md

View file

@ -23,20 +23,20 @@ jobs:
timeout-minutes: 25 timeout-minutes: 25
run: | run: |
echo "Waiting for handshake completion..." echo "Waiting for handshake completion..."
while ! docker logs quartz-cli-transfers 2>&1 | grep -q "Enclave is listening"; do while ! docker logs enclave 2>&1 | grep -q "Enclave is listening"; do
sleep 30 sleep 30
done done
- name: Capture logs from CLI - name: Capture logs from CLI
working-directory: examples/transfers/frontend working-directory: examples/transfers/frontend
run: docker logs --tail 50 quartz-cli-transfers &> quartz-cli-transfers_logs.txt run: docker logs --tail 50 enclave &> enclave.logs.txt
- name: Setup Frontend environment variables for quartz - name: Setup Frontend environment variables for quartz
working-directory: examples/transfers/frontend working-directory: examples/transfers/frontend
run: | run: |
cp .env.example .env.local cp .env.example .env.local
sed -i "s/^NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=.*/NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=$(grep 'Contract Address:' quartz-cli-transfers_logs.txt | awk '{print $NF}')/" .env.local sed -i "s/^NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=.*/NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=$(grep 'Contract Address:' enclave.logs.txt | awk '{print $NF}')/" .env.local
sed -i "s/^NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=.*/NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=$(grep 'Handshake complete:' quartz-cli-transfers_logs.txt | awk '{print $NF}')/" .env.local sed -i "s/^NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=.*/NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=$(grep 'Handshake complete:' enclave.logs.txt | awk '{print $NF}')/" .env.local
- name: Install Frontend dependencies - name: Install Frontend dependencies
working-directory: examples/transfers/frontend working-directory: examples/transfers/frontend

View file

@ -5,6 +5,12 @@ ARG CARGO_FLAGS=""
COPY . /opt COPY . /opt
# Temporarily disable GPG checks
RUN echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/99no-check-valid-until \
&& echo 'Acquire::AllowInsecureRepositories "true";' > /etc/apt/apt.conf.d/99allow-insecure \
&& echo 'Acquire::AllowDowngradeToInsecureRepositories "true";' >> /etc/apt/apt.conf.d/99allow-insecure
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
protobuf-compiler \ protobuf-compiler \
@ -15,12 +21,12 @@ RUN apt-get update && \
# Install Go # Install Go
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y --no-install-recommends wget && \ apt-get install -y --no-install-recommends wget && \
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz && \ wget https://go.dev/dl/go1.22.0.linux-amd64.tar.gz && \
tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz && \ tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz && \
rm go1.20.5.linux-amd64.tar.gz && \ rm go1.22.0.linux-amd64.tar.gz && \
wget https://github.com/CosmWasm/wasmd/releases/download/v0.44.0/wasmd-v0.44.0-linux-amd64.tar.gz && \ wget https://github.com/neutron-org/neutron/releases/download/v4.2.4/neutrond-linux-amd64 && \
tar -C /usr/local/bin -xzf wasmd-v0.44.0-linux-amd64.tar.gz && \ chmod +x neutrond-linux-amd64 && \
rm wasmd-v0.44.0-linux-amd64.tar.gz && \ cp neutrond-linux-amd64 /usr/local/bin/neutrond && \
apt-get remove -y wget && \ apt-get remove -y wget && \
apt-get clean && \ apt-get clean && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
@ -35,4 +41,7 @@ WORKDIR /opt/crates/cli
RUN cargo build --locked --release ${CARGO_FLAGS} RUN cargo build --locked --release ${CARGO_FLAGS}
RUN cp /opt/target/release/quartz /usr/local/bin/ RUN cp /opt/target/release/quartz /usr/local/bin/
CMD ["quartz", "--mock-sgx", "--app-dir", "/opt/examples/transfers", "dev", "--unsafe-trust-latest", "--contract-manifest", "/opt/examples/transfers/contracts/Cargo.toml", "--init-msg", "{\"denom\":\"ucosm\"}"] # Create a directory for the app
RUN mkdir -p /opt/examples/transfers
ENTRYPOINT ["quartz", "--mock-sgx", "--app-dir", "/opt/examples/transfers", "dev", "--unsafe-trust-latest", "--contract-manifest", "/opt/examples/transfers/contracts/Cargo.toml", "--init-msg", "{\"denom\":\"untrn\"}"]

View file

@ -1,31 +1,39 @@
name: "transfers" name: "transfers"
volumes: volumes:
wasmd_data: data:
services: services:
node: node:
container_name: wasmd container_name: neutron
build: "./wasmd" healthcheck:
ports: test:
- "26657:26657" [
- "26656:26656" "CMD",
- "1317:1317" "curl",
network_mode: host "-f",
"http://127.0.0.1:1317/cosmos/base/tendermint/v1beta1/blocks/1",
]
start_period: 10s
interval: 5s
timeout: 5s
retries: 3
volumes: volumes:
- wasmd_data:/root/.wasmd - data:/root/.neutrond
build:
context: "./neutrond"
network_mode: host
enclave: enclave:
container_name: quartz-cli-transfers container_name: enclave
environment: environment:
DOCKER_BUILDKIT: 1 DOCKER_BUILDKIT: 1
ADMIN_SK: 07b291dca4ead76392945ea0a8c35b2d506617d36337788c9043c8fc992213e1
build: build:
context: ".." context: ".."
dockerfile: "./crates/cli/Dockerfile" dockerfile: "./crates/cli/Dockerfile"
depends_on: depends_on:
- node node:
ports: condition: service_healthy
- "11090:11090"
network_mode: host
volumes: volumes:
- wasmd_data:/root/.wasmd - data:/root/.neutrond
network_mode: host

View file

@ -0,0 +1,2 @@
*
!data

View file

@ -0,0 +1,9 @@
FROM golang:1.22-bullseye
RUN apt-get update && apt-get install -y jq && \
git clone https://github.com/neutron-org/neutron.git /root/neutron && \
cd /root/neutron && make install-test-binary
COPY data /root/
CMD bash /root/entrypoint.sh

View file

@ -1,10 +1,11 @@
# Setup local accounts. This is only for local development and should not be used in production. # Setup local accounts. This is only for local development and should not be used in production.
import-local-accounts: import-local-accounts:
neutrond keys add val1 --keyring-backend test > ./accounts/val1.txt 2>&1 neutrond keys add admin --keyring-backend test > ./data/accounts/admin.txt 2>&1
neutrond keys add val2 --keyring-backend test > ./accounts/val2.txt 2>&1 neutrond keys add alice --keyring-backend test > ./data/accounts/alice.txt 2>&1
neutrond keys add demowallet1 --keyring-backend test > ./accounts/demowallet1.txt 2>&1 neutrond keys add bob --keyring-backend test > ./data/accounts/bob.txt 2>&1
neutrond keys add demowallet2 --keyring-backend test > ./accounts/demowallet2.txt 2>&1 neutrond keys add charlie --keyring-backend test > ./data/accounts/charlie.txt 2>&1
neutrond keys add demowallet3 --keyring-backend test > ./accounts/demowallet3.txt 2>&1
neutrond keys add rly1 --keyring-backend test > ./accounts/rly1.txt 2>&1 create-local-accounts: import-local-accounts
neutrond keys add rly2 --keyring-backend test > ./accounts/rly2.txt 2>&1 @echo "Local accounts have been created."
.PHONY: create-local-accounts
.PHONY: create-local-accounts import-local-accounts

View file

@ -1,78 +1,51 @@
# Setting up a Single Node Neutron Testnet # Quartz Neutrond image
This guide provides instructions for setting up a single node Neutron testnet using Docker and local installation. This folder contains a `Dockerfile` that helps build a single-node [neutrond]
for use in testing your Quartz application.
> Note - For more detailed instructions, refer to the [official Neutron documentation](https://docs.neutron.org/neutron/build-and-run/neutron-docker). It facilitates the creation of a Docker image with 4 accounts pre-loaded, each
having a small amount of `untrn` preloaded from genesis for experimentation.
## Setup Steps - `admin`
- `alice`
- `bob`
- `charlie`
Clone the Neutron repository in your `$HOME` or your preferred repository: These accounts' details are stored in clear text in the [data/accounts](./data/accounts/)
``` folder.
git clone -b v4.0.1 https://github.com/neutron-org/neutron.git
cd neutron **Note: this image is _NOT_ intended to be used in production.**
## Using the image
For running this image you can just use the already prepared [docker-compose.yml](../docker-compose.yml)
file by simply run at `docker` folder root level:
```bash
docker compose up node
``` ```
Build the Docker image: ## Importing the account keys
```
make build-docker-image As previously mentioned, the [data/accounts](./data/accounts/) folder contains all of
the necessary material to construct the public/private keypairs of the accounts.
A convenient helper target is provided in [`/Makefile`](./Makefile) to facilitate
importing of these accounts into a local `neutrond` configuration (i.e. on your
host machine, outside of the Docker container). This will allow you to transact
on behalf of any of those accounts from outside of the Docker container.
**NB**: For this to work, you will need the same version of `neutrond` installed on
your local machine as what is built into the `neutrond` Docker image.
```bash
make import-local-accounts
``` ```
Start the Docker container: To check that the accounts have been imported correctly, on your host machine
``` run:
make start-docker-container
```
Monitor the logs: ```bash
# List all keys available in your local neutrond configuration
neutrond keys list --keyring-backend=test
``` ```
docker ps # Get the container ID
docker logs -f <neutron-node-container-id>
```
Verify the Docker keyring setup:
```
docker exec -it neutron neutrond query bank balances neutron1qnk2n4nlkpw9xfqntladh74w6ujtulwn6dwq8z --chain-id test-1
```
This should return:
```
balances:
- amount: "100000000000000"
denom: untrn
pagination:
total: "1"
```
Install neutrond locally:
```
make install
```
To setup the local keyring:
```
cd docker/neutrond
make create-local-accounts
```
Verify local keyring setup:
```
neutrond query bank balances neutron1qnk2n4nlkpw9xfqntladh74w6ujtulwn6dwq8z --chain-id test-1
```
This should return:
```
balances:
- amount: "100000000000000"
denom: untrn
pagination:
total: "1"
```
To stop and reset the chain, go back into the neutron source folder from github and run:
```
make stop-docker-container
```
## How accounts are setup on neutron
We use the standard 7 accounts that come from the neutron base docker setup. We have imported those to `docker/neutrond/accounts`. These accounts already exist in the container running the node, and we get them locally by running `make import-local-accounts`. We don't have functions to create or delete accounts, since we want to strictly follow their base docker setup, and thus keep the accounts the exact same. The 7 accounts are:
- `demowallet1`, `demowallet2` and `demowallet3` - These are the accounts you should use for testing. They are seeded with the test token `untrn`, and 2 IBC tokens, `uibcatom` and `uibcusdc`.
- `val1` and `val2` - accounts used to setup the validators for the test network. Seeded only with the test token `untrn`. Use if you need extra accounts beyond the demo wallets.
- `rly1` and `rly2` - accounts used to setup IBC relayers for the test network. Only seeded with `untrn`. Use if you need extra accounts beyond the demo wallets.

View file

@ -1,11 +0,0 @@
- address: neutron1a57m0naqaf56hcvldfvagde7rajse68hnynpe4
name: demowallet1
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A6iUKYrdZW53fFEXZpjfVqcaOcXOAucfHBhdzpx/u660"}'
type: local
**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.
cave middle fade cube battle parrot live picture item before mention cheap veteran nose sting recipe talk vapor judge bracket flee flavor lazy blue

View file

@ -1,11 +0,0 @@
- address: neutron105slt5cpynvzv5cy6xadxl548em5wsjfh2shat
name: demowallet2
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Akj8ZdWICka5rn2/M5csbMpt0tU0N9TMkC9981KqG3ks"}'
type: local
**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.
thunder blanket sort image frequent village adult fish caution explain legend canyon canal property since razor whale zero idle parrot large tank such smart

View file

@ -1,11 +0,0 @@
- address: neutron1zf0a8ueetawfqwzzx5njmq88jpmqa827t5v38a
name: demowallet3
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Av2LbNFHvcNR0D4BHk51lmiVvCRLOmoh4YMlJLnNbvg5"}'
type: local
**Important** write this mnemonic phrase in a safe place.
It is the only way to recover your account if you ever forget your password.
polar twice glass ostrich crush tank charge caution planet answer ripple culture staff relief have tragic occur helmet between slight proof direct output shoot

View file

@ -1,6 +1,6 @@
- address: neutron1zmr7dfc325907tvj8jl2p2p4cx84clk5aflstl - address: neutron1zmr7dfc325907tvj8jl2p2p4cx84clk5aflstl
name: rly1 name: admin
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ak3alwik1L65ujlKbgQP//JL3LUlJmvA0zn8rt4eeoHG"}' pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Ak3alwik1L65ujlKbgQP//JL3LUlJmvA0zn8rt4eeoHG"}'
type: local type: local

View file

@ -1,6 +1,6 @@
- address: neutron152zj7nyksf7dgrt4tpcf64t92k4ar9c2c97wxz - address: neutron152zj7nyksf7dgrt4tpcf64t92k4ar9c2c97wxz
name: rly2 name: alice
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A9jd2NZ40ZkD0TqBMmco6ejP1EzR1AnYIqSNm5m/Y997"}' pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A9jd2NZ40ZkD0TqBMmco6ejP1EzR1AnYIqSNm5m/Y997"}'
type: local type: local

View file

@ -1,6 +1,6 @@
override the existing name val1 [y/N]: override the existing name val1 [y/N]:
- address: neutron1t4jlep6w6qxzwf58x49uya74x4tfjx4vd7v9a7 - address: neutron1t4jlep6w6qxzwf58x49uya74x4tfjx4vd7v9a7
name: val1 name: bob
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Are6QBWqMGG3srEdzWj6ulFzX2J9mU5V5BUGDWpPZvzn"}' pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"Are6QBWqMGG3srEdzWj6ulFzX2J9mU5V5BUGDWpPZvzn"}'
type: local type: local

View file

@ -1,6 +1,6 @@
- address: neutron1efkh8rpul8v6km98cuaejz0a5zczvvvz4ps82r - address: neutron1efkh8rpul8v6km98cuaejz0a5zczvvvz4ps82r
name: val2 name: charlie
pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A0owhBMbRQ2jwJ7dKqwRA2fFyqSMpRmI2aefEdBIT/td"}' pubkey: '{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A0owhBMbRQ2jwJ7dKqwRA2fFyqSMpRmI2aefEdBIT/td"}'
type: local type: local

View file

@ -0,0 +1,43 @@
#!/bin/sh
set e
# Clean previous keys & reset node
rm -rf /root/.neutrond/keyring-test &> /dev/null
neutrond tendermint unsafe-reset-all
# Init configuration files
neutrond init test --chain-id test-1 --overwrite
# Modify default configurations
sed -i 's/keyring-backend = "os"/keyring-backend = "test"/g' /root/.neutrond/config/client.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \[\"*\"\]/g' /root/.neutrond/config/config.toml
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0.0025untrn"/g' /root/.neutrond/config/app.toml
sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' /root/.neutrond/config/app.toml
sed -i 's/enable = false/enable = true/g' /root/.neutrond/config/app.toml
sed -i 's/swagger = false/swagger = true/g' /root/.neutrond/config/app.toml
GENESIS_PATH="/root/.neutrond/config/genesis.json"
function set_genesis_param_jq() {
param_path=$1
param_value=$2
jq "${param_path} = ${param_value}" > tmp_genesis_file.json < "$GENESIS_PATH" && mv tmp_genesis_file.json "$GENESIS_PATH"
}
# feemarket
set_genesis_param_jq ".app_state.feemarket.params.min_base_gas_price" "\"0.0025\""
set_genesis_param_jq ".app_state.feemarket.params.fee_denom" "\"untrn\""
set_genesis_param_jq ".app_state.feemarket.state.base_gas_price" "\"0.0025\""
# Import all test accounts
for filename in /root/accounts/*.txt; do
tail -n 1 "$filename" | neutrond keys add "$(basename "$filename" .txt)" --no-backup --recover --keyring-backend=test
neutrond add-genesis-account "$(neutrond keys show $(basename "$filename" .txt) -a)" 12000000000000untrn
done
# Enable as a single node consumer
neutrond add-consumer-section
# Start node
neutrond start --trace

View file

@ -1,13 +1,13 @@
# App required variables # App required variables
NEXT_PUBLIC_TARGET_CHAIN=localWasm NEXT_PUBLIC_TARGET_CHAIN=localNeutron
NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=02360955ff74750f6ea0b539f41cce89451f591e4c835d0a5406e6effa96dd169d NEXT_PUBLIC_ENCLAVE_PUBLIC_KEY=02a4db2129c629a709351bd7d9e09c49326c580cb2863aec9020dccaaa5984a68f
NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=wasm14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s0phg4d NEXT_PUBLIC_TRANSFERS_CONTRACT_ADDRESS=neutron14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s5c2epq
# E2E testing required variables # E2E testing required variables
TEST_BASE_URL=http://127.0.0.1:3000 TEST_BASE_URL=http://127.0.0.1:3000
TEST_KEPLR_EXTENSION_VERSION=0.12.124 TEST_KEPLR_EXTENSION_VERSION=0.12.124
TEST_WALLET_MNEMONIC=grain shoe diamond mix chunk turn odor across reduce room smart napkin scale ghost emotion stove mistake someone account snow country rail boy rescue TEST_WALLET_MNEMONIC=run snack expand version flag foil used session name lift mouse repeat bunker pencil orchard lens kitchen prevent emerge alien outdoor else cat brass
TEST_SECONDARY_WALLET_MNEMONIC=inmate surface cement any mule sweet what hamster rent ridge series equip equal supply plunge mango mystery chase other economy build pool coyote enter TEST_SECONDARY_WALLET_MNEMONIC=rare tobacco crisp auction shrug turkey transfer little giggle giraffe live stereo soft arctic raw page october river armor home champion check virus trap
TEST_SECONDARY_WALLET_ADDRESS=wasm1adcnk7lt6qst7p5d0g5607e28k77um7nxwxuqy TEST_SECONDARY_WALLET_ADDRESS=neutron1t4jlep6w6qxzwf58x49uya74x4tfjx4vd7v9a7
TEST_WALLET_PASSWORD=;pzPCXB^@92byC TEST_WALLET_PASSWORD=;pzPCXB^@92byC
PLAYWRIGHT_HTML_OPEN=never PLAYWRIGHT_HTML_OPEN=never

View file

@ -11,7 +11,11 @@ export const getBalance = async ({
// Check new balance // Check new balance
await page.getByRole('button', { name: /get/i }).click() await page.getByRole('button', { name: /get/i }).click()
await signTx({ context, page }) await signTx({
context,
page,
notificationMsg: 'Balance updated successfully',
})
// Wait for the success alert to appear so we know balance updated // Wait for the success alert to appear so we know balance updated
await page.getByText(/\$/i).waitFor({ state: 'visible' }) await page.getByText(/\$/i).waitFor({ state: 'visible' })

View file

@ -3,14 +3,16 @@ import { BrowserContext, Page } from '@playwright/test'
export const signTx = async ({ export const signTx = async ({
context, context,
page, page,
notificationMsg = /successfully/i,
}: { }: {
context: BrowserContext context: BrowserContext
page: Page page: Page
notificationMsg?: string | RegExp
}) => { }) => {
// Sign tx // Sign tx
const signPage = await context.waitForEvent('page') const signPage = await context.waitForEvent('page')
await signPage.getByRole('button', { name: /approve/i }).click() await signPage.getByRole('button', { name: /approve/i }).click()
await signPage.waitForEvent('close') await signPage.waitForEvent('close')
await page.getByText(/successfully/i).waitFor({ state: 'visible' }) await page.getByText(notificationMsg).waitFor({ state: 'visible' })
} }

View file

@ -1,8 +1,8 @@
mock_sgx = true mock_sgx = true
tx_sender = "admin" tx_sender = "admin"
chain_id = "testing" chain_id = "test-1"
node_url = "http://127.0.0.1:26657" node_url = "http://127.0.0.1:26657"
ws_url = "ws://127.0.0.1/wesocket" ws_url = "ws://127.0.0.1:26657/websocket"
grpc_url = "http://127.0.0.1:9090" grpc_url = "http://127.0.0.1:9090"
enclave_rpc_addr = "http://127.0.0.1" enclave_rpc_addr = "http://127.0.0.1"
enclave_rpc_port = 11090 enclave_rpc_port = 11090