Skip to content

Commit

Permalink
working foundation
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Aug 10, 2024
1 parent eb850a8 commit 44abecb
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 30 deletions.
120 changes: 95 additions & 25 deletions local-interchain/bash/source.bash
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
# IMPORT ME WITH: source <(curl -s https://github.com/strangelove-ventures/interchaintest/tree/main/local-interchain/bash/source.bash)

# CONTENT_HEADERS="Content-Type: application/json"
# TODOL: prefix with ICT_ for all functions

# MAKE_GENERAL_REQUEST http://127.0.0.1:8080 '{"chain_id":"localjuno-1","action":"q","cmd":"bank total"}'
# Call this standalone, not from another function
# MAKE_GENERAL_REQUEST() {
# API=$1
# DATA=$2

# curl "$API" --include --header "\"Content-Type: application/json\"" -X POST --data $DATA
# }

# MAKE_REQUEST http://127.0.0.1:8080 localjuno-1 q "bank total"
# MAKE_REQUEST http://127.0.0.1:8080 localjuno-1 "q" "bank total"
MAKE_REQUEST() {
API=$1

Expand All @@ -23,38 +14,61 @@ MAKE_REQUEST() {
DATA=`printf '{"chain_id":"%s","action":"%s","cmd":"MYCOMMAND"}' $CHAIN_ID $ACTION`
DATA=`echo $DATA | sed "s/MYCOMMAND/$COMMAND/g"`

curl "$API" --header "Content-Type: application/json" -X POST -d "$DATA"
curl "$API" -ss --no-progress-meter --header "Content-Type: application/json" -X POST -d "$DATA"
}


# QUERY "http://localhost:8080" "localjuno-1" "bank balances juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"
QUERY() {
API=$1
CHAIN_ID=$2
CMD=$3 # can be multiple words
MAKE_REQUEST "$API" $CHAIN_ID "q" "$CMD"
}

# MAKE_BIN "http://localhost:8080" "localjuno-1" "decode"
MAKE_BIN() {
API=$1
CHAIN_ID=$2
CMD=$3 # can be multiple words
MAKE_REQUEST "$API" $CHAIN_ID "bin" "$CMD"
}

# MAKE_SH_EXEC "http://localhost:8080" "localjuno-1" "ls -l"
MAKE_SH_EXEC() {
API=$1
CHAIN_ID=$2
CMD=$3 # can be multiple words
MAKE_REQUEST "$API" $CHAIN_ID "exec" "$CMD"
}

# FAUCET_REQUEST "http://localhost:8080" "localjuno-1" "1000000000ujuno" "juno1qk7zqy3k2v3jx2zq2z2zq2zq2zq2zq2zq2zq"
FAUCET_REQUEST() {
API=$1
CHAIN_ID=$2
AMOUNT=$3
ADDRESS=$4
# MAKE_REQUEST $API '{"chain_id":"'$CHAIN_ID'","action":"faucet","cmd":"amount='$AMOUNT';address='$ADDRESS'"}'
MAKE_REQUEST $API $CHAIN_ID "faucet" "amount=$AMOUNT;address=$ADDRESS"
}

KILL_ALL() {
API=$1
MAKE_REQUEST $API '{"action":"kill-all"}'
}

# QUERY "http://localhost:8080" "localjuno-1" "bank balances juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"
QUERY() {

# === COSMWASM ===
DUMP_CONTRACT_STATE() {
API=$1
CHAIN_ID=$2
CMD=$3 # can be multiple words
CONTRACT=$3
HEIGHT=$4

# MAKE_REQUEST "$API" \''{"chain_id":"'$CHAIN_ID'","action":"q","cmd":"'$CMD'"}'\'
MAKE_REQUEST "$API" $CHAIN_ID "q" "$CMD"
MAKE_REQUEST $API $CHAIN_ID "recover-key" "contract=$CONTRACT;height=$HEIGHT"
}

# relayer

# todo: info request curl -G -d "chain_id=localjuno-1" -d "request=peer" http://127.0.0.1:8080/info
# === OTHER ===
KILL_ALL() {
API=$1
CHAIN_ID=$2
MAKE_REQUEST $API $CHAIN_ID "kill-all" ""
}

GET_PEER() {
API=$1
Expand All @@ -67,3 +81,59 @@ GET_PEER() {
curl -G -d "chain_id=$CHAIN_ID" -d "request=peer" $API
}

# ADD_FULL_NODE http://127.0.0.1:8080 "localjuno-1" "1"
ADD_FULL_NODE() {
API=$1
CHAIN_ID=$2
AMOUNT=$3

MAKE_REQUEST $API $CHAIN_ID "add-full-nodes" "amount=$AMOUNT"
}

# RECOVER_KEY "http://localhost:8080" "localjuno-1" "mykey" "my mnemonic string here"
RECOVER_KEY() {
API=$1
CHAIN_ID=$2
KEYNAME=$3
shift 3 # get the 4th argument and up as the command
MNEMONIC="$*"

MAKE_REQUEST $API $CHAIN_ID "recover-key" "keyname=$KEYNAME;mnemonic=$MNEMONIC"
}

# === RELAYER ===
RELAYER_STOP() {
API=$1
CHAIN_ID=$2

# TODO: how does this function?
MAKE_REQUEST $API $CHAIN_ID "stop-relayer" ""
}

RELAYER_START() {
API=$1
CHAIN_ID=$2
CMD=$3

MAKE_REQUEST $API $CHAIN_ID "start-relayer" "$CMD"
}

# RELAYER_EXEC http://127.0.0.1:8080 "localjuno-1" "rly paths list"
RELAYER_EXEC() {
API=$1
CHAIN_ID=$2
shift 2 # get the 3rd argument and up as the command
CMD="$*"

MAKE_REQUEST $API $CHAIN_ID "relayer-exec" "$CMD"
}

# RELAYER_CHANNELS http://127.0.0.1:8080 "localjuno-1"
RELAYER_CHANNELS() {
API=$1
CHAIN_ID=$2

MAKE_REQUEST $API $CHAIN_ID "get_channels" ""
}


76 changes: 71 additions & 5 deletions local-interchain/bash/test.bash
Original file line number Diff line number Diff line change
@@ -1,12 +1,78 @@
#!/bin/bash

# local-ic start base_ibc

source ./source.bash
# source <(curl -s https://github.com/strangelove-ventures/interchaintest/tree/main/local-interchain/bash/source.bash)

# QUERY http://127.0.0.1:8080/ "localjuno-1" "bank total"
# MAKE_REQUEST http://127.0.0.1:8080 "localjuno-1" "q" "bank total"

API_ADDR="http://localhost:8080"

# Set standard interaction defaults
MAKE_BIN "$API_ADDR" "localjuno-1" "config keyring-backend test"
MAKE_BIN "$API_ADDR" "localjuno-1" "config output json"

# exitIfEmpty "$someKey" someKey
function exitIfEmpty() {
if [ -z "$1" ]; then
echo "Exiting because ${2} is empty"
exit 1
fi
}

# Get total bank supply
BANK_TOTAL=`QUERY $API_ADDR "localjuno-1" "bank total"` && echo "BANK_TOTAL: $BANK_TOTAL"
exitIfEmpty "$BANK_TOTAL" "BANK_TOTAL"
echo $BANK_TOTAL | jq -r '.supply'

# Get total bank supply another way (directly)
BANK_TOTAL=`MAKE_REQUEST $API_ADDR "localjuno-1" "q" "bank total"` && echo "BANK_TOTAL: $BANK_TOTAL"
exitIfEmpty "$BANK_TOTAL" "BANK_TOTAL"
echo $BANK_TOTAL | jq -r '.supply'


# faucet to user
FAUCET_RES=`FAUCET_REQUEST "$API_ADDR" "localjuno-1" "7" "juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"` && echo "FAUCET_RES: $FAUCET_RES"
FAUCET_CONFIRM=`QUERY $API_ADDR "localjuno-1" "bank balances juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"` && echo "FAUCET_CONFIRM: $FAUCET_CONFIRM"
exitIfEmpty "$FAUCET_CONFIRM" "FAUCET_CONFIRM"

if [ $(echo $FAUCET_CONFIRM | jq -r '.balances[0].amount') -lt 7 ]; then
echo "FAUCET_CONFIRM is less than 7"
exit 1
fi


PEER=`GET_PEER $API_ADDR "localjuno-1"` && echo "PEER: $PEER"
exitIfEmpty "$PEER" "PEER"

# RELAYER
CHANNELS=`RELAYER_CHANNELS $API_ADDR "localjuno-1"` && echo "CHANNELS: $CHANNELS"
exitIfEmpty "$CHANNELS" "CHANNELS"

RELAYER_EXEC $API_ADDR "localjuno-1" "rly paths list"
RELAYER_EXEC $API_ADDR "localjuno-1" "rly chains list"
RLY_BALANCE=`RELAYER_EXEC $API_ADDR "localjuno-1" "rly q balance localjuno-1 --output=json"` && echo "RLY_BALANCE: $RLY_BALANCE"
exitIfEmpty "$RLY_BALANCE" "RLY_BALANCE"
echo $RLY_BALANCE | jq -r '.balance'


# Recover a key and validate
COSMOS_KEY_STATUS=`RECOVER_KEY $API_ADDR "localjuno-1" "mynewkey" "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art"` && echo "COSMOS_KEY_STATUS: $COSMOS_KEY_STATUS"

COSMOS_KEY_ADDRESS=`MAKE_BIN "$API_ADDR" "localjuno-1" "keys show mynewkey -a"` && echo "COSMOS_KEY_ADDRESS: $COSMOS_KEY_ADDRESS"
exitIfEmpty "$COSMOS_KEY_ADDRESS" "COSMOS_KEY_ADDRESS"

# Run a bash / shell command in the docekr instance
MISC_BASH_CMD=`MAKE_SH_EXEC "$API_ADDR" "localjuno-1" "ls -l"` && echo "MISC_BASH_CMD: $MISC_BASH_CMD"
exitIfEmpty "$MISC_BASH_CMD" "MISC_BASH_CMD"

FULL_NODE_ADDED=`ADD_FULL_NODE $API_ADDR "localjuno-1" "1"`
exitIfEmpty "$FULL_NODE_ADDED" "FULL_NODE_ADDED"

# FAUCET_REQUEST "http://localhost:8080" "localjuno-1" "7" "juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"
# QUERY http://127.0.0.1:8080/ "localjuno-1" "bank balances juno10r39fueph9fq7a6lgswu4zdsg8t3gxlq670lt0"
# Stop the relayer
RELAYER_STOP $API_ADDR "localjuno-1"

KILL_ALL $API_ADDR "localjuno-1"

GET_PEER http://127.0.0.1:8080 "localjuno-1"
killall local-ic
exit 0

0 comments on commit 44abecb

Please sign in to comment.