-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add integration test script for pmonitor
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
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters