diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 215fd7542..c4c39d030 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 230a8deeb..8d2cd2896 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/contrib/bashlib.sh b/contrib/bashlib.sh index 7680e4e79..2279cc456 100644 --- a/contrib/bashlib.sh +++ b/contrib/bashlib.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -e - # ————————————————————————————————————————————————— # COLORS: Terminal colors are set with ANSI escape codes. @@ -40,7 +38,17 @@ log_error() { } log_success() { - echo "${COLOR_GREEN}✅ Success:${COLOR_RESET}" "$@" + 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}WARNING${COLOR_RESET}" "$@" >&2 +} + +log_info() { + echo "${COLOR_MAGENTA}INFO${COLOR_RESET}" "$@" } # ————————————————————————————————————————————————— diff --git a/contrib/scripts/localnet.sh b/contrib/scripts/localnet.sh index 868ea94b0..7b7cdade0 100755 --- a/contrib/scripts/localnet.sh +++ b/contrib/scripts/localnet.sh @@ -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 # ------------------------------------------------------------------------ @@ -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') @@ -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: ' @@ -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" +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 diff --git a/justfile b/justfile index 31bc57854..bd91f243c 100644 --- a/justfile +++ b/justfile @@ -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 @@ -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" + +# 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 @@ -46,7 +73,7 @@ tidy: just lint just fmt -release-test: +test-release: make release-snapshot release-publish: diff --git a/proto/nibiru/sudo/v1/event.proto b/proto/nibiru/sudo/v1/event.proto index f40344447..eeb8a7e8e 100644 --- a/proto/nibiru/sudo/v1/event.proto +++ b/proto/nibiru/sudo/v1/event.proto @@ -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 ]; diff --git a/proto/nibiru/sudo/v1/state.proto b/proto/nibiru/sudo/v1/state.proto index 164d18937..8e54d80fb 100644 --- a/proto/nibiru/sudo/v1/state.proto +++ b/proto/nibiru/sudo/v1/state.proto @@ -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 ]; } diff --git a/x/sudo/types/event.pb.go b/x/sudo/types/event.pb.go index 8dc8afb33..f49fa8417 100644 --- a/x/sudo/types/event.pb.go +++ b/x/sudo/types/event.pb.go @@ -24,6 +24,7 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// EventUpdateSudoers: ABCI event emitted upon execution of "MsgEditSudoers". type EventUpdateSudoers struct { Sudoers Sudoers `protobuf:"bytes,1,opt,name=sudoers,proto3" json:"sudoers"` // Action is the type of update that occured to the "sudoers" diff --git a/x/sudo/types/state.pb.go b/x/sudo/types/state.pb.go index 99b71715a..2fcf10a1a 100644 --- a/x/sudo/types/state.pb.go +++ b/x/sudo/types/state.pb.go @@ -77,7 +77,7 @@ func (m *Sudoers) GetContracts() []string { return nil } -// GenesisState defines the module's genesis state. +// GenesisState: State for migrations and genesis for the x/sudo module. type GenesisState struct { Sudoers Sudoers `protobuf:"bytes,1,opt,name=sudoers,proto3" json:"sudoers"` }