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

ci(localnet): Fix script, simplify, and test in CI. #1714

Merged
merged 8 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
15 changes: 13 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ jobs:
with:
go-version: 1.21

- name: "Install just"
# casey/just: https://just.systems/man/en/chapter_6.html
# taiki-e/install-action: https://github.com/taiki-e/install-action
uses: taiki-e/install-action@just

- name: "Build the nibid binary"
run: make build
run: |
just install

- name: "Run scripts/chaosnet.sh (Used in Docker image)"
run: bash contrib/scripts/chaosnet.sh &
run: |
just test-chaosnet

- name: "Run scripts/localnet.sh"
run: |
just test-localnet
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - feat(inflation): add events for inflation distribution
* [#1695](https://github.com/NibiruChain/nibiru/pull/1695) - fix(sudo): Make blank sudoers root invalid at genesis time.
* [#1710](https://github.com/NibiruChain/nibiru/pull/1710) - refactor(perp): Clean and organize module errors for x/perp
* [#1714](https://github.com/NibiruChain/nibiru/pull/1714) - ci(localnet.sh): Fix script, simplify, and test in CI.

### Dependencies

Expand Down
12 changes: 10 additions & 2 deletions contrib/bashlib.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

set -e

# —————————————————————————————————————————————————
# COLORS: Terminal colors are set with ANSI escape codes.

Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -43,6 +41,16 @@ log_success() {
echo "${COLOR_GREEN}✅ Success:${COLOR_RESET}" "$@"
}

# log_warning: WARNING messages represent non-critical issues that might not
# require immediate action but should be noted as points of concern or failure.
log_warning() {
echo "${COLOR_YELLOW}INFO${COLOR_RESET}" "$@" >&2
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
}

log_info() {
echo "${COLOR_MAGENTA}INFO${COLOR_RESET}" "$@"
}

# —————————————————————————————————————————————————
# OK Suffix: Functions used for error handling or validating inputs.

Expand Down
113 changes: 41 additions & 72 deletions contrib/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,90 +112,38 @@ else
echo_error "Failed to initialize $CHAIN_ID"
fi

# Configure keyring-backend to "test"
echo_info "Configuring keyring-backend..."
if $BINARY config keyring-backend test; then
echo_success "Successfully configured keyring-backend"
else
echo_error "Failed to configure keyring-backend"
fi

# Configure chain-id
echo_info "Configuring chain-id..."
if $BINARY config chain-id $CHAIN_ID; then
echo_success "Successfully configured chain-id"
else
echo_error "Failed to configure chain-id"
fi

# Configure broadcast mode
echo_info "Configuring broadcast mode..."
if $BINARY config broadcast-mode sync; then
echo_success "Successfully configured broadcast-mode"
else
echo_error "Failed to configure broadcast mode"
fi

# Configure output mode
echo_info "Configuring output mode..."
if $BINARY config output json; then
echo_success "Successfully configured output mode"
else
echo_error "Failed to configure output mode"
fi
# nibid config
echo_info "Updating nibid config..."
$BINARY config keyring-backend test
$BINARY config chain-id $CHAIN_ID
$BINARY config broadcast-mode sync
$BINARY config output json
$BINARY config # Prints config.

# Enable API Server
echo_info "Enabling API server"
if sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled API server"
else
echo_error "Failed to enable API server"
fi
echo_info "config/app.toml: Enabling API server"
sed -i $SEDOPTION '/\[api\]/,+3 s/enable = false/enable = true/' $CHAIN_DIR/config/app.toml

# Enable Swagger Docs
echo_info "Enabling Swagger Docs"
if sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled Swagger Docs"
else
echo_error "Failed to enable Swagger Docs"
fi
echo_info "config/app.toml: Enabling Swagger Docs"
sed -i $SEDOPTION 's/swagger = false/swagger = true/' $CHAIN_DIR/config/app.toml

# Enable CORS for localnet
echo_info "Enabling CORS"
if sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml; then
echo_success "Successfully enabled CORS"
else
echo_error "Failed to enable CORS"
fi
echo_info "config/app.toml: Enabling CORS"
sed -i $SEDOPTION 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/' $CHAIN_DIR/config/app.toml


echo_info "Adding genesis accounts..."

val_key_name="validator"

echo "$MNEMONIC" | $BINARY keys add $val_key_name --recover
if $BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS; then
echo_success "Successfully added genesis account: $val_key_name"
else
echo_error "Failed to add genesis account: $val_key_name"
fi
$BINARY add-genesis-account $($BINARY keys show $val_key_name -a) $GENESIS_COINS
echo_success "Successfully added genesis account: $val_key_name"

val_address=$($BINARY keys list | jq -r '.[] | select(.name == "validator") | .address')
val_address=${val_address:-"nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl"}

echo_info "Adding gentx validator..."
if $BINARY genesis gentx $val_key_name 900000000unibi --chain-id $CHAIN_ID; then
echo_success "Successfully added gentx"
else
echo_error "Failed to add gentx"
fi

echo_info "Collecting gentx..."
if $BINARY genesis collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi

# ------------------------------------------------------------------------
# Configure genesis params
# ------------------------------------------------------------------------
Expand Down Expand Up @@ -244,7 +192,7 @@ add_genesis_perp_markets_with_coingecko_prices() {
fi
}

nibid genesis add-genesis-perp-market --pair=ubtc:unusd --sqrt-depth=$reserve_amt --price-multiplier=$price_btc
nibid genesis add-genesis-perp-market --pair=ubtc:unusd --sqrt-depth="$reserve_amt" --price-multiplier="$price_btc" --oracle-pair="ubtc:uusd"
check_fail nibid genesis add-genesis-perp-market

price_eth=$(cat tmp_market_prices.json | jq -r '.ethereum.usd')
Expand All @@ -253,7 +201,7 @@ add_genesis_perp_markets_with_coingecko_prices() {
return 1
fi

nibid genesis add-genesis-perp-market --pair=ueth:unusd --sqrt-depth=$reserve_amt --price-multiplier=$price_eth
nibid genesis add-genesis-perp-market --pair=ueth:unusd --sqrt-depth=$reserve_amt --price-multiplier="$price_eth" --oracle-pair="ueth:uusd"
check_fail nibid genesis add-genesis-perp-market

echo 'tmp_market_prices: '
Expand Down Expand Up @@ -284,11 +232,32 @@ fi
add_genesis_param '.app_state.sudo.sudoers.root = "'"$val_address"'"'

# hack for localnet since we don't have a pricefeeder yet
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc:unusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].pair = "ubtc:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[0].exchange_rate = "'"$price_btc"'"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth:unusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].pair = "ueth:uuusd"'
add_genesis_param '.app_state.oracle.exchange_rates[1].exchange_rate = "'"$price_eth"'"'

# ------------------------------------------------------------------------
# Gentx
# ------------------------------------------------------------------------

echo_info "Adding gentx validator..."
if $BINARY genesis gentx $val_key_name 900000000unibi --chain-id $CHAIN_ID; then
echo_success "Successfully added gentx"
Comment on lines 232 to +246
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gentx has to occur after we add the address to the x/sudo genesis

else
echo_error "Failed to add gentx"
fi

echo_info "Collecting gentx..."
if $BINARY genesis collect-gentxs; then
echo_success "Successfully collected genesis txs into genesis.json"
else
echo_error "Failed to collect genesis txs"
fi

# ------------------------------------------------------------------------
# Start the network
# ------------------------------------------------------------------------

echo_info "Starting $CHAIN_ID in $CHAIN_DIR..."
$BINARY start --home "$CHAIN_DIR" --pruning nothing
29 changes: 28 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ setup:

# Locally install the `nibid` binary and build if needed.
install:
go mod tidy
make install

install-clean:
rm -rf temp
just install

# Build the `nibid` binary.
build:
make build
Expand Down Expand Up @@ -34,6 +39,28 @@ lint:

golangci-lint run --allow-parallel-runners --fix

# Runs a Nibiru local network
localnet:
make localnet

# Test: "localnet.sh" script
test-localnet:
#!/usr/bin/env bash
source contrib/bashlib.sh
just install
bash contrib/scripts/localnet.sh &
log_info "Sleeping for 6 seconds to give network time to spin up and run a few blocks."
sleep 6
kill $(pgrep -x nibid) # Stops network running as background process.
log_success "Spun up localnet"
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved

# Test: "chaosnet.sh" script
test-chaosnet:
#!/usr/bin/env bash
source contrib/bashlib.sh
which_ok nibid
bash contrib/scripts/chaosnet.sh

# Runs golang formatter (gofumpt)
fmt:
gofumpt -w x app
Expand All @@ -46,7 +73,7 @@ tidy:
just lint
just fmt

release-test:
test-release:
make release-snapshot

release-publish:
Expand Down
1 change: 1 addition & 0 deletions proto/nibiru/sudo/v1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "nibiru/sudo/v1/state.proto";

option go_package = "github.com/NibiruChain/nibiru/x/sudo/types";

// EventUpdateSudoers: ABCI event emitted upon execution of "MsgEditSudoers".
message EventUpdateSudoers {
nibiru.sudo.v1.Sudoers sudoers = 1 [ (gogoproto.nullable) = false ];

Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion proto/nibiru/sudo/v1/state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ message Sudoers {
repeated string contracts = 2;
}

// GenesisState defines the module's genesis state.
// GenesisState: State for migrations and genesis for the x/sudo module.
message GenesisState { Sudoers sudoers = 1 [ (gogoproto.nullable) = false ]; }
1 change: 1 addition & 0 deletions x/sudo/types/event.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion x/sudo/types/state.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading