Skip to content

Commit

Permalink
ci: add integration test script for pmonitor
Browse files Browse the repository at this point in the history
Used this script locally during review of the pmonitor PR. It's not
actually wired up to a workflow, and maybe it should be dropped from the
diff altogether, but I'm committing it so it's easier to test follow-up
changes in the near future.
  • Loading branch information
conorsch committed Sep 26, 2024
1 parent dee84cc commit cdcb279
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
93 changes: 93 additions & 0 deletions deployments/scripts/pmonitor-integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
# quick script to test the `pmonitor` tool during review
# set -euo pipefail
set -eu

>&2 echo "Preparing pmonitor test bed..."
num_wallets=10

wallets_dir="/tmp/pmonitor-test-wallets"
wallet_addresses="${wallets_dir}/addresses.txt"
allocations_csv="${wallets_dir}/pmonitor-test-allocations.csv"
fvks_json="${wallets_dir}/fvks.json"
rm -rf "$wallets_dir"
cargo run --release --bin pd -- network unsafe-reset-all || true
cargo run --release --bin pmonitor -- reset || true
mkdir "$wallets_dir"
# override process-compose default port of 8080, which we use for pd
export PC_PORT_NUM="8888"
process-compose down || true

>&2 echo "creating pcli wallets"
for i in $(seq 1 "$num_wallets"); do
yes | cargo run -q --release --bin pcli -- --home "${wallets_dir}/wallet-$i" init --grpc-url http://localhost:8080 soft-kms generate
done

# collect addresses
>&2 echo "collecting pcli wallet addresses"
for i in $(seq 1 "$num_wallets"); do
cargo run -q --release --bin pcli -- --home "${wallets_dir}/wallet-$i" view address
done > "$wallet_addresses"


# generate genesis allocations
>&2 echo "generating genesis allocations"
printf 'amount,denom,address\n' > "$allocations_csv"
while read -r a ; do
printf '1_000_000__000_000,upenumbra,%s\n1000,test_usd,%s\n' "$a" "$a"
done < "$wallet_addresses" >> "$allocations_csv"

# generate network data
>&2 echo "generating network data"
cargo run --release --bin pd -- network generate \
--chain-id penumbra-devnet-pmonitor \
--unbonding-delay 50 \
--epoch-duration 50 \
--proposal-voting-blocks 50 \
--timeout-commit 3s \
--gas-price-simple 500 \
--allocations-input-file "$allocations_csv"

# run network
>&2 echo "running local devnet"
process-compose up --detached --config deployments/compose/process-compose.yml

# ensure network is torn down afterward; comment this out if you want
# to interact with the network after tests complete.
trap 'process-compose down || true' EXIT

# wait for network to come up; lazily sleeping, rather than polling process-compose for "ready" state
sleep 8

>&2 echo "collecting fvks"
fd config.toml "$wallets_dir" -x toml get {} full_viewing_key | jq -s > "$fvks_json"

>&2 echo "initializing pmonitor"
cargo run --release --bin pmonitor -- init --fvks "$fvks_json" --grpc-url http://localhost:8080

>&2 echo "running pmonitor audit"
# happy path: we expect this audit to exit 0, because no transfers have occurred yet
cargo run --release --bin pmonitor -- audit

>&2 echo "committing misbehavior"
alice_wallet="${wallets_dir}/wallet-alice"
yes | cargo run --quiet --release --bin pcli -- --home "$alice_wallet" init --grpc-url http://localhost:8080 soft-kms generate
alice_address="$(cargo run --quiet --release --bin pcli -- --home "$alice_wallet" view address)"
misbehaving_wallet="${wallets_dir}/wallet-2"
cargo run --quiet --release --bin pcli -- --home "$misbehaving_wallet" tx send --memo "take these tokens, but tell no one" 500penumbra --to "$alice_address"

>&2 echo "re-running pmonitor audit"
# unhappy path: we expect this audit to exit 10, because a transfer occurred from a monitored wallet
# TODO: make pmonitor exit non-zero when there's bad misbehavior
cargo run --release --bin pmonitor -- audit | tee "${wallets_dir}/pmonitor-log-1.txt"

printf '#################################\n'
printf 'PMONITOR INTEGRATION TEST SUMMARY\n'
printf '#################################\n'

if grep -q "Unexpected balance! Balance is less than the genesis balance" "${wallets_dir}/pmonitor-log-1.txt" ; then
>&2 echo "OK: 'pmonitor audit' reported unexpected balance, due to misbehavior"
else
>&2 echo "ERROR: 'pmonitor audit' failed to identify misbehavior, which we know occurred"
exit 1
fi
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
default:
@just --list

# Run integration tests for pmonitor tool
test-pmonitor:
./deployments/scripts/pmonitor-integration-test.sh

# Creates and runs a local devnet with solo validator. Includes ancillary services
# like metrics, postgres for storing ABCI events, and pindexer for munging those events.
dev:
Expand Down

0 comments on commit cdcb279

Please sign in to comment.