Skip to content

Commit

Permalink
feat: Prepare test hook (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
usmanmani1122 authored Jan 2, 2025
1 parent ce1df1d commit 183440d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
28 changes: 23 additions & 5 deletions packages/synthetic-chain/public/upgrade-test-scripts/env_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export GOV3ADDR=$($binary keys show gov3 -a --keyring-backend="test")
export VALIDATORADDR=$($binary keys show validator -a --keyring-backend="test")
export USER1ADDR=$($binary keys show user1 -a --keyring-backend="test")

export PID_FILE="$HOME/.agoric/agd.pid"
export STATUS_FILE="$HOME/.agoric/last_observed_status"

if [[ "$binary" == "agd" ]]; then
configdir=/usr/src/agoric-sdk/packages/vm-config
# Check specifically for package.json because the directory may persist in the file system
Expand Down Expand Up @@ -80,6 +83,20 @@ await_agd_startable() {
fi
}

save_latest_node_info() {
PID="$(cat "$PID_FILE")"

if ps --pid "$PID" > /dev/null
then
NODE_STATUS="$(agd status)"
BLOCK_HEIGHT="$(echo "$NODE_STATUS" | jq '.SyncInfo.latest_block_height' --raw-output)"
echo "Saving node status at block height $BLOCK_HEIGHT"
echo "$NODE_STATUS" > "$STATUS_FILE"
else
echo "[FATAL] Chain process not running"
fi
}

startAgd() {
echo "startAgd()"

Expand All @@ -88,19 +105,20 @@ startAgd() {

agd start --log_level warn "$@" &
AGD_PID=$!
echo $AGD_PID >$HOME/.agoric/agd.pid
echo $AGD_PID > "$PID_FILE"
echo "startAgd() at height $(wait_for_bootstrap | tr '\n' ' ' | sed 's/ $//; s/ /... /g;')"
waitForBlock 2
echo "startAgd() done"
}

killAgd() {
echo "killAgd()"
AGD_PID=$(cat $HOME/.agoric/agd.pid)
kill $AGD_PID
rm $HOME/.agoric/agd.pid
save_latest_node_info
AGD_PID=$(cat "$PID_FILE")
kill "$AGD_PID"
rm "$PID_FILE"
# cf. https://stackoverflow.com/a/41613532
tail --pid=$AGD_PID -f /dev/null || true
tail --follow /dev/null --pid "$AGD_PID" || true
}

provisionSmartWallet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ fi

echo "[$PROPOSAL] Eval completed. Running 10 blocks and exiting."
waitForBlock 10

killAgd
14 changes: 12 additions & 2 deletions packages/synthetic-chain/public/upgrade-test-scripts/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@ echo '
|_____| |_____| | |_____ |_____| | | | |______
'

source ./env_setup.sh

cd /usr/src/proposals/"$PROPOSAL/" || fail "Proposal $PROPOSAL does not exist"

if test -f prepare-test.sh
then
echo "[$PROPOSAL] Running prepare-test.sh"
./prepare-test.sh
fi

echo "[$PROPOSAL] Starting agd"

source ./env_setup.sh
startAgd

echo "[$PROPOSAL] Running test.sh."
cd /usr/src/proposals/"$PROPOSAL/" || fail "Proposal $PROPOSAL does not exist"
./test.sh

echo "[$PROPOSAL] Testing completed."

killAgd
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ cd "$PROPOSAL_DIR"

echo "[$PROPOSAL] Actions completed. Running for a few blocks and exiting."
waitForBlock 5

killAgd
12 changes: 11 additions & 1 deletion packages/synthetic-chain/src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ export const buildProposalSubmissions = (proposals: ProposalInfo[]) => {
* @param [dry] - Whether to skip building and just print the build config.
*/
export const bakeTarget = (target: string, dry = false) => {
const cmd = `docker buildx bake --load ${target} ${dry ? '--print' : ''}`;
const cmd = [
'docker',
'buildx',
'bake',
`--load "${target}"`,
dry && '--print',
process.env.DOCKER_PROGRESS_FORMAT &&
`--progress "${process.env.DOCKER_PROGRESS_FORMAT}"`,
]
.filter(Boolean)
.join(' ');
console.log(cmd);
execSync(cmd, { stdio: 'inherit' });
};

0 comments on commit 183440d

Please sign in to comment.