Skip to content

Commit

Permalink
feat(deployment): add state-sync to upgrade 11 test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Aug 10, 2023
1 parent 316fbf3 commit 0e2987e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

. ./upgrade-test-scripts/env_setup.sh

# Enable debugging
set -x

# CWD is agoric-sdk
upgrade11=./upgrade-test-scripts/agoric-upgrade-11

# replicate state-sync of node
killAgd
EXPORT_DIR=$(mktemp -t -d swing-store-export-upgrade-11-XXX)
make_swing_store_snapshot $EXPORT_DIR || fail "Couldn't make swing-store snapshot"
test_val "$(compare_swing_store_export_data $EXPORT_DIR)" "match" "swing-store export data"
restore_swing_store_snapshot $EXPORT_DIR || fail "Couldn't restore swing-store snapshot"
rm -rf $EXPORT_DIR
startAgd

######################################################################
# FIXME: remove this line when these tests don't hardcode bundle hashes.
echo 1>&2 "FIXME: skipping zoe-full-upgrade tests"; return 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,65 @@ pushPriceOnce () {
else
echo "ERROR: pushPrice failed (using $nextOracle)"
fi
}

export_genesis() {
HEIGHT_ARG=

if [ -n "$1" ]; then
HEIGHT_ARG="--height $1"
shift
fi

agd export $HEIGHT_ARG "$@"
}

make_swing_store_snapshot() {( set -euo pipefail
EXPORT_DIR="$1"
shift
/usr/src/agoric-sdk/packages/cosmic-swingset/src/export-kernel-db.js --home "$HOME/.agoric" --export-dir "$EXPORT_DIR" --verbose --artifact-mode archival --export-data-mode all "$@"

EXPORT_MANIFEST_FILE="$EXPORT_DIR/export-manifest.json"
EXPORT_DATA_FILE="$EXPORT_DIR/$(cat "$EXPORT_MANIFEST_FILE" | jq -r .data)"
EXPORT_DATA_UNTRUSTED_FILE="${EXPORT_DATA_FILE%.*}-untrusted.jsonl"
EXPORT_HEIGHT=$(cat "$EXPORT_MANIFEST_FILE" | jq -r .blockHeight)
EXPORT_MANIFEST="$(cat $EXPORT_MANIFEST_FILE)"

mv "$EXPORT_DATA_FILE" "$EXPORT_DATA_UNTRUSTED_FILE"
export_genesis $EXPORT_HEIGHT | jq -cr '.app_state.swingset.swing_store_export_data[] | [.key,.value]' > "$EXPORT_DATA_FILE"

jq -n "$EXPORT_MANIFEST | .untrustedData=\"$(basename -- "$EXPORT_DATA_UNTRUSTED_FILE")\"" > "$EXPORT_MANIFEST_FILE"

echo "Successful swing-store export for block $EXPORT_HEIGHT"
)}

restore_swing_store_snapshot() {( set -euo pipefail
rm -f $HOME/.agoric/data/agoric/swingstore.sqlite
EXPORT_DIR="$1"
shift

/usr/src/agoric-sdk/packages/cosmic-swingset/src/import-kernel-db.js --home "$HOME/.agoric" --export-dir "$EXPORT_DIR" --verbose --artifact-mode replay --export-data-mode all "$@"
)}

compare_swing_store_export_data() {
EXPORT_DIR="$1"
EXPORT_MANIFEST_FILE="$EXPORT_DIR/export-manifest.json"
EXPORT_DATA_FILE="$(cat "$EXPORT_MANIFEST_FILE" | jq -r .data)"
EXPORT_DATA_UNTRUSTED_FILE="$(cat "$EXPORT_MANIFEST_FILE" | jq -r .untrustedData)"

if [ -z "$EXPORT_DATA_FILE" ]; then
echo "missing-export-data"
return
fi

if [ -z "$EXPORT_DATA_UNTRUSTED_FILE" ]; then
echo "missing-untrusted-export-data"
return
fi

diff <(cat "$EXPORT_DIR/$EXPORT_DATA_FILE" | sort) <(cat "$EXPORT_DIR/$EXPORT_DATA_UNTRUSTED_FILE" | sort) >&2 && {
echo "match"
} || {
echo "mismatch"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ waitForBlock 2
# CWD is agoric-sdk
upgrade11=./upgrade-test-scripts/agoric-upgrade-11

# verify swing-store export-data is consistent
killAgd
EXPORT_DIR=$(mktemp -t -d swing-store-export-upgrade-11-XXX)
make_swing_store_snapshot $EXPORT_DIR --artifact-mode none || fail "Couldn't make swing-store snapshot"
test_val "$(compare_swing_store_export_data $EXPORT_DIR)" "match" "swing-store consistent state-sync"
rm -rf $EXPORT_DIR
startAgd

# zoe vat is at incarnation 1
echo "FIXME: bypassed zoe-full-upgrade validation"; return 0
test_val "$(yarn --silent node $upgrade11/vat-status.mjs zoe)" "1" "zoe vat incarnation"

0 comments on commit 0e2987e

Please sign in to comment.