Skip to content

Commit

Permalink
Launch some test with three node in localnet
Browse files Browse the repository at this point in the history
  • Loading branch information
boogeroccam committed Nov 13, 2024
1 parent 407ddfd commit c2ff3b3
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 248 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI/CD Pipeline

on:
push:
branches:
- "*"
pull_request:
types: [opened, synchronize]
workflow_dispatch:
inputs:
branch:
description: "Branch to run tests on"
required: true
default: "main"
release:
types: [created]

jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Build binary
run: make build

- name: Upload binary artifact
if: github.event_name == 'release'
uses: actions/upload-artifact@v2
with:
name: galacticad
path: build/galacticad

test:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v2

- uses: astral-sh/setup-uv@v3
with:
version: "latest"

- name: Run tests
run: make test

- name: Test status check
if: failure()
run: exit 1

permissions:
pull-requests: write

manual-tests:
runs-on: self-hosted
needs: test
if: github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "1.17"

- name: Run manual tests
run: go test ./...
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,11 @@ install: build
mkdir -p $(BINDIR)
cp -f $(BUILDDIR)/$(GALACTICA_BINARY) $(BINDIR)/$(GALACTICA_BINARY)
@echo "Galactica has been installed to $(BINDIR)"

help: ## Show this help
@printf "\033[33m%s:\033[0m\n" 'Available commands'
@awk 'BEGIN {FS = ":.*?## "} /^[[:alpha:][:punct:]]+:.*?## / {printf " \033[32m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

ifeq ($(CI),true)
include tests/Makefile
endif
130 changes: 60 additions & 70 deletions localnet/init-configs-localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ CHAIN_ID=${2:-"galactica_9302-1"}
KEYRING_BACKEND=${3:-"test"}
BASE_DENOM=${4:-"agnet"}
DISPLAY_DENOM=${5:-"gnet"}
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)

# localKey address 0x7cb61d4117ae31a12e393a1cfa3bac666481d02e
PREDEFINED_KEY_NAME="localkey"
PREDEFINED_KEY_MNEMONIC="gesture inject test cycle original hollow east ridge hen combine junk child bacon zero hope comfort vacuum milk pitch cage oppose unhappy lunar seat"


function gala() {
./build/galacticad --home "$MAIN_PATH_HOME" "$@"
}
Expand All @@ -50,16 +49,12 @@ function add_key() {
}

function add_key_predefined() {
echo $PREDEFINED_KEY_MNEMONIC | gala keys add \
$PREDEFINED_KEY_NAME \
--recover \
--keyring-backend $KEYRING_BACKEND \
--algo "eth_secp256k1" \
--keyring-dir $MAIN_PATH_HOME/
}

function init_localtestnet() {
gala init localtestnet --chain-id $CHAIN_ID --default-denom $BASE_DENOM
echo $PREDEFINED_KEY_MNEMONIC | gala keys add \
$PREDEFINED_KEY_NAME \
--recover \
--keyring-backend $KEYRING_BACKEND \
--algo "eth_secp256k1" \
--keyring-dir $MAIN_PATH_HOME/
}

function configure_app() {
Expand All @@ -69,41 +64,40 @@ function configure_app() {
# sed -i.backup 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/address = "localhost:9090"/address = "0.0.0.0:9090"/' $MAIN_PATH_CONFIG/app.toml
sed -i.backup '/\[grpc-web\]/,+7 s/address = "localhost:9091"/address = "0.0.0.0:9091"/' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/pruning = "default"/pruning = "nothing"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/minimum-gas-prices = "0stake"/minimum-gas-prices = "10'$BASE_DENOM'"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/pruning = "default"/pruning = "nothing"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/minimum-gas-prices = "0stake"/minimum-gas-prices = "10'$BASE_DENOM'"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup '/\[telemetry\]/,+8 s/enabled = false/enabled = true/' $MAIN_PATH_CONFIG/app.toml
sed -i.backup '/\[telemetry\]/,+20 s/prometheus-retention-time = 0/prometheus-retention-time = 60/' $MAIN_PATH_CONFIG/app.toml
sed -i.backup '/global-labels = \[/a\
\["chain_id", "'$CHAIN_ID'"\],
' $MAIN_PATH_CONFIG/app.toml

sed -i.backup 's/timeout_propose = ".*"/timeout_propose = "3s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_propose_delta = ".*"/timeout_propose_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_prevote = ".*"/timeout_prevote = "1s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_prevote_delta = ".*"/timeout_prevote_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_precommit = ".*"/timeout_precommit = "1s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_precommit_delta = ".*"/timeout_precommit_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_commit = ".*"/timeout_commit = "5s"/g' $MAIN_PATH_CONFIG/app.toml

sed -i.backup 's/timeout_propose = ".*"/timeout_propose = "3s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_propose_delta = ".*"/timeout_propose_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_prevote = ".*"/timeout_prevote = "1s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_prevote_delta = ".*"/timeout_prevote_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_precommit = ".*"/timeout_precommit = "1s"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_precommit_delta = ".*"/timeout_precommit_delta = "500ms"/g' $MAIN_PATH_CONFIG/app.toml
sed -i.backup 's/timeout_commit = ".*"/timeout_commit = "5s"/g' $MAIN_PATH_CONFIG/app.toml

# configure config settings
sed -i.backup 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/proxy_app = "tcp:\/\/127.0.0.1:26658"/proxy_app = "tcp:\/\/127.0.0.1:26658"/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/max_num_inbound_peers = 40/max_num_inbound_peers = 120/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/max_num_outbound_peers = 10/max_num_outbound_peers = 60/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/laddr = "tcp:\/\/127.0.0.1:26657"/laddr = "tcp:\/\/0.0.0.0:26657"/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/proxy_app = "tcp:\/\/127.0.0.1:26658"/proxy_app = "tcp:\/\/127.0.0.1:26658"/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/max_num_inbound_peers = 40/max_num_inbound_peers = 120/g' $MAIN_PATH_CONFIG/config.toml
sed -i.backup 's/max_num_outbound_peers = 10/max_num_outbound_peers = 60/g' $MAIN_PATH_CONFIG/config.toml
}

function update_genesis_json() {
local jq_command=$1
local file_path=${2:-"$MAIN_PATH_CONFIG/genesis.json"}

jq "$jq_command" "$file_path" > "${file_path}.tmp" && mv "${file_path}.tmp" "$file_path"
jq "$jq_command" "$file_path" >"${file_path}.tmp" && mv "${file_path}.tmp" "$file_path"
}

function configure_genesis() {
local staking_min_deposit="$1"
local total_supply="$2"
local staking_min_deposit="$1" # 5000000000000000000000
local total_supply="$2" # 1000000000000000000000000
local faucet_address="$3"
local voting_period="60s"
local unbonding_time="30s"
Expand Down Expand Up @@ -144,7 +138,7 @@ function configure_genesis() {
"uri_hash": ""
}'
update_genesis_json '.app_state.bank.send_enabled[0] = {"denom": "'$BASE_DENOM'", "enabled": true}'
# update_genesis_json '.app_state.bank.supply[0] = {"denom": "'$BASE_DENOM'", "amount": "'$total_supply'"}'
# update_genesis_json '.app_state.bank.supply[0] = {"denom": "'$BASE_DENOM'", "amount": "'$total_supply'"}'

# EVM params
update_genesis_json '.app_state.evm.params.evm_denom = "'$BASE_DENOM'"'
Expand All @@ -169,8 +163,8 @@ function add_genesis_account() {
local amount="$2"

gala add-genesis-account \
"$(gala keys show $account_name -a --keyring-dir $MAIN_PATH_HOME)" \
$amount
"$(gala keys show $account_name -a --keyring-dir $MAIN_PATH_HOME)" \
$amount
}

function initialize_validator() {
Expand All @@ -181,36 +175,26 @@ function initialize_validator() {
local validator_home=$MAIN_PATH_HOME/validators/$moniker

gala init \
$moniker \
--chain-id $CHAIN_ID \
--default-denom $BASE_DENOM \
--home $validator_home
$moniker \
--chain-id $CHAIN_ID \
--default-denom $BASE_DENOM \
--home $validator_home

cp $MAIN_PATH_CONFIG/genesis.json $validator_home/config/genesis.json

gala gentx \
$moniker \
$staking_amount \
--ip $ip \
--p2p-port $p2p_port \
--home $validator_home \
--keyring-dir $MAIN_PATH_HOME \
--keyring-backend $KEYRING_BACKEND
$moniker \
$staking_amount \
--ip $ip \
--p2p-port $p2p_port \
--home $validator_home \
--keyring-dir $MAIN_PATH_HOME \
--keyring-backend $KEYRING_BACKEND

mkdir -p $MAIN_PATH_CONFIG/gentx/
cp $validator_home/config/gentx/* $MAIN_PATH_CONFIG/gentx/
}

function collect_gentxs() {
gala collect-gentxs
rm $MAIN_PATH_CONFIG/node_key.json
rm $MAIN_PATH_CONFIG/priv_validator_key.json
}

function validate_genesis() {
gala validate-genesis
}

function configure_validator() {
local moniker=$1
local ip_address=$2
Expand All @@ -225,18 +209,21 @@ function configure_validator() {

# Filter out the IP address of the current validator from persistent_peers
local persistent_peers=$(cat $validator_home/config/config.toml | grep persistent_peers | cut -d '=' -f 2 | tr -d '"')
IFS=',' read -ra parts <<< "$persistent_peers"
IFS=',' read -ra parts <<<"$persistent_peers"
filtered_parts=()
for part in "${parts[@]}"; do
if [[ ! "$part" =~ $ip_address ]]; then
filtered_parts+=("$part")
fi
done
local new_persistent_peers=$(IFS=','; echo "${filtered_parts[*]}")
local new_persistent_peers=$(
IFS=','
echo "${filtered_parts[*]}"
)

echo "Validator $moniker persistent_peers: $new_persistent_peers"
sed -i.backup "s/\(persistent_peers *= *\"\).*\(\" *\)/\1$new_persistent_peers\2/" $validator_home/config/config.toml
sed -i.backup 's/moniker = "localtestnet"/moniker = "'$moniker'"/g' $validator_home/config/config.toml
sed -i.backup 's/moniker = "localtestnet"/moniker = "'$moniker'"/g' $validator_home/config/config.toml

local key=$(gala keys unsafe-export-eth-key --keyring-backend test --keyring-dir ./$MAIN_PATH_HOME $moniker)
yes '00000000' | gala keys unsafe-import-eth-key --keyring-backend test --keyring-dir ./$MAIN_PATH_HOME/validators/$moniker $moniker $key --chain-id $CHAIN_ID
Expand All @@ -246,7 +233,7 @@ function configure_faucet() {
local key=$(gala keys unsafe-export-eth-key --keyring-backend test --keyring-dir ./$MAIN_PATH_HOME faucet)
yes '00000000' | gala keys unsafe-import-eth-key --keyring-backend test --keyring-dir ./$MAIN_PATH_HOME/faucet faucet $key --chain-id $CHAIN_ID

echo $key > ./$MAIN_PATH_HOME/faucet/PRIVATE_KEY
echo $key >./$MAIN_PATH_HOME/faucet/PRIVATE_KEY
}

function main() {
Expand All @@ -262,12 +249,11 @@ function main() {
add_key "reticulum01"
add_key "reticulum02"
add_key "reticulum03"
add_key "vlval"
add_key "treasury"
add_key "faucet"
add_key_predefined

init_localtestnet
gala init localtestnet --chain-id $CHAIN_ID --default-denom $BASE_DENOM
configure_app

local faucet_address_bech32=$(gala keys show faucet -a --keyring-dir $MAIN_PATH_HOME)
Expand All @@ -280,23 +266,27 @@ function main() {
# Add genesis accounts
add_genesis_account "reticulum01" "10000000000000000000000$BASE_DENOM"
add_genesis_account "reticulum02" "10000000000000000000000$BASE_DENOM"
add_genesis_account "reticulum03" "10000000000000000000000$BASE_DENOM"

add_genesis_account "faucet" "10000000000000000000000$BASE_DENOM"
add_genesis_account "localkey" "10000000000000000000000$BASE_DENOM"
add_genesis_account "treasury" "950000000000000000000000$BASE_DENOM"
add_genesis_account "vlval" "10000000000000000000000$BASE_DENOM"


# Initialize validators
initialize_validator "reticulum01" "127.0.1.1" 26656 "9000000000000000000000$BASE_DENOM"
initialize_validator "reticulum02" "127.0.1.2" 26656 "9000000000000000000000$BASE_DENOM"
initialize_validator "vlval" "95.154.64.137" 26656 "9000000000000000000000$BASE_DENOM"
initialize_validator "reticulum01" "127.0.0.2" 26656 "9000000000000000000000$BASE_DENOM"
initialize_validator "reticulum02" "127.0.0.3" 26656 "9000000000000000000000$BASE_DENOM"
initialize_validator "reticulum03" "127.0.0.4" 26656 "9000000000000000000000$BASE_DENOM"

collect_gentxs
validate_genesis
gala collect-gentxs

rm $MAIN_PATH_CONFIG/node_key.json
rm $MAIN_PATH_CONFIG/priv_validator_key.json

gala validate-genesis

configure_validator "reticulum01" "127.0.1.1"
configure_validator "reticulum02" "127.0.1.2"
configure_validator "vlval" "95.154.64.137"
configure_validator "reticulum01" "127.0.0.2"
configure_validator "reticulum02" "127.0.0.3"
configure_validator "reticulum03" "127.0.0.4"

configure_faucet
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test: ## some tests
cd tests/galacli && $(MAKE)
1 change: 1 addition & 0 deletions tests/galacli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
data
config
node0*
__pycache__
20 changes: 20 additions & 0 deletions tests/galacli/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uname=$(shell uname -s)
is_darwin :=$(filter Darwin,$(uname))

all: $(if $(is_darwin),network,) clean start

clean:
rm -rf node0*

.venv/bin/python:
uv venv
uv sync

start: .venv/bin/python
.venv/bin/python galacli.py

ifeq ($(uname),Darwin)
network: /tmp/127.0.0.2 /tmp/127.0.0.3 /tmp/127.0.0.4
/tmp/127.0.0.%:
sudo ifconfig lo0 alias $(shell basename $@) up && touch $@
endif
Loading

0 comments on commit c2ff3b3

Please sign in to comment.