Skip to content

Commit

Permalink
Some more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sveitser committed Jan 22, 2025
1 parent 3e8144c commit 22752c0
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions espresso-tests/migration-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function fmt {
echo
}

# Show something with a comment in front, to distinguish it from console output.
function info {
echo "# $@"
}

# Remove log files on exit
trap "exit" INT TERM
trap cleanup EXIT
Expand All @@ -62,15 +67,18 @@ TESTNODE_LOG_FILE=$(mktemp -t nitro-test-node-logs-XXXXXXXX)
ESPRESSO_DEVNODE_LOG_FILE=$(mktemp -t espresso-dev-node-logs-XXXXXXXX)
TESTNODE_DIR="$(dirname "$TEST_DIR")"
ORBIT_ACTIONS_DIR="$TESTNODE_DIR/orbit-actions"
ENV_FILE="$TEST_DIR/.env"

# Change to orbit actions directory, update the submodule, and install any dependencies for the purposes of the test.
cd "$ORBIT_ACTIONS_DIR"

info "Ensuring submodules are checked out"
run git submodule update --init --recursive

info "Ensuring nodejs dependencies are installed"
run yarn

# ensure we can compile the contracts
info "Ensuring we can compile the migration smart contracts"
run forge build

# Change to the top level directory for the purposes of the test.
Expand All @@ -82,46 +90,59 @@ cd "$TESTNODE_DIR"
# can't work out a way to be able to filter the lines (e. g. grep -v WARN) and
# still have the output show up.

# Initialize a standard network not compatible with espresso to simulate a pre-upgrade orbit network e.g. not needed for the real migration
info Deploying a vanilla Nitro stack locally, to be migrated to Espresso later.
emph ./test-node.bash --simple --init-force --tokenbridge --detach --no-build-utils
if [ "$DEBUG" = "true" ]; then
./test-node.bash --simple --init-force --tokenbridge --detach --no-build-utils
else
echo "This command starts up an entire Nitro stack. It takes a long time."
echo "Run \`tail -f $TESTNODE_LOG_FILE\` to see logs, if necessary."
info "This command starts up an entire Nitro stack. It takes a long time."
info "Run \`tail -f $TESTNODE_LOG_FILE\` to see logs, if necessary."
echo
./test-node.bash --simple --init-force --tokenbridge --detach --no-build-utils > "$TESTNODE_LOG_FILE" 2>&1
fi

# Start espresso sequencer node for the purposes of the test e.g. not needed for the real migration.
info "Starting a local Espresso confirmation layer development node"
emph docker compose up espresso-dev-node --detach
if [ "$DEBUG" = "true" ]; then
docker compose up espresso-dev-node --detach
else
echo "Run \`tail -f $ESPRESSO_DEVNODE_LOG_FILE\` to see logs, if necessary."
info "Run \`tail -f $ESPRESSO_DEVNODE_LOG_FILE\` to see logs, if necessary."
echo
docker compose up espresso-dev-node --detach > "$ESPRESSO_DEVNODE_LOG_FILE" 2>&1
fi

# Export environment variables in .env file
info "Load environment variables in $ENV_FILE"
# A similar env file should be supplied for whatever
emph . "$TEST_DIR/.env"
. "$TEST_DIR/.env"
echo
echo Loaded env vars:
info "Loaded env vars:"
echo
cat "$TEST_DIR/.env" | sed 's/^/ /'
echo

function trim-last {
tail -n 1 | tr -d '\r\n'

}
function get-addr {
local file="$1"
local path="$2"
docker compose run --entrypoint cat scripts $file 2>/dev/null | jq -r "$path" | trim-last
}

# Overwrite the ROLLUP_ADDRESS for this test, it might not be the same as the one in the .env file
#* Essential migration sub step * This address (the rollup proxy address) is likely a known address to operators.
ROLLUP_ADDRESS=$(docker compose run --entrypoint cat scripts /config/deployed_chain_info.json | jq -r '.[0].rollup.rollup' | tail -n 1 | tr -d '\r\n')
ROLLUP_ADDRESS=$(get-addr /config/deployed_chain_info.json '.[0].rollup.rollup')
declare -p ROLLUP_ADDRESS

# A convoluted way to get the address of the child chain upgrade executor, maybe there's a better way?
# These steps below are just for the purposes of the test. In a real deployment operators will likely already know their child-chain's upgrade executor address, and it should be included in a .env file for the migration run.
INBOX_ADDRESS=$(docker compose run --entrypoint cat scripts /config/deployed_chain_info.json | jq -r '.[0].rollup.inbox' | tail -n 1 | tr -d '\r\n')
INBOX_ADDRESS=$(get-addr /config/deployed_chain_info.json '.[0].rollup.inbox')
declare -p INBOX_ADDRESS

L1_TOKEN_BRIDGE_CREATOR_ADDRESS=$(docker compose run --entrypoint cat scripts /tokenbridge-data/network.json | jq -r '.l1TokenBridgeCreator' | tail -n 1 | tr -d '\r\n')
L1_TOKEN_BRIDGE_CREATOR_ADDRESS=$(get-addr /tokenbridge-data/network.json '.l1TokenBridgeCreator')
declare -p L1_TOKEN_BRIDGE_CREATOR_ADDRESS

CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS=$(cast call $L1_TOKEN_BRIDGE_CREATOR_ADDRESS 'inboxToL2Deployment(address)(address,address,address,address,address,address,address,address,address)' $INBOX_ADDRESS | tail -n 2 | head -n 1 | tr -d '\r\n')
Expand All @@ -130,26 +151,22 @@ declare -p CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS
# Export l2 owner private key and address
# These commands are exclusive to the test.
# * Essential migration sub step * These addresses are likely known addresses to operators in the event of a real migration
PRIVATE_KEY="$(docker compose run scripts print-private-key --account l2owner | tail -n 1 | tr -d '\r\n')"
PRIVATE_KEY="$(docker compose run scripts print-private-key --account l2owner 2>dev/null | trim-last)"
# This is a private key used for testing, save to print
declare -p PRIVATE_KEY

OWNER_ADDRESS="$(docker compose run scripts print-address --account l2owner | tail -n 1 | tr -d '\r\n')"
OWNER_ADDRESS="$(docker compose run scripts print-address --account l2owner 2>/dev/null | trim-last)"
declare -p OWNER_ADDRESS

cd $ORBIT_ACTIONS_DIR
echo "Deploying mock espresso tee verifier"
info "Deploying mock espresso tee verifier"
forge script --chain $PARENT_CHAIN_CHAIN_ID ../espresso-tests/DeployMockVerifier.s.sol:DeployMockVerifier --rpc-url $PARENT_CHAIN_RPC_URL --broadcast -vvvv

ESPRESSO_TEE_VERIFIER_ADDRESS=$(cat broadcast/DeployMockVerifier.s.sol/1337/run-latest.json | jq -r '.transactions[0].contractAddress' | cast to-checksum)
declare -p ESPRESSO_TEE_VERIFIER_ADDRESS

echo "Mock TEE Address:"
echo $ESPRESSO_TEE_VERIFIER_ADDRESS
declare -p ESPRESSO_TEE_VERIFIER_ADDRESS

# Echo for debug
echo "Deploying and initializing Espresso SequencerInbox"
info "Deploying and initializing Espresso SequencerInbox"
# ** Essential migration step ** Forge script to deploy the new SequencerInbox. We do this to later point the rollups challenge manager to the espresso integrated OSP.
forge script --chain $PARENT_CHAIN_CHAIN_ID ../espresso-tests/DeployAndInitEspressoSequencerInboxForTest.s.sol:DeployAndInitEspressoSequencerInbox --rpc-url $PARENT_CHAIN_RPC_URL --broadcast -vvvv --skip-simulation

Expand All @@ -158,10 +175,10 @@ NEW_SEQUENCER_INBOX_IMPL_ADDRESS=$(cat broadcast/DeployAndInitEspressoSequencerI
declare -p NEW_SEQUENCER_INBOX_IMPL_ADDRESS

# Echo for debugging.
echo "Deployed new SequencerInbox at $NEW_SEQUENCER_INBOX_IMPL_ADDRESS"
info "Deployed new SequencerInbox at $NEW_SEQUENCER_INBOX_IMPL_ADDRESS"

# Echo for debug
echo "Deploying Espresso SequencerInbox migration action"
info "Deploying Espresso SequencerInbox migration action"

# ** Essential migration step ** Forge script to deploy Espresso OSP migration action
run forge script --chain $PARENT_CHAIN_CHAIN_ID contracts/parent-chain/espresso-migration/DeployEspressoSequencerMigrationAction.s.sol:DeployEspressoSequencerMigrationAction --rpc-url $PARENT_CHAIN_RPC_URL --broadcast -vvvv
Expand All @@ -171,9 +188,9 @@ run forge script --chain $PARENT_CHAIN_CHAIN_ID contracts/parent-chain/espresso-
SEQUENCER_MIGRATION_ACTION=$(cat broadcast/DeployEspressoSequencerMigrationAction.s.sol/1337/run-latest.json | jq -r '.transactions[0].contractAddress' | cast to-checksum)
declare -p SEQUENCER_MIGRATION_ACTION

echo "Deployed new EspressoSequencerMigrationAction at $SEQUENCER_MIGRATION_ACTION"
info "Deployed new EspressoSequencerMigrationAction at $SEQUENCER_MIGRATION_ACTION"

echo "Deploying ArbOS Upgrade action"
info "Deploying ArbOS Upgrade action"
# Forge script to deploy the Espresso ArbOS upgrade action.
# ** Essential migration step ** the ArbOS upgrade signifies that the chain is now espresso compatible.
run forge script --chain $CHILD_CHAIN_CHAIN_NAME contracts/child-chain/espresso-migration/DeployArbOSUpgradeAction.s.sol:DeployArbOSUpgradeAction --rpc-url $CHILD_CHAIN_RPC_URL --broadcast -vvvv
Expand All @@ -183,19 +200,20 @@ ARBOS_UPGRADE_ACTION=$(cat broadcast/DeployArbOSUpgradeAction.s.sol/412346/run-l
declare -p ARBOS_UPGRADE_ACTION

# Echo information for debugging.
echo "Deployed ArbOSUpgradeAction at $ARBOS_UPGRADE_ACTION"
info "Deployed ArbOSUpgradeAction at $ARBOS_UPGRADE_ACTION"

# Change directories to start nitro node in new docker container with espresso image
cd $TESTNODE_DIR

docker stop nitro-testnode-sequencer-1
docker wait nitro-testnode-sequencer-1
run docker stop nitro-testnode-sequencer-1
run docker wait nitro-testnode-sequencer-1

# Start nitro node in new docker container with espresso image
./espresso-tests/create-espresso-integrated-nitro-node.bash
run ./espresso-tests/create-espresso-integrated-nitro-node.bash
# Use cast to call the upgradeExecutor and execute the L1 upgrade actions.This will point the challenge manager at the new OSP entry, as well as update the wasmModuleRoot for the rollup. ** Essential migration step **
cast send $PARENT_CHAIN_UPGRADE_EXECUTOR "execute(address, bytes)" $SEQUENCER_MIGRATION_ACTION $(cast calldata "perform()") --rpc-url $PARENT_CHAIN_RPC_URL --private-key $PRIVATE_KEY
run cast send $PARENT_CHAIN_UPGRADE_EXECUTOR "execute(address, bytes)" $SEQUENCER_MIGRATION_ACTION $(cast calldata "perform()") --rpc-url $PARENT_CHAIN_RPC_URL --private-key $PRIVATE_KEY

echo "Executed SequencerMigrationAction via UpgradeExecutor"
info "Executed SequencerMigrationAction via UpgradeExecutor"

# Get the number of confirmed nodes before the upgrade to ensure the staker is still working.
NUM_CONFIRMED_NODES_BEFORE_UPGRADE=$(cast call --rpc-url $PARENT_CHAIN_RPC_URL $ROLLUP_ADDRESS 'latestConfirmed()(uint256)')
Expand All @@ -204,28 +222,28 @@ NUM_CONFIRMED_NODES_BEFORE_UPGRADE=$(cast call --rpc-url $PARENT_CHAIN_RPC_URL $
# Wait for CHILD_CHAIN_RPC_URL to be available
# * Essential migration sub step * This is technically essential to the migration, but doesn't usually take long and shouldn't need to be programmatically determined during a live migration.
while ! curl -s $CHILD_CHAIN_RPC_URL > /dev/null; do
echo "Waiting for $CHILD_CHAIN_RPC_URL to be available..."
info "Waiting for $CHILD_CHAIN_RPC_URL to be available..."
sleep 5
done

# Echo for debugging
echo "Adding child chain upgrade executor as an L2 chain owner"
info "Adding child chain upgrade executor as an L2 chain owner"
# This step is done for the purposes of the test, as there should already be an upgrade executor on the child chain that is a chain owner
cast send 0x0000000000000000000000000000000000000070 'addChainOwner(address)' $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
run cast send 0x0000000000000000000000000000000000000070 'addChainOwner(address)' $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY

cd $ORBIT_ACTIONS_DIR
# Grab the pre-upgrade ArbOS version for testing.
ARBOS_VERSION_BEFORE_UPGRADE=$(cast call "0x0000000000000000000000000000000000000064" "arbOSVersion()(uint64)" --rpc-url $CHILD_CHAIN_RPC_URL)

# Use the Upgrde executor on the child chain to execute the ArbOS upgrade to signify that the node is now operating in espresso mode. This is essential for the migration.
# ** Essential migration step ** This step can technically be done before all of the others as it is just scheduling the ArbOS upgrade. The unix timestamp at which the upgrade occurrs can be determined by operators, but for the purposes of the test we use 0 to upgrade immediately.
cast send $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS "execute(address, bytes)" $ARBOS_UPGRADE_ACTION $(cast calldata "perform()") --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
run cast send $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS "execute(address, bytes)" $ARBOS_UPGRADE_ACTION $(cast calldata "perform()") --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
cd $TEST_DIR
# write tee verifier address into chain config
jq -r '.arbitrum.EspressoTEEVerifierAddress |= $ESPRESSO_TEE_VERIFIER_ADDRESS' test-chain-config.json > sent-chain-config.json --arg ESPRESSO_TEE_VERIFIER_ADDRESS $ESPRESSO_TEE_VERIFIER_ADDRESS
CHAIN_CONFIG=$(cat sent-chain-config.json)

cast send $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS $(cast calldata "executeCall(address, bytes)" "0x0000000000000000000000000000000000000070" $(cast calldata "setChainConfig(string)" "$CHAIN_CONFIG")) --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
run cast send $CHILD_CHAIN_UPGRADE_EXECUTOR_ADDRESS $(cast calldata "executeCall(address, bytes)" "0x0000000000000000000000000000000000000070" $(cast calldata "setChainConfig(string)" "$CHAIN_CONFIG")) --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
# Set the chain config

# Check the upgrade happened
Expand All @@ -244,14 +262,10 @@ if [ $ARBOS_VERSION_AFTER_UPGRADE != "90" ]; then
fail "ArbOS version not updated: Expected 90, Actual $ARBOS_VERSION_AFTER_UPGRADE"
fi

# Check for balance before transfer.
# The following sequence is to check that transactions are still successfully being sequenced on the L2
ORIGINAL_OWNER_BALANCE=$(cast balance $OWNER_ADDRESS -e --rpc-url $CHILD_CHAIN_RPC_URL)

# Send 1 eth as the owner
info "Testing if the Espresso integration works by doing an Eth transfer."
RECIPIENT_ADDRESS=0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BALANCE_ORIG=$(cast balance $RECIPIENT_ADDRESS -e --rpc-url $CHILD_CHAIN_RPC_URL)
cast send $RECIPIENT_ADDRESS --value 1ether --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY
run cast send $RECIPIENT_ADDRESS --value 1ether --rpc-url $CHILD_CHAIN_RPC_URL --private-key $PRIVATE_KEY

# Get the new balance after the transfer.
BALANCE_NEW=$(cast balance $RECIPIENT_ADDRESS -e --rpc-url $CHILD_CHAIN_RPC_URL)
Expand Down

0 comments on commit 22752c0

Please sign in to comment.