-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add test-upgrade script #94
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
Open
AdriaCarrera
wants to merge
1
commit into
main
Choose a base branch
from
feat/test-upgrade
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #!/bin/bash | ||
|
|
||
| # ========== Helper: Read named parameters ========== | ||
| for arg in "$@"; do | ||
| case $arg in | ||
| --chainId=*) CHAIN_ID="${arg#*=}" ;; | ||
| --nodeHome=*) NODE_HOME="${arg#*=}" ;; | ||
| --exportedState=*) EXPORTED_STATE="${arg#*=}" ;; | ||
| --version=*) VERSION="${arg#*=}" ;; | ||
| *) echo "⚠️ Unknown argument: $arg" ;; | ||
| esac | ||
| done | ||
|
|
||
| # ========== Fallback to env vars if not passed ========== | ||
| : "${CHAIN_ID:=${CHAIN_ID_ENV:-}}" | ||
| : "${NODE_HOME:=${NODE_HOME_ENV:-}}" | ||
| : "${EXPORTED_STATE:=${EXPORTED_STATE_ENV:-}}" | ||
| : "${VERSION:=${VERSION_ENV:-}}" | ||
|
|
||
| # ========== Validate dependencies ========== | ||
| echo "ℹ️ Checking required tools..." | ||
| for cmd in exrpd jq sponge; do | ||
| if ! command -v "$cmd" &> /dev/null; then | ||
| echo "❌ Error: Required tool '$cmd' not found. Please install it before running this script." | ||
| exit 1 | ||
| fi | ||
| done | ||
| echo "✅ All tools found" | ||
|
|
||
| # ========== Validate required variables ========== | ||
| missing_vars=() | ||
| for var in CHAIN_ID NODE_HOME EXPORTED_STATE VERSION; do | ||
| if [ -z "${!var}" ]; then | ||
| missing_vars+=("$var") | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#missing_vars[@]} -ne 0 ]; then | ||
| echo "❌ Error: The following required variables are missing:" | ||
| for var in "${missing_vars[@]}"; do echo " - $var"; done | ||
| echo | ||
| echo "👉 You can provide them as parameters or environment variables." | ||
| echo | ||
| echo "📌 Example usage:" | ||
| echo "./test-upgrade.sh \\" | ||
| echo " --chainId=\"xrplevm_1440000-1\" \\" | ||
| echo " --nodeHome=\"./.exrpd\" \\" | ||
| echo " --exportedState=\"./exported.json\" \\" | ||
| echo " --version=\"9.0.0\" \\" | ||
| echo | ||
| echo "Or set them as environment variables before running:" | ||
| echo "export CHAIN_ID=... && ./test-upgrade.sh" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "ℹ️ Initializing node home in $NODE_HOME..." | ||
| exrpd config set client chain-id "$CHAIN_ID" --home "$NODE_HOME" | ||
| exrpd config set client keyring-backend test --home "$NODE_HOME" | ||
| exrpd keys add key --key-type eth_secp256k1 --keyring-backend test --home "$NODE_HOME" | ||
| exrpd init localnode --chain-id "$CHAIN_ID" --home "$NODE_HOME" > /dev/null 2>&1 | ||
| echo "✅ Node home initialized " | ||
|
|
||
| echo "ℹ️ Configuring genesis..." | ||
| cp $EXPORTED_STATE genesis.json | ||
| echo "ℹ️ Modifying bank ibc denoms..." | ||
| for ((i=1; i< $(jq '.app_state.bank.denom_metadata | length' genesis.json); i++)); do | ||
| jq --argjson i "$i" '.app_state.bank.denom_metadata[$i].denom_units[0].denom = .app_state.bank.denom_metadata[$i].base' genesis.json | sponge genesis.json | ||
| jq --argjson i "$i" '.app_state.bank.denom_metadata[$i].display = .app_state.bank.denom_metadata[$i].base' genesis.json | sponge genesis.json | ||
| done | ||
|
|
||
| echo "ℹ️ Modifying ratelimit initial_height..." | ||
| jq '.app_state.ratelimit.hour_epoch.epoch_start_height = .initial_height' genesis.json | sponge genesis.json | ||
|
|
||
| echo "ℹ️ Modifying gov voting periods..." | ||
| jq '.app_state.gov.params.voting_period = "30s"' genesis.json | sponge genesis.json | ||
| jq '.app_state.gov.params.expedited_voting_period = "20s"' genesis.json | sponge genesis.json | ||
|
|
||
| mv genesis.json "$NODE_HOME"/config/genesis.json | ||
| echo "✅ Genesis configured " | ||
|
|
||
| echo "ℹ️ Configuring local validator..." | ||
| echo "ℹ️ Adding local validator genesis account..." | ||
| exrpd add-genesis-account $(exrpd keys show key -a --keyring-backend test --home "$NODE_HOME") 100000000poa,10000xrp --home "$NODE_HOME" | ||
| echo "ℹ️ Creating local validator staking transaction..." | ||
| exrpd gentx key 100000000poa --fees 80000000000000000axrp --chain-id $CHAIN_ID --commission-rate 0 \ | ||
| --commission-max-rate 0 --commission-max-change-rate 0 --timeout-height $(jq '.initial_height' $EXPORTED_STATE) \ | ||
| --keyring-backend test --home "$NODE_HOME" \ | ||
| --account-number $(jq '.app_state.auth.accounts | length' $EXPORTED_STATE) --sequence 0 --offline --gas 400000 | ||
| exrpd collect-gentxs --home "$NODE_HOME" > /dev/null 2>&1 | ||
| exrpd validate-genesis --home "$NODE_HOME" | ||
| echo "✅ Local validator configured " | ||
|
|
||
| jq '.initial_height = (.initial_height | tostring)' "$NODE_HOME"/config/genesis.json | sponge "$NODE_HOME"/config/genesis.json | ||
|
|
||
| echo "ℹ️ Starting the node in background process..." | ||
| exrpd start --home "$NODE_HOME" & | ||
|
|
||
| sleep 10 | ||
|
|
||
| INITIAL_HEIGHT=$(jq '.initial_height' .exrpd/config/genesis.json) | ||
| INITIAL_HEIGHT=${INITIAL_HEIGHT//\"/} | ||
| PROPOSAL_HEIGHT=$(( INITIAL_HEIGHT + 15 )) | ||
| echo "ℹ️ Creating upgrade proposal for version $VERSION and height $PROPOSAL_HEIGHT..." | ||
| cat <<EOF > upgrade-proposal.json | ||
| { | ||
| "messages": [ | ||
| { | ||
| "@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade", | ||
| "authority": "ethm10d07y265gmmuvt4z0w9aw880jnsr700jpva843", | ||
| "plan": { | ||
| "name": "v$VERSION", | ||
| "height": "$PROPOSAL_HEIGHT", | ||
| "info": "{\"binaries\":{\"linux/amd64\":\"https://github.com/xrplevm/node/releases/download/v$VERSION/node_$VERSION_Linux_amd64.tar.gz\",\"linux/arm64\":\"https://github.com/xrplevm/node/releases/download/v$VERSION/node_$VERSION_Linux_arm64.tar.gz\",\"darwin/amd64\":\"https://github.com/xrplevm/node/releases/download/v$VERSION/node_$VERSION_Darwin_amd64.tar.gz\",\"darwin/arm64\":\"https://github.com/xrplevm/node/releases/download/v$VERSION/node_$VERSION_Darwin_arm64.tar.gz\"}}" | ||
| } | ||
| } | ||
| ], | ||
| "title": "Protocol upgrade to v$VERSION", | ||
| "summary": "This proposal will execute a protocol upgrade to the version $VERSION (https://github.com/xrplevm/node/releases/tag/v$VERSION)", | ||
| "metadata": "ipfs://QmRWbE8bibBjtacYaaJ1suRpxFiHuYCD1T4Uz6QV27GXKH", | ||
| "deposit": "500000000000000000000axrp" | ||
| } | ||
| EOF | ||
|
|
||
| exrpd --home "$NODE_HOME" tx gov submit-proposal ./upgrade-proposal.json --from key --gas-prices 800000000000axrp --gas 400000 --yes | ||
| echo "✅ Proposal created" | ||
|
|
||
| sleep 10 | ||
| PROPOSAL_ID=$(exrpd q gov proposals --home $NODE_HOME -o json --page-count-total | jq '.pagination.total') | ||
| PROPOSAL_ID=${PROPOSAL_ID//\"/} | ||
| echo "ℹ️ Voting for proposal $PROPOSAL_ID..." | ||
|
|
||
| exrpd --home "$NODE_HOME" tx gov vote "$PROPOSAL_ID" yes --from key --gas-prices 800000000000axrp --yes --broadcast-mode async | ||
| echo "✅ Proposal voted" | ||
|
|
||
| rm upgrade-proposal.json | ||
| wait | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should replace this line with the current: