Skip to content

Commit

Permalink
Migrate SDK consts to Registry [3/3] - CLI (#3659)
Browse files Browse the repository at this point in the history
### Description

Update the CLI to read and write from registries

### Related issues

hyperlane-xyz/issues#917

### Backward compatibility

No, this changes several CLI arguments related to configs and artifacts

### Testing

Locally and with ci-test.sh
  • Loading branch information
jmrossy authored Apr 30, 2024
2 parents 2881bde + 85a5562 commit b3886dc
Show file tree
Hide file tree
Showing 60 changed files with 1,248 additions and 1,721 deletions.
10 changes: 9 additions & 1 deletion typescript/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.env*
/dist
/cache

# Deployment artifacts and local registry configs
/configs
/artifacts
/artifacts
/chains
/deployments

# Test artifacts
/test-configs/**/addresses.yaml
/test-configs/*/deployments
153 changes: 68 additions & 85 deletions typescript/cli/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ _main() {
# with the routing over igp hook (which is closer to production deployment)
TEST_TYPE=$1
if [ -z "$TEST_TYPE" ]; then
echo "Usage: ci-test.sh <test-type>"
echo "Usage: ci-test.sh <$TEST_TYPE_PRESET_HOOK | $TEST_TYPE_CONFIGURED_HOOK | $TEST_TYPE_PI_CORE>"
exit 1
fi

HOOK_FLAG=false
if [ "$TEST_TYPE" == $TEST_TYPE_CONFIGURED_HOOK ]; then
HOOK_FLAG=true
fi
prepare_environment_vars;

prepare_anvil;

Expand All @@ -48,23 +45,36 @@ _main() {
echo "Done";
}

prepare_anvil() {
prepare_environment_vars() {
ANVIL_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
CHAIN1=anvil1
CHAIN2=anvil2
EXAMPLES_PATH=./examples
TEST_CONFIGS_PATH=./test-configs
CLI_PATH=./typescript/cli
REGISTRY_PATH="$TEST_CONFIGS_PATH/anvil"
CORE_ISM_PATH="$EXAMPLES_PATH/ism.yaml"
WARP_DEPLOY_CONFIG_PATH="$EXAMPLES_PATH/warp-route-deployment.yaml"
DEPLOY_ERC20_PATH=./src/tests/deployTestErc20.ts

# use different chain names and config for pi<>core test
if [ "$TEST_TYPE" == $TEST_TYPE_PI_CORE ]; then
CHAIN1=anvil
CHAIN2=ethereum
EXAMPLES_PATH=./examples/fork
REGISTRY_PATH="$TEST_CONFIGS_PATH/fork"
CORE_ISM_PATH="$REGISTRY_PATH/ism.yaml"
WARP_DEPLOY_CONFIG_PATH="$REGISTRY_PATH/warp-route-deployment.yaml"
fi

CHAIN1_CAPS=$(echo "${CHAIN1}" | tr '[:lower:]' '[:upper:]')
CHAIN2_CAPS=$(echo "${CHAIN2}" | tr '[:lower:]' '[:upper:]')

HOOK_FLAG=false
if [ "$TEST_TYPE" == $TEST_TYPE_CONFIGURED_HOOK ]; then
HOOK_FLAG=true
fi
}

prepare_anvil() {
CHAIN1_PORT=8545
CHAIN2_PORT=8555

Expand All @@ -73,6 +83,8 @@ prepare_anvil() {
rm -rf /tmp/${CHAIN1}*
rm -rf /tmp/${CHAIN2}*
rm -rf /tmp/relayer
rm -f $CLI_PATH/$TEST_CONFIGS_PATH/*/chains/*/addresses.yaml
rm -rf $CLI_PATH/$TEST_CONFIGS_PATH/*/deployments

if [[ $OSTYPE == 'darwin'* ]]; then
# kill child processes on exit, but only locally because
Expand All @@ -95,7 +107,7 @@ prepare_anvil() {
if [ "$TEST_TYPE" == $TEST_TYPE_PI_CORE ]; then
# Fetch the RPC of chain to fork
cd typescript/infra
RPC_URL=$(yarn tsx scripts/print-chain-metadatas.ts -e mainnet3 | jq -r ".${CHAIN2}.rpcUrls[0].http")
RPC_URL=$(LOG_LEVEL=error yarn tsx scripts/print-chain-metadatas.ts -e mainnet3 | jq -r ".${CHAIN2}.rpcUrls[0].http")
cd ../../

# run the fork chain
Expand All @@ -112,8 +124,6 @@ prepare_anvil() {
fi

set -e

echo "{}" > /tmp/empty-artifacts.json
}

reset_anvil() {
Expand All @@ -129,95 +139,65 @@ run_hyperlane_deploy_core_dry_run() {
return;
fi

BEFORE_CORE_DRY_RUN=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT});
update_deployer_balance;

echo -e "\nDry-running contract deployments to Alfajores"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy core \
--dry-run alfajores \
--targets alfajores \
--chains ${EXAMPLES_PATH}/dry-run/anvil-chains.yaml \
--artifacts /tmp/empty-artifacts.json \
--registry ${TEST_CONFIGS_PATH}/dry-run \
--overrides " " \
$(if [ "$HOOK_FLAG" == "true" ]; then echo "--hook ${EXAMPLES_PATH}/hooks.yaml"; fi) \
--ism ${EXAMPLES_PATH}/ism.yaml \
--out /tmp \
--ism ${TEST_CONFIGS_PATH}/dry-run/ism.yaml \
--key 0xfaD1C94469700833717Fa8a3017278BC1cA8031C \
--yes

AFTER_CORE_DRY_RUN=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
CORE_MIN_GAS=$(bc <<< "($BEFORE_CORE_DRY_RUN - $AFTER_CORE_DRY_RUN) / $GAS_PRICE")
echo "Gas used: $CORE_MIN_GAS"

CORE_ARTIFACTS_PATH=`find /tmp/core-deployment* -type f -exec ls -t1 {} + | head -1`
echo "Core artifacts:"
echo $CORE_ARTIFACTS_PATH
cat $CORE_ARTIFACTS_PATH

AGENT_CONFIG_FILENAME=`ls -t1 /tmp | grep agent-config | head -1`
check_deployer_balance;
}

run_hyperlane_deploy_warp_dry_run() {
if [ "$TEST_TYPE" == $TEST_TYPE_PI_CORE ]; then
return;
fi

BEFORE_WARP_DRY_RUN=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT});
update_deployer_balance;

echo -e "\nDry-running warp route deployments to Alfajores"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy warp \
--dry-run alfajores \
--chains ${EXAMPLES_PATH}/dry-run/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--config ${EXAMPLES_PATH}/dry-run/warp-route-deployment.yaml \
--out /tmp \
--overrides ${TEST_CONFIGS_PATH}/dry-run \
--config ${TEST_CONFIGS_PATH}/dry-run/warp-route-deployment.yaml \
--key 0xfaD1C94469700833717Fa8a3017278BC1cA8031C \
--yes

AFTER_WARP_DRY_RUN=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
WARP_MIN_GAS=$(bc <<< "($BEFORE_WARP_DRY_RUN - $AFTER_WARP_DRY_RUN) / $GAS_PRICE")
echo "Gas used: $WARP_MIN_GAS"

WARP_ARTIFACTS_PATH=`find /tmp/dry-run_warp-route-deployment* -type f -exec ls -t1 {} + | head -1`
echo "Warp dry-run artifacts:"
echo $WARP_ARTIFACTS_PATH
cat $WARP_ARTIFACTS_PATH
check_deployer_balance;
}

run_hyperlane_deploy_core() {
BEFORE_CORE=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT});
update_deployer_balance;

echo -e "\nDeploying contracts to ${CHAIN1} and ${CHAIN2}"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy core \
--registry $REGISTRY_PATH \
--overrides " " \
--targets ${CHAIN1},${CHAIN2} \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--artifacts /tmp/empty-artifacts.json \
$(if [ "$HOOK_FLAG" == "true" ]; then echo "--hook ${EXAMPLES_PATH}/hooks.yaml"; fi) \
--ism ${EXAMPLES_PATH}/ism.yaml \
--out /tmp \
--ism $CORE_ISM_PATH \
--agent /tmp/agent-config.json \
--key $ANVIL_KEY \
--yes

AFTER_CORE=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
CORE_MIN_GAS=$(bc <<< "($BEFORE_CORE - $AFTER_CORE) / $GAS_PRICE")
echo "Gas used: $CORE_MIN_GAS"

CORE_ARTIFACTS_PATH=`find /tmp/core-deployment* -type f -exec ls -t1 {} + | head -1`
echo "Core artifacts:"
echo $CORE_ARTIFACTS_PATH
cat $CORE_ARTIFACTS_PATH

AGENT_CONFIG_FILENAME=`ls -t1 /tmp | grep agent-config | head -1`
check_deployer_balance;
}

run_hyperlane_deploy_warp() {
update_deployer_balance;

echo -e "\nDeploying hypNative warp route"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy warp \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--config ${EXAMPLES_PATH}/warp-route-deployment.yaml \
--out /tmp \
--registry $REGISTRY_PATH \
--overrides " " \
--config $WARP_DEPLOY_CONFIG_PATH \
--key $ANVIL_KEY \
--yes

Expand All @@ -228,51 +208,43 @@ run_hyperlane_deploy_warp() {

echo "Deploying hypCollateral warp route"
yarn workspace @hyperlane-xyz/cli run hyperlane deploy warp \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--registry $REGISTRY_PATH \
--overrides " " \
--config /tmp/warp-collateral-deployment.json \
--out /tmp \
--key $ANVIL_KEY \
--yes

AFTER_WARP=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
WARP_MIN_GAS=$(bc <<< "($AFTER_CORE - $AFTER_WARP) / $GAS_PRICE")
echo "Gas used: $WARP_MIN_GAS"
check_deployer_balance;
}

run_hyperlane_send_message() {
update_deployer_balance;

echo -e "\nSending test message"
yarn workspace @hyperlane-xyz/cli run hyperlane send message \
--registry $REGISTRY_PATH \
--overrides " " \
--origin ${CHAIN1} \
--destination ${CHAIN2} \
--messageBody "Howdy!" \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--body "Howdy!" \
--quick \
--key $ANVIL_KEY \
| tee /tmp/message1

AFTER_MSG=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
MSG_MIN_GAS=$(bc <<< "($AFTER_WARP - $AFTER_MSG) / $GAS_PRICE")
echo "Gas used: $MSG_MIN_GAS"
check_deployer_balance;

MESSAGE1_ID=`cat /tmp/message1 | grep "Message ID" | grep -E -o '0x[0-9a-f]+'`
echo "Message 1 ID: $MESSAGE1_ID"

WARP_CONFIG_FILE=`find /tmp/warp-config* -type f -exec ls -t1 {} + | head -1`
CHAIN1_ROUTER="${CHAIN1_CAPS}_ROUTER"
declare $CHAIN1_ROUTER=$(jq -r --arg CHAIN1 "$CHAIN1" '.tokens[] | select(.chainName==$CHAIN1) | .addressOrDenom' $WARP_CONFIG_FILE)
WARP_CONFIG_FILE="$REGISTRY_PATH/deployments/warp_routes/FAKE/${CHAIN1}-${CHAIN2}-config.yaml"

echo -e "\nSending test warp transfer"
yarn workspace @hyperlane-xyz/cli run hyperlane send transfer \
--registry $REGISTRY_PATH \
--overrides " " \
--origin ${CHAIN1} \
--destination ${CHAIN2} \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--warp ${WARP_CONFIG_FILE} \
--router ${!CHAIN1_ROUTER} \
--quick \
--key $ANVIL_KEY \
| tee /tmp/message2
Expand Down Expand Up @@ -303,7 +275,7 @@ run_validator() {

VALIDATOR_PORT=$((VALIDATOR_PORT+1))
echo "Running validator on $CHAIN on port $VALIDATOR_PORT"
export CONFIG_FILES=/tmp/${AGENT_CONFIG_FILENAME}
export CONFIG_FILES=/tmp/agent-config.json
export HYP_ORIGINCHAINNAME=${CHAIN}
export HYP_VALIDATOR_INTERVAL=1
export HYP_VALIDATOR_TYPE=hexKey
Expand Down Expand Up @@ -340,7 +312,7 @@ run_relayer() {
cargo build --bin relayer

echo "Running relayer"
export CONFIG_FILES=/tmp/${AGENT_CONFIG_FILENAME}
export CONFIG_FILES=/tmp/agent-config.json
export HYP_RELAYCHAINS=${CHAIN1},${CHAIN2}
export HYP_ALLOWLOCALCHECKPOINTSYNCERS=true
export HYP_DB=/tmp/relayer
Expand All @@ -367,8 +339,8 @@ run_hyperlane_status() {
yarn workspace @hyperlane-xyz/cli run hyperlane status \
--id $2 \
--destination ${CHAIN2} \
--chains ${EXAMPLES_PATH}/anvil-chains.yaml \
--core $CORE_ARTIFACTS_PATH \
--registry $REGISTRY_PATH \
--overrides " " \
| tee /tmp/message-status-$1
if ! grep -q "$2 was delivered" /tmp/message-status-$1; then
echo "ERROR: Message $1 was not delivered"
Expand All @@ -379,6 +351,17 @@ run_hyperlane_status() {
done
}

update_deployer_balance() {
OLD_BALANCE=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT});
}

check_deployer_balance() {
NEW_BALANCE=$(cast balance $DEPLOYER --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_PRICE=$(cast gas-price --rpc-url http://127.0.0.1:${CHAIN1_PORT})
GAS_USED=$(bc <<< "($OLD_BALANCE - $NEW_BALANCE) / $GAS_PRICE")
echo "Gas used: $GAS_USED"
}

_main "$@";

exit;
20 changes: 16 additions & 4 deletions typescript/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ import { deployCommand } from './src/commands/deploy.js';
import { hookCommand } from './src/commands/hook.js';
import { ismCommand } from './src/commands/ism.js';
import {
keyCommandOption,
logFormatCommandOption,
logLevelCommandOption,
overrideRegistryUriCommandOption,
registryUriCommandOption,
skipConfirmationOption,
} from './src/commands/options.js';
import { sendCommand } from './src/commands/send.js';
import { statusCommand } from './src/commands/status.js';
import { contextMiddleware } from './src/context/context.js';
import { configureLogger, errorRed } from './src/logger.js';
import { checkVersion } from './src/utils/version-check.js';
import { VERSION } from './src/version.js';
Expand All @@ -32,10 +37,17 @@ try {
.scriptName('hyperlane')
.option('log', logFormatCommandOption)
.option('verbosity', logLevelCommandOption)
.global(['log', 'verbosity'])
.middleware((argv) => {
configureLogger(argv.log as LogFormat, argv.verbosity as LogLevel);
})
.option('registry', registryUriCommandOption)
.option('overrides', overrideRegistryUriCommandOption)
.option('key', keyCommandOption)
.option('yes', skipConfirmationOption)
.global(['log', 'verbosity', 'registry', 'overrides', 'yes'])
.middleware([
(argv) => {
configureLogger(argv.log as LogFormat, argv.verbosity as LogLevel);
},
contextMiddleware,
])
.command(chainsCommand)
.command(configCommand)
.command(deployCommand)
Expand Down
22 changes: 0 additions & 22 deletions typescript/cli/examples/anvil-chains.yaml

This file was deleted.

Loading

0 comments on commit b3886dc

Please sign in to comment.